~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/indicator/ValidateIndicatorAction.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.indicator;
 
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 Torgeir Lorange Ostby
 
38
 * @version $Id: ValidateIndicatorAction.java 4015 2007-11-15 14:46:04Z larshelg $
 
39
 */
 
40
public class ValidateIndicatorAction
 
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 numerator;
 
108
 
 
109
    public void setNumerator( String numerator )
 
110
    {
 
111
        this.numerator = numerator;
 
112
    }
 
113
    
 
114
    private String numeratorDescription;
 
115
 
 
116
    public void setNumeratorDescription( String numeratorDescription )
 
117
    {
 
118
        this.numeratorDescription = numeratorDescription;
 
119
    }
 
120
 
 
121
    private String numeratorAggregationOperator;
 
122
 
 
123
    public void setNumeratorAggregationOperator( String numeratorAggregationOperator )
 
124
    {
 
125
        this.numeratorAggregationOperator = numeratorAggregationOperator;
 
126
    }
 
127
 
 
128
    private String denominator;
 
129
 
 
130
    public void setDenominator( String denominator )
 
131
    {
 
132
        this.denominator = denominator;
 
133
    }
 
134
 
 
135
    private String denominatorDescription;
 
136
 
 
137
    public void setDenominatorDescription( String denominatorDescription )
 
138
    {
 
139
        this.denominatorDescription = denominatorDescription;
 
140
    }
 
141
 
 
142
    private String denominatorAggregationOperator;
 
143
 
 
144
    public void setDenominatorAggregationOperator( String denominatorAggregationOperator )
 
145
    {
 
146
        this.denominatorAggregationOperator = denominatorAggregationOperator;
 
147
    }
 
148
    
 
149
    // -------------------------------------------------------------------------
 
150
    // Output
 
151
    // -------------------------------------------------------------------------
 
152
 
 
153
    private String message;
 
154
 
 
155
    public String getMessage()
 
156
    {
 
157
        return message;
 
158
    }
 
159
 
 
160
    // -------------------------------------------------------------------------
 
161
    // Action implementation
 
162
    // -------------------------------------------------------------------------
 
163
 
 
164
    public String execute()
 
165
    {
 
166
        if ( name == null )
 
167
        {
 
168
            message = i18n.getString( "specify_name" );
 
169
 
 
170
            return INPUT;
 
171
        }
 
172
        else
 
173
        {
 
174
            name = name.trim();
 
175
 
 
176
            if ( name.length() == 0 )
 
177
            {
 
178
                message = i18n.getString( "specify_name" );
 
179
 
 
180
                return INPUT;
 
181
            }
 
182
 
 
183
            Indicator match = indicatorService.getIndicatorByName( name );
 
184
 
 
185
            if ( match != null && (id == null || match.getId() != id) )
 
186
            {
 
187
                message = i18n.getString( "name_in_use" );
 
188
 
 
189
                return INPUT;
 
190
            }
 
191
        }
 
192
 
 
193
        if ( shortName == null )
 
194
        {
 
195
            message = i18n.getString( "specify_short_name" );
 
196
 
 
197
            return INPUT;
 
198
        }
 
199
        else
 
200
        {
 
201
            shortName = shortName.trim();
 
202
 
 
203
            if ( shortName.length() == 0 )
 
204
            {
 
205
                message = i18n.getString( "specify_short_name" );
 
206
 
 
207
                return INPUT;
 
208
            }
 
209
 
 
210
            Indicator match = indicatorService.getIndicatorByShortName( shortName );
 
211
 
 
212
            if ( match != null && (id == null || match.getId() != id) )
 
213
            {
 
214
                message = i18n.getString( "short_name_in_use" );
 
215
 
 
216
                return INPUT;
 
217
            }
 
218
        }
 
219
 
 
220
        if ( alternativeName != null && alternativeName.trim().length() != 0 )
 
221
        {
 
222
            Indicator match = indicatorService.getIndicatorByAlternativeName( alternativeName );
 
223
 
 
224
            if ( match != null && (id == null || match.getId() != id) )
 
225
            {
 
226
                message = i18n.getString( "alternative_name_in_use" );
 
227
 
 
228
                return INPUT;
 
229
            }
 
230
        }
 
231
 
 
232
        if ( code != null && code.trim().length() != 0 )
 
233
        {
 
234
            Indicator match = indicatorService.getIndicatorByCode( code );
 
235
 
 
236
            if ( match != null && (id == null || match.getId() != id) )
 
237
            {
 
238
                message = i18n.getString( "code_in_use" );
 
239
 
 
240
                return INPUT;
 
241
            }
 
242
        }
 
243
 
 
244
        if ( indicatorTypeId == null )
 
245
        {
 
246
            message = i18n.getString( "choose_indicator_type" );
 
247
 
 
248
            return INPUT;
 
249
        }
 
250
        
 
251
        if ( numerator == null )
 
252
        {
 
253
            message = i18n.getString( "specify_numerator" );
 
254
        }
 
255
        
 
256
        if ( numeratorDescription == null )
 
257
        {
 
258
            message = i18n.getString( "specify_numerator_description" );
 
259
        }
 
260
        
 
261
        if ( numeratorAggregationOperator == null )
 
262
        {
 
263
            message = i18n.getString( "specify_numerator_agg_operator" );
 
264
        }
 
265
        
 
266
        if ( denominator == null )
 
267
        {
 
268
            message = i18n.getString( "specify_denominator" );
 
269
        }
 
270
        
 
271
        if ( denominatorDescription == null )
 
272
        {
 
273
            message = i18n.getString( "specify_denominator_description" );
 
274
        }
 
275
        
 
276
        if ( denominatorAggregationOperator == null )
 
277
        {
 
278
            message = i18n.getString( "specify_denominator_agg_operator" );
 
279
        }
 
280
 
 
281
        message = i18n.getString( "everything_is_ok" );
 
282
 
 
283
        return SUCCESS;
 
284
    }
 
285
 
 
286
}