1
package org.hisp.dhis.dd.action.extendedindicator;
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.i18n.I18n;
31
import org.hisp.dhis.indicator.Indicator;
32
import org.hisp.dhis.indicator.IndicatorService;
34
import com.opensymphony.xwork.ActionSupport;
37
* @author Lars Helge Overland
40
public class ValidateExtendedIndicatorAction
43
// -------------------------------------------------------------------------
45
// -------------------------------------------------------------------------
47
private IndicatorService indicatorService;
49
public void setIndicatorService( IndicatorService indicatorService )
51
this.indicatorService = indicatorService;
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 Integer indicatorTypeId;
102
public void setIndicatorTypeId( Integer indicatorTypeId )
104
this.indicatorTypeId = indicatorTypeId;
107
private String numeratorDescription;
109
public void setNumeratorDescription( String numeratorDescription )
111
this.numeratorDescription = numeratorDescription;
114
private String denominatorDescription;
116
public void setDenominatorDescription( String denominatorDescription )
118
this.denominatorDescription = denominatorDescription;
121
private String mnemonic;
123
public void setMnemonic( String mnemonic )
125
this.mnemonic = mnemonic;
128
private String version;
130
public void setVersion( String version )
132
this.version = version;
135
private String description;
137
public void setDescription( String description )
139
this.description = description;
142
private String keywords;
144
public void setKeywords( String keywords )
146
this.keywords = keywords;
149
private String minimumSize;
151
public void setMinimumSize( String minimumSize )
153
this.minimumSize = minimumSize;
156
private String maximumSize;
158
public void setMaximumSize( String maximumSize )
160
this.maximumSize = maximumSize;
163
private String responsibleAuthority;
165
public void setResponsibleAuthority( String responsibleAuthority )
167
this.responsibleAuthority = responsibleAuthority;
170
private String location;
172
public void setLocation( String location )
174
this.location = location;
177
private String reportingMethods;
179
public void setReportingMethods( String reportingMethods )
181
this.reportingMethods = reportingMethods;
184
private String versionStatus;
186
public void setVersionStatus( String versionStatus )
188
this.versionStatus = versionStatus;
191
// -------------------------------------------------------------------------
193
// -------------------------------------------------------------------------
195
private String message;
197
public String getMessage()
202
// -------------------------------------------------------------------------
203
// Action implementation
204
// -------------------------------------------------------------------------
206
public String execute()
208
// -------------------------------------------------------------------------
209
// name: required / unique
210
// -------------------------------------------------------------------------
214
message = i18n.getString( "specify_name" );
222
if ( name.length() == 0 )
224
message = i18n.getString( "specify_name" );
229
Indicator match = indicatorService.getIndicatorByName( name );
231
if ( match != null && (id == null || match.getId() != id) )
233
message = i18n.getString( "name_in_use" );
239
// -------------------------------------------------------------------------
240
// shortName: required / unique
241
// -------------------------------------------------------------------------
243
if ( shortName == null )
245
message = i18n.getString( "specify_short_name" );
251
shortName = shortName.trim();
253
if ( shortName.length() == 0 )
255
message = i18n.getString( "specify_short_name" );
260
Indicator match = indicatorService.getIndicatorByShortName( shortName );
262
if ( match != null && (id == null || match.getId() != id) )
264
message = i18n.getString( "short_name_in_use" );
270
// -------------------------------------------------------------------------
271
// alternativeName: unique
272
// -------------------------------------------------------------------------
274
if ( alternativeName != null && alternativeName.trim().length() != 0 )
276
Indicator match = indicatorService.getIndicatorByAlternativeName( alternativeName );
278
if ( match != null && (id == null || match.getId() != id) )
280
message = i18n.getString( "alternative_name_in_use" );
286
// -------------------------------------------------------------------------
288
// -------------------------------------------------------------------------
290
if ( code != null && code.trim().length() != 0 )
292
Indicator match = indicatorService.getIndicatorByCode( code );
294
if ( match != null && (id == null || match.getId() != id) )
296
message = i18n.getString( "code_in_use" );
302
// -------------------------------------------------------------------------
303
// description: required
304
// -------------------------------------------------------------------------
306
if ( description == null || description.trim().length() == 0 )
308
message = i18n.getString( "specify_description" );
313
if ( indicatorTypeId == null )
315
message = i18n.getString( "choose_indicator_type" );
320
// -------------------------------------------------------------------------
321
// numeratorDescription: required
322
// -------------------------------------------------------------------------
324
if ( numeratorDescription == null )
326
message = i18n.getString( "specify_numerator_description" );
329
// -------------------------------------------------------------------------
330
// denominatorDescription: required
331
// -------------------------------------------------------------------------
333
if ( denominatorDescription == null )
335
message = i18n.getString( "specify_denominator_description" );
338
// -------------------------------------------------------------------------
339
// mnemonic: required
340
// -------------------------------------------------------------------------
342
if ( mnemonic == null || mnemonic.trim().length() == 0 )
344
message = i18n.getString( "specify_mnemonic" );
349
// -------------------------------------------------------------------------
351
// -------------------------------------------------------------------------
353
if ( version == null || version.trim().length() == 0 )
355
message = i18n.getString( "specify_version" );
360
// -------------------------------------------------------------------------
361
// keywords: required
362
// -------------------------------------------------------------------------
364
if ( keywords == null || keywords.trim().length() == 0 )
366
message = i18n.getString( "specify_keywords" );
371
// -------------------------------------------------------------------------
372
// minimumSize: distinct number
373
// -------------------------------------------------------------------------
375
if ( minimumSize != null && minimumSize.trim().length() > 0 )
379
Integer.parseInt( minimumSize );
381
catch ( NumberFormatException ex )
383
message = i18n.getString( "specify_integer_minimum_size" );
389
// -------------------------------------------------------------------------
390
// maximumSize: distinct number
391
// -------------------------------------------------------------------------
393
if ( maximumSize != null && maximumSize.trim().length() > 0 )
397
Integer.parseInt( maximumSize );
399
catch ( NumberFormatException ex )
401
message = i18n.getString( "specify_integer_maximum_size" );
407
// -------------------------------------------------------------------------
408
// responsibleAuthority: required
409
// -------------------------------------------------------------------------
411
if ( responsibleAuthority == null || responsibleAuthority.trim().length() == 0 )
413
message = i18n.getString( "specify_responsible_authority" );
418
// -------------------------------------------------------------------------
419
// location: required
420
// -------------------------------------------------------------------------
422
if ( location == null || location.trim().length() == 0 )
424
message = i18n.getString( "specify_location" );
429
// -------------------------------------------------------------------------
430
// reportingMethods: required
431
// -------------------------------------------------------------------------
433
if ( reportingMethods == null || reportingMethods.trim().length() == 0 )
435
message = i18n.getString( "specify_reporting_methods" );
440
// -------------------------------------------------------------------------
441
// versionStatus: required
442
// -------------------------------------------------------------------------
444
if ( versionStatus == null || versionStatus.trim().length() == 0 )
446
message = i18n.getString( "specify_version_status" );
451
message = i18n.getString( "everything_is_ok" );