~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/extendedindicator/ValidateExtendedIndicatorAction.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.dd.action.extendedindicator;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 * * Redistributions of source code must retain the above copyright notice, this
 
10
 *   list of conditions and the following disclaimer.
 
11
 * * Redistributions in binary form must reproduce the above copyright notice,
 
12
 *   this list of conditions and the following disclaimer in the documentation
 
13
 *   and/or other materials provided with the distribution.
 
14
 * * Neither the name of the HISP project nor the names of its contributors may
 
15
 *   be used to endorse or promote products derived from this software without
 
16
 *   specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 
22
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 
25
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
 
 
30
import org.hisp.dhis.i18n.I18n;
 
31
import org.hisp.dhis.indicator.Indicator;
 
32
import org.hisp.dhis.indicator.IndicatorService;
 
33
 
 
34
import com.opensymphony.xwork.ActionSupport;
 
35
 
 
36
/**
 
37
 * @author Lars Helge Overland
 
38
 * @version $Id$
 
39
 */
 
40
public class ValidateExtendedIndicatorAction
 
41
    extends ActionSupport
 
42
{
 
43
    // -------------------------------------------------------------------------
 
44
    // Dependencies
 
45
    // -------------------------------------------------------------------------
 
46
 
 
47
    private IndicatorService indicatorService;
 
48
 
 
49
    public void setIndicatorService( IndicatorService indicatorService )
 
50
    {
 
51
        this.indicatorService = indicatorService;
 
52
    }
 
53
    
 
54
    private I18n i18n;
 
55
 
 
56
    public void setI18n( I18n i18n )
 
57
    {
 
58
        this.i18n = i18n;
 
59
    }
 
60
 
 
61
    // -------------------------------------------------------------------------
 
62
    // Input
 
63
    // -------------------------------------------------------------------------
 
64
 
 
65
    private Integer id;
 
66
 
 
67
    public void setId( Integer id )
 
68
    {
 
69
        this.id = id;
 
70
    }
 
71
 
 
72
    private String name;
 
73
 
 
74
    public void setName( String name )
 
75
    {
 
76
        this.name = name;
 
77
    }
 
78
 
 
79
    private String shortName;
 
80
 
 
81
    public void setShortName( String shortName )
 
82
    {
 
83
        this.shortName = shortName;
 
84
    }
 
85
 
 
86
    private String alternativeName;
 
87
 
 
88
    public void setAlternativeName( String alternativeName )
 
89
    {
 
90
        this.alternativeName = alternativeName;
 
91
    }
 
92
    
 
93
    private String code;
 
94
 
 
95
    public void setCode( String code )
 
96
    {
 
97
        this.code = code;
 
98
    }
 
99
    
 
100
    private Integer indicatorTypeId;
 
101
 
 
102
    public void setIndicatorTypeId( Integer indicatorTypeId )
 
103
    {
 
104
        this.indicatorTypeId = indicatorTypeId;
 
105
    }    
 
106
    
 
107
    private String numeratorDescription;
 
108
 
 
109
    public void setNumeratorDescription( String numeratorDescription )
 
110
    {
 
111
        this.numeratorDescription = numeratorDescription;
 
112
    }
 
113
    
 
114
    private String denominatorDescription;
 
115
 
 
116
    public void setDenominatorDescription( String denominatorDescription )
 
117
    {
 
118
        this.denominatorDescription = denominatorDescription;
 
119
    }
 
120
 
 
121
    private String mnemonic;
 
122
 
 
123
    public void setMnemonic( String mnemonic )
 
124
    {
 
125
        this.mnemonic = mnemonic;
 
126
    }    
 
127
    
 
128
    private String version;
 
129
 
 
130
    public void setVersion( String version )
 
131
    {
 
132
        this.version = version;
 
133
    }
 
134
    
 
135
    private String description;
 
136
 
 
137
    public void setDescription( String description )
 
138
    {
 
139
        this.description = description;
 
140
    }
 
141
 
 
142
    private String keywords;
 
143
 
 
144
    public void setKeywords( String keywords )
 
145
    {
 
146
        this.keywords = keywords;
 
147
    }
 
148
    
 
149
    private String minimumSize;
 
150
 
 
151
    public void setMinimumSize( String minimumSize )
 
152
    {
 
153
        this.minimumSize = minimumSize;
 
154
    }
 
155
 
 
156
    private String maximumSize;
 
157
 
 
158
    public void setMaximumSize( String maximumSize )
 
159
    {
 
160
        this.maximumSize = maximumSize;
 
161
    }
 
162
    
 
163
    private String responsibleAuthority;
 
164
 
 
165
    public void setResponsibleAuthority( String responsibleAuthority )
 
166
    {
 
167
        this.responsibleAuthority = responsibleAuthority;
 
168
    }
 
169
 
 
170
    private String location;
 
171
 
 
172
    public void setLocation( String location )
 
173
    {
 
174
        this.location = location;
 
175
    }
 
176
 
 
177
    private String reportingMethods;
 
178
 
 
179
    public void setReportingMethods( String reportingMethods )
 
180
    {
 
181
        this.reportingMethods = reportingMethods;
 
182
    }
 
183
 
 
184
    private String versionStatus;
 
185
 
 
186
    public void setVersionStatus( String versionStatus )
 
187
    {
 
188
        this.versionStatus = versionStatus;
 
189
    }
 
190
 
 
191
    // -------------------------------------------------------------------------
 
192
    // Output
 
193
    // -------------------------------------------------------------------------
 
194
 
 
195
    private String message;
 
196
 
 
197
    public String getMessage()
 
198
    {
 
199
        return message;
 
200
    }
 
201
 
 
202
    // -------------------------------------------------------------------------
 
203
    // Action implementation
 
204
    // -------------------------------------------------------------------------
 
205
 
 
206
    public String execute()
 
207
    {
 
208
        // -------------------------------------------------------------------------
 
209
        // name: required / unique
 
210
        // -------------------------------------------------------------------------
 
211
 
 
212
        if ( name == null )
 
213
        {
 
214
            message = i18n.getString( "specify_name" );
 
215
 
 
216
            return INPUT;
 
217
        }
 
218
        else
 
219
        {
 
220
            name = name.trim();
 
221
 
 
222
            if ( name.length() == 0 )
 
223
            {
 
224
                message = i18n.getString( "specify_name" );
 
225
 
 
226
                return INPUT;
 
227
            }
 
228
 
 
229
            Indicator match = indicatorService.getIndicatorByName( name );
 
230
 
 
231
            if ( match != null && (id == null || match.getId() != id) )
 
232
            {
 
233
                message = i18n.getString( "name_in_use" );
 
234
 
 
235
                return INPUT;
 
236
            }
 
237
        }
 
238
        
 
239
        // -------------------------------------------------------------------------
 
240
        // shortName: required / unique
 
241
        // -------------------------------------------------------------------------
 
242
 
 
243
        if ( shortName == null )
 
244
        {
 
245
            message = i18n.getString( "specify_short_name" );
 
246
 
 
247
            return INPUT;
 
248
        }
 
249
        else
 
250
        {
 
251
            shortName = shortName.trim();
 
252
 
 
253
            if ( shortName.length() == 0 )
 
254
            {
 
255
                message = i18n.getString( "specify_short_name" );
 
256
 
 
257
                return INPUT;
 
258
            }
 
259
 
 
260
            Indicator match = indicatorService.getIndicatorByShortName( shortName );
 
261
 
 
262
            if ( match != null && (id == null || match.getId() != id) )
 
263
            {
 
264
                message = i18n.getString( "short_name_in_use" );
 
265
 
 
266
                return INPUT;
 
267
            }
 
268
        }
 
269
        
 
270
        // -------------------------------------------------------------------------
 
271
        // alternativeName: unique
 
272
        // -------------------------------------------------------------------------
 
273
 
 
274
        if ( alternativeName != null && alternativeName.trim().length() != 0 )
 
275
        {
 
276
            Indicator match = indicatorService.getIndicatorByAlternativeName( alternativeName );
 
277
 
 
278
            if ( match != null && (id == null || match.getId() != id) )
 
279
            {
 
280
                message = i18n.getString( "alternative_name_in_use" );
 
281
 
 
282
                return INPUT;
 
283
            }
 
284
        }
 
285
        
 
286
        // -------------------------------------------------------------------------
 
287
        // code: unique
 
288
        // -------------------------------------------------------------------------
 
289
 
 
290
        if ( code != null && code.trim().length() != 0 )
 
291
        {
 
292
            Indicator match = indicatorService.getIndicatorByCode( code );
 
293
 
 
294
            if ( match != null && (id == null || match.getId() != id) )
 
295
            {
 
296
                message = i18n.getString( "code_in_use" );
 
297
 
 
298
                return INPUT;
 
299
            }
 
300
        }
 
301
 
 
302
        // -------------------------------------------------------------------------
 
303
        // description: required
 
304
        // -------------------------------------------------------------------------
 
305
 
 
306
        if ( description == null || description.trim().length() == 0 )
 
307
        {
 
308
            message = i18n.getString( "specify_description" );
 
309
            
 
310
            return INPUT;
 
311
        }
 
312
        
 
313
        if ( indicatorTypeId == null )
 
314
        {
 
315
            message = i18n.getString( "choose_indicator_type" );
 
316
 
 
317
            return INPUT;
 
318
        }
 
319
        
 
320
        // -------------------------------------------------------------------------
 
321
        // numeratorDescription: required
 
322
        // -------------------------------------------------------------------------
 
323
 
 
324
        if ( numeratorDescription == null )
 
325
        {
 
326
            message = i18n.getString( "specify_numerator_description" );
 
327
        }
 
328
 
 
329
        // -------------------------------------------------------------------------
 
330
        // denominatorDescription: required
 
331
        // -------------------------------------------------------------------------
 
332
 
 
333
        if ( denominatorDescription == null )
 
334
        {
 
335
            message = i18n.getString( "specify_denominator_description" );
 
336
        }
 
337
 
 
338
        // -------------------------------------------------------------------------
 
339
        // mnemonic: required
 
340
        // -------------------------------------------------------------------------
 
341
        
 
342
        if ( mnemonic == null || mnemonic.trim().length() == 0 )
 
343
        {
 
344
            message = i18n.getString( "specify_mnemonic" );
 
345
            
 
346
            return INPUT;
 
347
        }
 
348
 
 
349
        // -------------------------------------------------------------------------
 
350
        // version: required
 
351
        // -------------------------------------------------------------------------
 
352
 
 
353
        if ( version == null || version.trim().length() == 0 )
 
354
        {
 
355
            message = i18n.getString( "specify_version" );
 
356
            
 
357
            return INPUT;
 
358
        }
 
359
 
 
360
        // -------------------------------------------------------------------------
 
361
        // keywords: required
 
362
        // -------------------------------------------------------------------------
 
363
 
 
364
        if ( keywords == null || keywords.trim().length() == 0 )
 
365
        {
 
366
            message = i18n.getString( "specify_keywords" );
 
367
            
 
368
            return INPUT;
 
369
        }
 
370
        
 
371
        // -------------------------------------------------------------------------
 
372
        // minimumSize: distinct number
 
373
        // -------------------------------------------------------------------------
 
374
 
 
375
        if ( minimumSize != null && minimumSize.trim().length() > 0 )
 
376
        {
 
377
            try
 
378
            {
 
379
                Integer.parseInt( minimumSize );
 
380
            }
 
381
            catch ( NumberFormatException ex )
 
382
            {
 
383
                message = i18n.getString( "specify_integer_minimum_size" );
 
384
                
 
385
                return INPUT;
 
386
            }
 
387
        }
 
388
 
 
389
        // -------------------------------------------------------------------------
 
390
        // maximumSize: distinct number
 
391
        // -------------------------------------------------------------------------
 
392
 
 
393
        if ( maximumSize != null && maximumSize.trim().length() > 0  )
 
394
        {
 
395
            try
 
396
            {
 
397
                Integer.parseInt( maximumSize );
 
398
            }
 
399
            catch ( NumberFormatException ex )
 
400
            {
 
401
                message = i18n.getString( "specify_integer_maximum_size" );
 
402
                
 
403
                return INPUT;
 
404
            }
 
405
        }
 
406
        
 
407
        // -------------------------------------------------------------------------
 
408
        // responsibleAuthority: required
 
409
        // -------------------------------------------------------------------------
 
410
 
 
411
        if ( responsibleAuthority == null || responsibleAuthority.trim().length() == 0 )
 
412
        {
 
413
            message = i18n.getString( "specify_responsible_authority" );
 
414
            
 
415
            return INPUT;
 
416
        }
 
417
        
 
418
        // -------------------------------------------------------------------------
 
419
        // location: required
 
420
        // -------------------------------------------------------------------------
 
421
 
 
422
        if ( location == null || location.trim().length() == 0 )
 
423
        {
 
424
            message = i18n.getString( "specify_location" );
 
425
            
 
426
            return INPUT;
 
427
        }
 
428
 
 
429
        // -------------------------------------------------------------------------
 
430
        // reportingMethods: required
 
431
        // -------------------------------------------------------------------------
 
432
 
 
433
        if ( reportingMethods == null || reportingMethods.trim().length() == 0 )
 
434
        {
 
435
            message = i18n.getString( "specify_reporting_methods" );
 
436
            
 
437
            return INPUT;
 
438
        }
 
439
 
 
440
        // -------------------------------------------------------------------------
 
441
        // versionStatus: required
 
442
        // -------------------------------------------------------------------------
 
443
 
 
444
        if ( versionStatus == null || versionStatus.trim().length() == 0 )
 
445
        {
 
446
            message = i18n.getString( "specify_version_status" );
 
447
            
 
448
            return INPUT;
 
449
        }
 
450
 
 
451
        message = i18n.getString( "everything_is_ok" );
 
452
 
 
453
        return SUCCESS;
 
454
    }
 
455
}