~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/extendeddataelement/ValidateExtendedDataElementAction.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.extendeddataelement;
 
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.dataelement.DataElement;
 
31
import org.hisp.dhis.dataelement.DataElementService;
 
32
import org.hisp.dhis.i18n.I18n;
 
33
 
 
34
import com.opensymphony.xwork.ActionSupport;
 
35
 
 
36
/**
 
37
 * @author Lars Helge Overland
 
38
 * @version $Id$
 
39
 */
 
40
public class ValidateExtendedDataElementAction
 
41
    extends ActionSupport
 
42
{
 
43
    // -------------------------------------------------------------------------
 
44
    // Dependencies
 
45
    // -------------------------------------------------------------------------
 
46
 
 
47
    private DataElementService dataElementService;
 
48
 
 
49
    public void setDataElementService( DataElementService dataElementService )
 
50
    {
 
51
        this.dataElementService = dataElementService;
 
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 String mnemonic;
 
101
 
 
102
    public void setMnemonic( String mnemonic )
 
103
    {
 
104
        this.mnemonic = mnemonic;
 
105
    }    
 
106
    
 
107
    private String version;
 
108
 
 
109
    public void setVersion( String version )
 
110
    {
 
111
        this.version = version;
 
112
    }
 
113
    
 
114
    private String description;
 
115
 
 
116
    public void setDescription( String description )
 
117
    {
 
118
        this.description = description;
 
119
    }
 
120
 
 
121
    private String keywords;
 
122
 
 
123
    public void setKeywords( String keywords )
 
124
    {
 
125
        this.keywords = keywords;
 
126
    }
 
127
    
 
128
    private String dataElementType;
 
129
 
 
130
    public void setDataElementType( String dataElementType )
 
131
    {
 
132
        this.dataElementType = dataElementType;
 
133
    }
 
134
    
 
135
    private String minimumSize;
 
136
 
 
137
    public void setMinimumSize( String minimumSize )
 
138
    {
 
139
        this.minimumSize = minimumSize;
 
140
    }
 
141
 
 
142
    private String maximumSize;
 
143
 
 
144
    public void setMaximumSize( String maximumSize )
 
145
    {
 
146
        this.maximumSize = maximumSize;
 
147
    }
 
148
    
 
149
    private String responsibleAuthority;
 
150
 
 
151
    public void setResponsibleAuthority( String responsibleAuthority )
 
152
    {
 
153
        this.responsibleAuthority = responsibleAuthority;
 
154
    }
 
155
 
 
156
    private String location;
 
157
 
 
158
    public void setLocation( String location )
 
159
    {
 
160
        this.location = location;
 
161
    }
 
162
 
 
163
    private String reportingMethods;
 
164
 
 
165
    public void setReportingMethods( String reportingMethods )
 
166
    {
 
167
        this.reportingMethods = reportingMethods;
 
168
    }
 
169
 
 
170
    private String versionStatus;
 
171
 
 
172
    public void setVersionStatus( String versionStatus )
 
173
    {
 
174
        this.versionStatus = versionStatus;
 
175
    }
 
176
 
 
177
    // -------------------------------------------------------------------------
 
178
    // Output
 
179
    // -------------------------------------------------------------------------
 
180
 
 
181
    private String message;
 
182
 
 
183
    public String getMessage()
 
184
    {
 
185
        return message;
 
186
    }
 
187
 
 
188
    // -------------------------------------------------------------------------
 
189
    // Action implementation
 
190
    // -------------------------------------------------------------------------
 
191
 
 
192
    public String execute()
 
193
    {     
 
194
        // -------------------------------------------------------------------------
 
195
        // name: required / unique
 
196
        // -------------------------------------------------------------------------
 
197
 
 
198
        if ( name == null )
 
199
        {
 
200
            message = i18n.getString( "specify_name" );
 
201
 
 
202
            return INPUT;
 
203
        }
 
204
        else
 
205
        {
 
206
            name = name.trim();
 
207
 
 
208
            if ( name.length() == 0 )
 
209
            {
 
210
                message = i18n.getString( "specify_name" );
 
211
 
 
212
                return INPUT;
 
213
            }
 
214
 
 
215
            DataElement match = dataElementService.getDataElementByName( name );
 
216
 
 
217
            if ( match != null && ( id == null || match.getId() != id ) )
 
218
            {
 
219
                message = i18n.getString( "name_in_use" );
 
220
 
 
221
                return INPUT;
 
222
            }
 
223
        }
 
224
        
 
225
        // -------------------------------------------------------------------------
 
226
        // shortName: required / unique
 
227
        // -------------------------------------------------------------------------
 
228
 
 
229
        if ( shortName == null )
 
230
        {
 
231
            message = i18n.getString( "specify_short_name" );
 
232
 
 
233
            return INPUT;
 
234
        }
 
235
        else
 
236
        {
 
237
            shortName = shortName.trim();
 
238
 
 
239
            if ( shortName.length() == 0 )
 
240
            {
 
241
                message = i18n.getString( "specify_short_name" );
 
242
 
 
243
                return INPUT;
 
244
            }
 
245
 
 
246
            DataElement match = dataElementService.getDataElementByShortName( shortName );
 
247
 
 
248
            if ( match != null && ( id == null || match.getId() != id ) )
 
249
            {
 
250
                message = i18n.getString( "short_name_in_use" );
 
251
 
 
252
                return INPUT;
 
253
            }
 
254
        }
 
255
 
 
256
        // -------------------------------------------------------------------------
 
257
        // alternativeName: required / unique
 
258
        // -------------------------------------------------------------------------
 
259
 
 
260
        if ( alternativeName == null )
 
261
        {
 
262
            message = i18n.getString( "specify_alternative_name" );
 
263
 
 
264
            return INPUT;
 
265
        }
 
266
        else
 
267
        {
 
268
            alternativeName = alternativeName.trim();
 
269
 
 
270
            if ( alternativeName.length() == 0 )
 
271
            {
 
272
                message = i18n.getString( "specify_alternative_name" );
 
273
 
 
274
                return INPUT;
 
275
            }
 
276
 
 
277
            DataElement match = dataElementService.getDataElementByAlternativeName( name );
 
278
 
 
279
            if ( match != null && ( id == null || match.getId() != id ) )
 
280
            {
 
281
                message = i18n.getString( "alternative_name_in_use" );
 
282
 
 
283
                return INPUT;
 
284
            }
 
285
        }
 
286
 
 
287
        // -------------------------------------------------------------------------
 
288
        // code: required / unique
 
289
        // -------------------------------------------------------------------------
 
290
        
 
291
        if ( code == null )
 
292
        {
 
293
            message = i18n.getString( "specify_code" );
 
294
            
 
295
            return INPUT;
 
296
        }
 
297
        else
 
298
        {
 
299
            code = code.trim();
 
300
            
 
301
            if ( code.length() == 0 )
 
302
            {
 
303
                message = i18n.getString( "specify_code" );
 
304
                
 
305
                return INPUT;
 
306
            }
 
307
            
 
308
            DataElement match = dataElementService.getDataElementByCode( code );
 
309
 
 
310
            if ( match != null && ( id == null || match.getId() != id ) )
 
311
            {
 
312
                message = i18n.getString( "code_in_use" );
 
313
 
 
314
                return INPUT;
 
315
            }
 
316
        }
 
317
 
 
318
        // -------------------------------------------------------------------------
 
319
        // description: required
 
320
        // -------------------------------------------------------------------------
 
321
 
 
322
        if ( description == null || description.trim().length() == 0 )
 
323
        {
 
324
            message = i18n.getString( "specify_description" );
 
325
            
 
326
            return INPUT;
 
327
        }
 
328
 
 
329
        // -------------------------------------------------------------------------
 
330
        // mnemonic: required
 
331
        // -------------------------------------------------------------------------
 
332
        
 
333
        if ( mnemonic == null || mnemonic.trim().length() == 0 )
 
334
        {
 
335
            message = i18n.getString( "specify_mnemonic" );
 
336
            
 
337
            return INPUT;
 
338
        }
 
339
 
 
340
        // -------------------------------------------------------------------------
 
341
        // version: required
 
342
        // -------------------------------------------------------------------------
 
343
 
 
344
        if ( version == null || version.trim().length() == 0 )
 
345
        {
 
346
            message = i18n.getString( "specify_version" );
 
347
            
 
348
            return INPUT;
 
349
        }
 
350
 
 
351
        // -------------------------------------------------------------------------
 
352
        // keywords: required
 
353
        // -------------------------------------------------------------------------
 
354
 
 
355
        if ( keywords == null || keywords.trim().length() == 0 )
 
356
        {
 
357
            message = i18n.getString( "specify_keywords" );
 
358
            
 
359
            return INPUT;
 
360
        }
 
361
        
 
362
        // -------------------------------------------------------------------------
 
363
        // dataelementtype: required
 
364
        // -------------------------------------------------------------------------
 
365
 
 
366
        if ( dataElementType == null || dataElementType.trim().length() == 0 || dataElementType.equals( "None" ) )
 
367
        {
 
368
            message = i18n.getString( "specify_data_element_type" );
 
369
            
 
370
            return INPUT;
 
371
        }
 
372
        
 
373
        // -------------------------------------------------------------------------
 
374
        // minimumSize: distinct number
 
375
        // -------------------------------------------------------------------------
 
376
 
 
377
        if ( minimumSize != null && minimumSize.trim().length() > 0 )
 
378
        {
 
379
            try
 
380
            {
 
381
                Integer.parseInt( minimumSize );
 
382
            }
 
383
            catch ( NumberFormatException ex )
 
384
            {
 
385
                message = i18n.getString( "specify_integer_minimum_size" );
 
386
                
 
387
                return INPUT;
 
388
            }
 
389
        }
 
390
 
 
391
        // -------------------------------------------------------------------------
 
392
        // maximumSize: distinct number
 
393
        // -------------------------------------------------------------------------
 
394
 
 
395
        if ( maximumSize != null && maximumSize.trim().length() > 0  )
 
396
        {
 
397
            try
 
398
            {
 
399
                Integer.parseInt( maximumSize );
 
400
            }
 
401
            catch ( NumberFormatException ex )
 
402
            {
 
403
                message = i18n.getString( "specify_integer_maximum_size" );
 
404
                
 
405
                return INPUT;
 
406
            }
 
407
        }
 
408
        
 
409
        // -------------------------------------------------------------------------
 
410
        // responsibleAuthority: required
 
411
        // -------------------------------------------------------------------------
 
412
 
 
413
        if ( responsibleAuthority == null || responsibleAuthority.trim().length() == 0 )
 
414
        {
 
415
            message = i18n.getString( "specify_responsible_authority" );
 
416
            
 
417
            return INPUT;
 
418
        }
 
419
        
 
420
        // -------------------------------------------------------------------------
 
421
        // location: required
 
422
        // -------------------------------------------------------------------------
 
423
 
 
424
        if ( location == null || location.trim().length() == 0 )
 
425
        {
 
426
            message = i18n.getString( "specify_location" );
 
427
            
 
428
            return INPUT;
 
429
        }
 
430
 
 
431
        // -------------------------------------------------------------------------
 
432
        // reportingMethods: required
 
433
        // -------------------------------------------------------------------------
 
434
 
 
435
        if ( reportingMethods == null || reportingMethods.trim().length() == 0 )
 
436
        {
 
437
            message = i18n.getString( "specify_reporting_methods" );
 
438
            
 
439
            return INPUT;
 
440
        }
 
441
 
 
442
        // -------------------------------------------------------------------------
 
443
        // versionStatus: required
 
444
        // -------------------------------------------------------------------------
 
445
 
 
446
        if ( versionStatus == null || versionStatus.trim().length() == 0 )
 
447
        {
 
448
            message = i18n.getString( "specify_version_status" );
 
449
            
 
450
            return INPUT;
 
451
        }
 
452
 
 
453
        message = i18n.getString( "everything_is_ok" );
 
454
 
 
455
        return SUCCESS;
 
456
    }
 
457
}