1
package org.hisp.dhis.dd.action.indicator;
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 Torgeir Lorange Ostby
38
* @version $Id: ValidateIndicatorAction.java 4015 2007-11-15 14:46:04Z larshelg $
40
public class ValidateIndicatorAction
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 numerator;
109
public void setNumerator( String numerator )
111
this.numerator = numerator;
114
private String numeratorDescription;
116
public void setNumeratorDescription( String numeratorDescription )
118
this.numeratorDescription = numeratorDescription;
121
private String numeratorAggregationOperator;
123
public void setNumeratorAggregationOperator( String numeratorAggregationOperator )
125
this.numeratorAggregationOperator = numeratorAggregationOperator;
128
private String denominator;
130
public void setDenominator( String denominator )
132
this.denominator = denominator;
135
private String denominatorDescription;
137
public void setDenominatorDescription( String denominatorDescription )
139
this.denominatorDescription = denominatorDescription;
142
private String denominatorAggregationOperator;
144
public void setDenominatorAggregationOperator( String denominatorAggregationOperator )
146
this.denominatorAggregationOperator = denominatorAggregationOperator;
149
// -------------------------------------------------------------------------
151
// -------------------------------------------------------------------------
153
private String message;
155
public String getMessage()
160
// -------------------------------------------------------------------------
161
// Action implementation
162
// -------------------------------------------------------------------------
164
public String execute()
168
message = i18n.getString( "specify_name" );
176
if ( name.length() == 0 )
178
message = i18n.getString( "specify_name" );
183
Indicator match = indicatorService.getIndicatorByName( name );
185
if ( match != null && (id == null || match.getId() != id) )
187
message = i18n.getString( "name_in_use" );
193
if ( shortName == null )
195
message = i18n.getString( "specify_short_name" );
201
shortName = shortName.trim();
203
if ( shortName.length() == 0 )
205
message = i18n.getString( "specify_short_name" );
210
Indicator match = indicatorService.getIndicatorByShortName( shortName );
212
if ( match != null && (id == null || match.getId() != id) )
214
message = i18n.getString( "short_name_in_use" );
220
if ( alternativeName != null && alternativeName.trim().length() != 0 )
222
Indicator match = indicatorService.getIndicatorByAlternativeName( alternativeName );
224
if ( match != null && (id == null || match.getId() != id) )
226
message = i18n.getString( "alternative_name_in_use" );
232
if ( code != null && code.trim().length() != 0 )
234
Indicator match = indicatorService.getIndicatorByCode( code );
236
if ( match != null && (id == null || match.getId() != id) )
238
message = i18n.getString( "code_in_use" );
244
if ( indicatorTypeId == null )
246
message = i18n.getString( "choose_indicator_type" );
251
if ( numerator == null )
253
message = i18n.getString( "specify_numerator" );
256
if ( numeratorDescription == null )
258
message = i18n.getString( "specify_numerator_description" );
261
if ( numeratorAggregationOperator == null )
263
message = i18n.getString( "specify_numerator_agg_operator" );
266
if ( denominator == null )
268
message = i18n.getString( "specify_denominator" );
271
if ( denominatorDescription == null )
273
message = i18n.getString( "specify_denominator_description" );
276
if ( denominatorAggregationOperator == null )
278
message = i18n.getString( "specify_denominator_agg_operator" );
281
message = i18n.getString( "everything_is_ok" );