1
package org.hisp.dhis.dd.action.extendeddataelement;
4
* Copyright (c) 2004-2007, University of Oslo
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.
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.
30
import org.hisp.dhis.dataelement.DataElement;
31
import org.hisp.dhis.dataelement.DataElementService;
32
import org.hisp.dhis.i18n.I18n;
34
import com.opensymphony.xwork.ActionSupport;
37
* @author Lars Helge Overland
40
public class ValidateExtendedDataElementAction
43
// -------------------------------------------------------------------------
45
// -------------------------------------------------------------------------
47
private DataElementService dataElementService;
49
public void setDataElementService( DataElementService dataElementService )
51
this.dataElementService = dataElementService;
56
public void setI18n( I18n i18n )
61
// -------------------------------------------------------------------------
63
// -------------------------------------------------------------------------
67
public void setId( Integer id )
74
public void setName( String name )
79
private String shortName;
81
public void setShortName( String shortName )
83
this.shortName = shortName;
86
private String alternativeName;
88
public void setAlternativeName( String alternativeName )
90
this.alternativeName = alternativeName;
95
public void setCode( String code )
100
private String mnemonic;
102
public void setMnemonic( String mnemonic )
104
this.mnemonic = mnemonic;
107
private String version;
109
public void setVersion( String version )
111
this.version = version;
114
private String description;
116
public void setDescription( String description )
118
this.description = description;
121
private String keywords;
123
public void setKeywords( String keywords )
125
this.keywords = keywords;
128
private String dataElementType;
130
public void setDataElementType( String dataElementType )
132
this.dataElementType = dataElementType;
135
private String minimumSize;
137
public void setMinimumSize( String minimumSize )
139
this.minimumSize = minimumSize;
142
private String maximumSize;
144
public void setMaximumSize( String maximumSize )
146
this.maximumSize = maximumSize;
149
private String responsibleAuthority;
151
public void setResponsibleAuthority( String responsibleAuthority )
153
this.responsibleAuthority = responsibleAuthority;
156
private String location;
158
public void setLocation( String location )
160
this.location = location;
163
private String reportingMethods;
165
public void setReportingMethods( String reportingMethods )
167
this.reportingMethods = reportingMethods;
170
private String versionStatus;
172
public void setVersionStatus( String versionStatus )
174
this.versionStatus = versionStatus;
177
// -------------------------------------------------------------------------
179
// -------------------------------------------------------------------------
181
private String message;
183
public String getMessage()
188
// -------------------------------------------------------------------------
189
// Action implementation
190
// -------------------------------------------------------------------------
192
public String execute()
194
// -------------------------------------------------------------------------
195
// name: required / unique
196
// -------------------------------------------------------------------------
200
message = i18n.getString( "specify_name" );
208
if ( name.length() == 0 )
210
message = i18n.getString( "specify_name" );
215
DataElement match = dataElementService.getDataElementByName( name );
217
if ( match != null && ( id == null || match.getId() != id ) )
219
message = i18n.getString( "name_in_use" );
225
// -------------------------------------------------------------------------
226
// shortName: required / unique
227
// -------------------------------------------------------------------------
229
if ( shortName == null )
231
message = i18n.getString( "specify_short_name" );
237
shortName = shortName.trim();
239
if ( shortName.length() == 0 )
241
message = i18n.getString( "specify_short_name" );
246
DataElement match = dataElementService.getDataElementByShortName( shortName );
248
if ( match != null && ( id == null || match.getId() != id ) )
250
message = i18n.getString( "short_name_in_use" );
256
// -------------------------------------------------------------------------
257
// alternativeName: required / unique
258
// -------------------------------------------------------------------------
260
if ( alternativeName == null )
262
message = i18n.getString( "specify_alternative_name" );
268
alternativeName = alternativeName.trim();
270
if ( alternativeName.length() == 0 )
272
message = i18n.getString( "specify_alternative_name" );
277
DataElement match = dataElementService.getDataElementByAlternativeName( name );
279
if ( match != null && ( id == null || match.getId() != id ) )
281
message = i18n.getString( "alternative_name_in_use" );
287
// -------------------------------------------------------------------------
288
// code: required / unique
289
// -------------------------------------------------------------------------
293
message = i18n.getString( "specify_code" );
301
if ( code.length() == 0 )
303
message = i18n.getString( "specify_code" );
308
DataElement match = dataElementService.getDataElementByCode( code );
310
if ( match != null && ( id == null || match.getId() != id ) )
312
message = i18n.getString( "code_in_use" );
318
// -------------------------------------------------------------------------
319
// description: required
320
// -------------------------------------------------------------------------
322
if ( description == null || description.trim().length() == 0 )
324
message = i18n.getString( "specify_description" );
329
// -------------------------------------------------------------------------
330
// mnemonic: required
331
// -------------------------------------------------------------------------
333
if ( mnemonic == null || mnemonic.trim().length() == 0 )
335
message = i18n.getString( "specify_mnemonic" );
340
// -------------------------------------------------------------------------
342
// -------------------------------------------------------------------------
344
if ( version == null || version.trim().length() == 0 )
346
message = i18n.getString( "specify_version" );
351
// -------------------------------------------------------------------------
352
// keywords: required
353
// -------------------------------------------------------------------------
355
if ( keywords == null || keywords.trim().length() == 0 )
357
message = i18n.getString( "specify_keywords" );
362
// -------------------------------------------------------------------------
363
// dataelementtype: required
364
// -------------------------------------------------------------------------
366
if ( dataElementType == null || dataElementType.trim().length() == 0 || dataElementType.equals( "None" ) )
368
message = i18n.getString( "specify_data_element_type" );
373
// -------------------------------------------------------------------------
374
// minimumSize: distinct number
375
// -------------------------------------------------------------------------
377
if ( minimumSize != null && minimumSize.trim().length() > 0 )
381
Integer.parseInt( minimumSize );
383
catch ( NumberFormatException ex )
385
message = i18n.getString( "specify_integer_minimum_size" );
391
// -------------------------------------------------------------------------
392
// maximumSize: distinct number
393
// -------------------------------------------------------------------------
395
if ( maximumSize != null && maximumSize.trim().length() > 0 )
399
Integer.parseInt( maximumSize );
401
catch ( NumberFormatException ex )
403
message = i18n.getString( "specify_integer_maximum_size" );
409
// -------------------------------------------------------------------------
410
// responsibleAuthority: required
411
// -------------------------------------------------------------------------
413
if ( responsibleAuthority == null || responsibleAuthority.trim().length() == 0 )
415
message = i18n.getString( "specify_responsible_authority" );
420
// -------------------------------------------------------------------------
421
// location: required
422
// -------------------------------------------------------------------------
424
if ( location == null || location.trim().length() == 0 )
426
message = i18n.getString( "specify_location" );
431
// -------------------------------------------------------------------------
432
// reportingMethods: required
433
// -------------------------------------------------------------------------
435
if ( reportingMethods == null || reportingMethods.trim().length() == 0 )
437
message = i18n.getString( "specify_reporting_methods" );
442
// -------------------------------------------------------------------------
443
// versionStatus: required
444
// -------------------------------------------------------------------------
446
if ( versionStatus == null || versionStatus.trim().length() == 0 )
448
message = i18n.getString( "specify_version_status" );
453
message = i18n.getString( "everything_is_ok" );