~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/extendedindicator/AddExtendedIndicatorAction.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.extendedindicator;
 
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 java.util.Date;
 
31
 
 
32
import org.hisp.dhis.datadictionary.ExtendedDataElement;
 
33
import org.hisp.dhis.dataelement.DataElement;
 
34
import org.hisp.dhis.i18n.I18nFormat;
 
35
import org.hisp.dhis.indicator.Indicator;
 
36
import org.hisp.dhis.indicator.IndicatorService;
 
37
import org.hisp.dhis.indicator.IndicatorType;
 
38
 
 
39
import com.opensymphony.xwork.ActionSupport;
 
40
 
 
41
import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
 
42
 
 
43
/**
 
44
 * @author Lars Helge Overland
 
45
 * @version $Id$
 
46
 */
 
47
public class AddExtendedIndicatorAction
 
48
    extends ActionSupport
 
49
{
 
50
    // -------------------------------------------------------------------------
 
51
    // Dependencies
 
52
    // -------------------------------------------------------------------------
 
53
 
 
54
    private IndicatorService indicatorService;
 
55
 
 
56
    public void setIndicatorService( IndicatorService indicatorService )
 
57
    {
 
58
        this.indicatorService = indicatorService;
 
59
    }
 
60
 
 
61
    private I18nFormat format;
 
62
 
 
63
    public void setFormat( I18nFormat format )
 
64
    {
 
65
        this.format = format;
 
66
    }
 
67
 
 
68
    // -------------------------------------------------------------------------
 
69
    // Indicator
 
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 description;
 
101
 
 
102
    public void setDescription( String description )
 
103
    {
 
104
        this.description = description;
 
105
    }
 
106
 
 
107
    private boolean annualized;
 
108
 
 
109
    public void setAnnualized( boolean annualized )
 
110
    {
 
111
        this.annualized = annualized;
 
112
    }
 
113
 
 
114
    private Integer indicatorTypeId;
 
115
 
 
116
    public void setIndicatorTypeId( Integer indicatorTypeId )
 
117
    {
 
118
        this.indicatorTypeId = indicatorTypeId;
 
119
    }
 
120
    
 
121
    private String numerator;
 
122
 
 
123
    public void setNumerator( String numerator )
 
124
    {
 
125
        this.numerator = numerator;
 
126
    }
 
127
    
 
128
    private String numeratorDescription;
 
129
 
 
130
    public void setNumeratorDescription( String numeratorDescription )
 
131
    {
 
132
        this.numeratorDescription = numeratorDescription;
 
133
    }
 
134
 
 
135
    private String numeratorAggregationOperator;
 
136
 
 
137
    public void setNumeratorAggregationOperator( String numeratorAggregationOperator )
 
138
    {
 
139
        this.numeratorAggregationOperator = numeratorAggregationOperator;
 
140
    }
 
141
 
 
142
    private String denominator;
 
143
 
 
144
    public void setDenominator( String denominator )
 
145
    {
 
146
        this.denominator = denominator;
 
147
    }
 
148
 
 
149
    private String denominatorDescription;
 
150
 
 
151
    public void setDenominatorDescription( String denominatorDescription )
 
152
    {
 
153
        this.denominatorDescription = denominatorDescription;
 
154
    }
 
155
 
 
156
    private String denominatorAggregationOperator;
 
157
 
 
158
    public void setDenominatorAggregationOperator( String denominatorAggregationOperator )
 
159
    {
 
160
        this.denominatorAggregationOperator = denominatorAggregationOperator;
 
161
    }
 
162
 
 
163
    // -------------------------------------------------------------------------
 
164
    // Identifying and Definitional attributes 
 
165
    // -------------------------------------------------------------------------
 
166
    
 
167
    private String mnemonic;
 
168
 
 
169
    public void setMnemonic( String mnemonic )
 
170
    {
 
171
        this.mnemonic = mnemonic;
 
172
    }    
 
173
    
 
174
    private String version;
 
175
 
 
176
    public void setVersion( String version )
 
177
    {
 
178
        this.version = version;
 
179
    }
 
180
    
 
181
    private String context;
 
182
 
 
183
    public void setContext( String context )
 
184
    {
 
185
        this.context = context;
 
186
    }    
 
187
 
 
188
    private String synonyms;
 
189
 
 
190
    public void setSynonyms( String synonyms )
 
191
    {
 
192
        this.synonyms = synonyms;
 
193
    }
 
194
    
 
195
    private String hononyms;
 
196
 
 
197
    public void setHononyms( String hononyms )
 
198
    {
 
199
        this.hononyms = hononyms;
 
200
    }
 
201
    
 
202
    private String keywords;
 
203
 
 
204
    public void setKeywords( String keywords )
 
205
    {
 
206
        this.keywords = keywords;
 
207
    }
 
208
    
 
209
    private String status;
 
210
 
 
211
    public void setStatus( String status )
 
212
    {
 
213
        this.status = status;
 
214
    }
 
215
    
 
216
    private String statusDate;
 
217
 
 
218
    public void setStatusDate( String statusDate )
 
219
    {
 
220
        this.statusDate = statusDate;
 
221
    }
 
222
    
 
223
    private String dataElementType;
 
224
 
 
225
    public void setDataElementType( String dataElementType )
 
226
    {
 
227
        this.dataElementType = dataElementType;
 
228
    }
 
229
 
 
230
    // -------------------------------------------------------------------------
 
231
    // Relational and Representational attributes
 
232
    // -------------------------------------------------------------------------
 
233
 
 
234
    private String dataType;
 
235
 
 
236
    public void setDataType( String dataType )
 
237
    {
 
238
        this.dataType = dataType;
 
239
    }
 
240
 
 
241
    private String representationalForm;
 
242
 
 
243
    public void setRepresentationalForm( String representationalForm )
 
244
    {
 
245
        this.representationalForm = representationalForm;
 
246
    }
 
247
 
 
248
    private String representationalLayout;
 
249
 
 
250
    public void setRepresentationalLayout( String representationalLayout )
 
251
    {
 
252
        this.representationalLayout = representationalLayout;
 
253
    }
 
254
 
 
255
    private Integer minimumSize;
 
256
 
 
257
    public void setMinimumSize( Integer minimumSize )
 
258
    {
 
259
        this.minimumSize = minimumSize;
 
260
    }
 
261
    
 
262
    private Integer maximumSize;
 
263
 
 
264
    public void setMaximumSize( Integer maximumSize )
 
265
    {
 
266
        this.maximumSize = maximumSize;
 
267
    }
 
268
 
 
269
    private String dataDomain;
 
270
 
 
271
    public void setDataDomain( String dataDomain )
 
272
    {
 
273
        this.dataDomain = dataDomain;
 
274
    }
 
275
 
 
276
    private String validationRules;
 
277
 
 
278
    public void setValidationRules( String validationRules )
 
279
    {
 
280
        this.validationRules = validationRules;
 
281
    }
 
282
 
 
283
    private String relatedDataReferences;
 
284
 
 
285
    public void setRelatedDataReferences( String relatedDataReferences )
 
286
    {
 
287
        this.relatedDataReferences = relatedDataReferences;
 
288
    }
 
289
 
 
290
    private String guideForUse;
 
291
 
 
292
    public void setGuideForUse( String guideForUse )
 
293
    {
 
294
        this.guideForUse = guideForUse;
 
295
    }
 
296
 
 
297
    private String collectionMethods;
 
298
 
 
299
    public void setCollectionMethods( String collectionMethods )
 
300
    {
 
301
        this.collectionMethods = collectionMethods;
 
302
    }
 
303
 
 
304
    // -------------------------------------------------------------------------
 
305
    // Administrative attributes 
 
306
    // -------------------------------------------------------------------------
 
307
 
 
308
    private String responsibleAuthority;
 
309
 
 
310
    public void setResponsibleAuthority( String responsibleAuthority )
 
311
    {
 
312
        this.responsibleAuthority = responsibleAuthority;
 
313
    }
 
314
 
 
315
    private String updateRules;
 
316
 
 
317
    public void setUpdateRules( String updateRules )
 
318
    {
 
319
        this.updateRules = updateRules;
 
320
    }
 
321
 
 
322
    private String accessAuthority;
 
323
 
 
324
    public void setAccessAuthority( String accessAuthority )
 
325
    {
 
326
        this.accessAuthority = accessAuthority;
 
327
    }
 
328
 
 
329
    private String updateFrequency;
 
330
 
 
331
    public void setUpdateFrequency( String updateFrequency )
 
332
    {
 
333
        this.updateFrequency = updateFrequency;
 
334
    }
 
335
 
 
336
    private String location;
 
337
 
 
338
    public void setLocation( String location )
 
339
    {
 
340
        this.location = location;
 
341
    }
 
342
 
 
343
    private String reportingMethods;
 
344
 
 
345
    public void setReportingMethods( String reportingMethods )
 
346
    {
 
347
        this.reportingMethods = reportingMethods;
 
348
    }
 
349
 
 
350
    private String versionStatus;
 
351
 
 
352
    public void setVersionStatus( String versionStatus )
 
353
    {
 
354
        this.versionStatus = versionStatus;
 
355
    }
 
356
 
 
357
    private String previousVersionReferences;
 
358
 
 
359
    public void setPreviousVersionReferences( String previousVersionReferences )
 
360
    {
 
361
        this.previousVersionReferences = previousVersionReferences;
 
362
    }
 
363
 
 
364
    private String sourceDocument;
 
365
 
 
366
    public void setSourceDocument( String sourceDocument )
 
367
    {
 
368
        this.sourceDocument = sourceDocument;
 
369
    }
 
370
 
 
371
    private String sourceOrganisation;
 
372
 
 
373
    public void setSourceOrganisation( String sourceOrganisation )
 
374
    {
 
375
        this.sourceOrganisation = sourceOrganisation;
 
376
    }
 
377
 
 
378
    private String comment;
 
379
 
 
380
    public void setComment( String comment )
 
381
    {
 
382
        this.comment = comment;
 
383
    }
 
384
    
 
385
    // -------------------------------------------------------------------------
 
386
    // Action implementation
 
387
    // -------------------------------------------------------------------------
 
388
 
 
389
    public String execute()
 
390
        throws Exception
 
391
    {
 
392
        // ---------------------------------------------------------------------
 
393
        // Prepare values
 
394
        // ---------------------------------------------------------------------
 
395
 
 
396
        if ( alternativeName != null && alternativeName.trim().length() == 0 )
 
397
        {
 
398
            alternativeName = null;
 
399
        }
 
400
 
 
401
        if ( code != null && code.trim().length() == 0 )
 
402
        {
 
403
            code = null;
 
404
        }
 
405
        
 
406
        if ( description != null && description.trim().length() == 0 )
 
407
        {
 
408
            description = null;
 
409
        }
 
410
 
 
411
        if ( numerator != null && numerator.trim().length() == 0 )
 
412
        {
 
413
            numerator = null;
 
414
        }
 
415
 
 
416
        if ( numeratorDescription != null && numeratorDescription.trim().length() == 0 )
 
417
        {
 
418
            numeratorDescription = null;
 
419
        }
 
420
 
 
421
        if ( numeratorAggregationOperator != null && numeratorAggregationOperator.trim().length() == 0 )
 
422
        {
 
423
            numeratorAggregationOperator = DataElement.AGGREGATION_OPERATOR_SUM;
 
424
        }
 
425
 
 
426
        if ( denominator != null && denominator.trim().length() == 0 )
 
427
        {
 
428
            denominator = null;
 
429
        }
 
430
 
 
431
        if ( denominatorDescription != null && denominatorDescription.trim().length() == 0 )
 
432
        {
 
433
            denominatorDescription = null;
 
434
        }
 
435
 
 
436
        if ( denominatorAggregationOperator != null && denominatorAggregationOperator.trim().length() == 0 )
 
437
        {
 
438
            denominatorAggregationOperator = DataElement.AGGREGATION_OPERATOR_SUM;
 
439
        }
 
440
        
 
441
        if ( context != null && context.trim().length() == 0 )
 
442
        {
 
443
            context = null;
 
444
        }
 
445
        
 
446
        if ( synonyms != null && synonyms.trim().length() == 0 )
 
447
        {
 
448
            synonyms = null;
 
449
        }
 
450
        
 
451
        if ( hononyms != null && hononyms.trim().length() == 0 )
 
452
        {
 
453
            hononyms = null;
 
454
        }
 
455
        
 
456
        if ( statusDate != null && statusDate.trim().length() == 0 )
 
457
        {
 
458
            statusDate = null;
 
459
        }
 
460
        
 
461
        if ( representationalLayout != null && representationalLayout.trim().length() == 0 )
 
462
        {
 
463
            representationalLayout = null;
 
464
        }
 
465
        
 
466
        if ( dataDomain != null && dataDomain.trim().length() == 0 )
 
467
        {
 
468
            dataDomain = null;
 
469
        }
 
470
 
 
471
        if ( validationRules != null && validationRules.trim().length() == 0 )
 
472
        {
 
473
            validationRules = null;
 
474
        }
 
475
 
 
476
        if ( relatedDataReferences != null && relatedDataReferences.trim().length() == 0 )
 
477
        {
 
478
            relatedDataReferences = null;
 
479
        }
 
480
 
 
481
        if ( guideForUse != null && guideForUse.trim().length() == 0 )
 
482
        {
 
483
            guideForUse = null;
 
484
        }
 
485
 
 
486
        if ( collectionMethods != null && collectionMethods.trim().length() == 0 )
 
487
        {
 
488
            collectionMethods = null;
 
489
        }
 
490
 
 
491
        if ( updateRules != null && updateRules.trim().length() == 0 )
 
492
        {
 
493
            updateRules = null;
 
494
        }
 
495
 
 
496
        if ( accessAuthority != null && accessAuthority.trim().length() == 0 )
 
497
        {
 
498
            accessAuthority = null;
 
499
        }
 
500
 
 
501
        if ( updateFrequency != null && updateFrequency.trim().length() == 0 )
 
502
        {
 
503
            updateFrequency = null;
 
504
        }
 
505
 
 
506
        if ( previousVersionReferences != null && previousVersionReferences.trim().length() == 0 )
 
507
        {
 
508
            previousVersionReferences = null;
 
509
        }
 
510
 
 
511
        if ( sourceDocument != null && sourceDocument.trim().length() == 0 )
 
512
        {
 
513
            sourceDocument = null;
 
514
        }
 
515
 
 
516
        if ( sourceOrganisation != null && sourceOrganisation.trim().length() == 0 )
 
517
        {
 
518
            sourceOrganisation = null;
 
519
        }
 
520
 
 
521
        if ( comment != null && comment.trim().length() == 0 )
 
522
        {
 
523
            comment = null;
 
524
        }
 
525
        
 
526
        IndicatorType indicatorType = indicatorService.getIndicatorType( indicatorTypeId );
 
527
 
 
528
        Indicator indicator = new Indicator();
 
529
 
 
530
        // -------------------------------------------------------------------------
 
531
        // Indicator
 
532
        // -------------------------------------------------------------------------
 
533
 
 
534
        indicator.setName( name );
 
535
        indicator.setAlternativeName( nullIfEmpty( alternativeName ) );
 
536
        indicator.setShortName( shortName );
 
537
        indicator.setCode( nullIfEmpty( code ) );
 
538
        indicator.setDescription( nullIfEmpty( description ) );
 
539
        indicator.setAnnualized( annualized );
 
540
        indicator.setIndicatorType( indicatorType );
 
541
        indicator.setNumerator( nullIfEmpty( numerator ) );
 
542
        indicator.setNumeratorDescription( nullIfEmpty( numeratorDescription ) );
 
543
        indicator.setNumeratorAggregationOperator( nullIfEmpty( numeratorAggregationOperator ) );
 
544
        indicator.setDenominator( nullIfEmpty( denominator ) );
 
545
        indicator.setDenominatorDescription( nullIfEmpty( denominatorDescription ) );
 
546
        indicator.setDenominatorAggregationOperator( nullIfEmpty( denominatorAggregationOperator ) );
 
547
        
 
548
        ExtendedDataElement extendedDataElement = new ExtendedDataElement();
 
549
        
 
550
        // -------------------------------------------------------------------------
 
551
        // Identifying and Definitional attributes 
 
552
        // -------------------------------------------------------------------------
 
553
        
 
554
        extendedDataElement.setMnemonic( nullIfEmpty( mnemonic ) );
 
555
        extendedDataElement.setVersion( nullIfEmpty( version ) );
 
556
        extendedDataElement.setContext( nullIfEmpty( context ) );
 
557
        extendedDataElement.setSynonyms( nullIfEmpty( synonyms ) );
 
558
        extendedDataElement.setHononyms( nullIfEmpty( hononyms ) );
 
559
        extendedDataElement.setKeywords( nullIfEmpty( keywords ) );
 
560
        extendedDataElement.setStatus( nullIfEmpty( status ) );
 
561
        extendedDataElement.setStatusDate( format.parseDate( statusDate ) );
 
562
        extendedDataElement.setDataElementType( nullIfEmpty( dataElementType ) );
 
563
        
 
564
        // -------------------------------------------------------------------------
 
565
        // Relational and Representational attributes
 
566
        // -------------------------------------------------------------------------
 
567
 
 
568
        extendedDataElement.setDataType( nullIfEmpty( dataType ) );
 
569
        extendedDataElement.setRepresentationalForm( nullIfEmpty( representationalForm ) );
 
570
        extendedDataElement.setRepresentationalLayout( nullIfEmpty( representationalLayout ) );
 
571
        extendedDataElement.setMinimumSize( minimumSize );
 
572
        extendedDataElement.setMaximumSize( maximumSize );
 
573
        extendedDataElement.setDataDomain( nullIfEmpty( dataDomain ) );
 
574
        extendedDataElement.setValidationRules( nullIfEmpty( validationRules ) );
 
575
        extendedDataElement.setRelatedDataReferences( nullIfEmpty( relatedDataReferences ) );
 
576
        extendedDataElement.setGuideForUse( nullIfEmpty( guideForUse ) );
 
577
        extendedDataElement.setCollectionMethods( nullIfEmpty( collectionMethods ) );
 
578
 
 
579
        // -------------------------------------------------------------------------
 
580
        // Administrative attributes 
 
581
        // -------------------------------------------------------------------------
 
582
 
 
583
        extendedDataElement.setResponsibleAuthority( nullIfEmpty( responsibleAuthority ) );
 
584
        extendedDataElement.setUpdateRules( nullIfEmpty( updateRules ) );
 
585
        extendedDataElement.setAccessAuthority( nullIfEmpty( accessAuthority ) );
 
586
        extendedDataElement.setUpdateFrequency( nullIfEmpty( updateFrequency ) );
 
587
        extendedDataElement.setLocation( nullIfEmpty( location ) );
 
588
        extendedDataElement.setReportingMethods( nullIfEmpty( reportingMethods ) );
 
589
        extendedDataElement.setVersionStatus( nullIfEmpty( versionStatus ) );
 
590
        extendedDataElement.setPreviousVersionReferences( nullIfEmpty( previousVersionReferences ) );
 
591
        extendedDataElement.setSourceDocument( nullIfEmpty( sourceDocument ) );
 
592
        extendedDataElement.setSourceOrganisation( nullIfEmpty( sourceOrganisation ) );
 
593
        extendedDataElement.setComment( nullIfEmpty( comment ) );
 
594
        extendedDataElement.setSaved( new Date() );
 
595
        extendedDataElement.setLastUpdated( new Date() );
 
596
        
 
597
        indicator.setExtended( extendedDataElement );
 
598
        
 
599
        indicatorService.addIndicator( indicator );
 
600
 
 
601
        return SUCCESS;
 
602
    }
 
603
}