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 java.util.Date;
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;
39
import com.opensymphony.xwork.ActionSupport;
41
import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
44
* @author Lars Helge Overland
47
public class AddExtendedIndicatorAction
50
// -------------------------------------------------------------------------
52
// -------------------------------------------------------------------------
54
private IndicatorService indicatorService;
56
public void setIndicatorService( IndicatorService indicatorService )
58
this.indicatorService = indicatorService;
61
private I18nFormat format;
63
public void setFormat( I18nFormat format )
68
// -------------------------------------------------------------------------
70
// -------------------------------------------------------------------------
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 description;
102
public void setDescription( String description )
104
this.description = description;
107
private boolean annualized;
109
public void setAnnualized( boolean annualized )
111
this.annualized = annualized;
114
private Integer indicatorTypeId;
116
public void setIndicatorTypeId( Integer indicatorTypeId )
118
this.indicatorTypeId = indicatorTypeId;
121
private String numerator;
123
public void setNumerator( String numerator )
125
this.numerator = numerator;
128
private String numeratorDescription;
130
public void setNumeratorDescription( String numeratorDescription )
132
this.numeratorDescription = numeratorDescription;
135
private String numeratorAggregationOperator;
137
public void setNumeratorAggregationOperator( String numeratorAggregationOperator )
139
this.numeratorAggregationOperator = numeratorAggregationOperator;
142
private String denominator;
144
public void setDenominator( String denominator )
146
this.denominator = denominator;
149
private String denominatorDescription;
151
public void setDenominatorDescription( String denominatorDescription )
153
this.denominatorDescription = denominatorDescription;
156
private String denominatorAggregationOperator;
158
public void setDenominatorAggregationOperator( String denominatorAggregationOperator )
160
this.denominatorAggregationOperator = denominatorAggregationOperator;
163
// -------------------------------------------------------------------------
164
// Identifying and Definitional attributes
165
// -------------------------------------------------------------------------
167
private String mnemonic;
169
public void setMnemonic( String mnemonic )
171
this.mnemonic = mnemonic;
174
private String version;
176
public void setVersion( String version )
178
this.version = version;
181
private String context;
183
public void setContext( String context )
185
this.context = context;
188
private String synonyms;
190
public void setSynonyms( String synonyms )
192
this.synonyms = synonyms;
195
private String hononyms;
197
public void setHononyms( String hononyms )
199
this.hononyms = hononyms;
202
private String keywords;
204
public void setKeywords( String keywords )
206
this.keywords = keywords;
209
private String status;
211
public void setStatus( String status )
213
this.status = status;
216
private String statusDate;
218
public void setStatusDate( String statusDate )
220
this.statusDate = statusDate;
223
private String dataElementType;
225
public void setDataElementType( String dataElementType )
227
this.dataElementType = dataElementType;
230
// -------------------------------------------------------------------------
231
// Relational and Representational attributes
232
// -------------------------------------------------------------------------
234
private String dataType;
236
public void setDataType( String dataType )
238
this.dataType = dataType;
241
private String representationalForm;
243
public void setRepresentationalForm( String representationalForm )
245
this.representationalForm = representationalForm;
248
private String representationalLayout;
250
public void setRepresentationalLayout( String representationalLayout )
252
this.representationalLayout = representationalLayout;
255
private Integer minimumSize;
257
public void setMinimumSize( Integer minimumSize )
259
this.minimumSize = minimumSize;
262
private Integer maximumSize;
264
public void setMaximumSize( Integer maximumSize )
266
this.maximumSize = maximumSize;
269
private String dataDomain;
271
public void setDataDomain( String dataDomain )
273
this.dataDomain = dataDomain;
276
private String validationRules;
278
public void setValidationRules( String validationRules )
280
this.validationRules = validationRules;
283
private String relatedDataReferences;
285
public void setRelatedDataReferences( String relatedDataReferences )
287
this.relatedDataReferences = relatedDataReferences;
290
private String guideForUse;
292
public void setGuideForUse( String guideForUse )
294
this.guideForUse = guideForUse;
297
private String collectionMethods;
299
public void setCollectionMethods( String collectionMethods )
301
this.collectionMethods = collectionMethods;
304
// -------------------------------------------------------------------------
305
// Administrative attributes
306
// -------------------------------------------------------------------------
308
private String responsibleAuthority;
310
public void setResponsibleAuthority( String responsibleAuthority )
312
this.responsibleAuthority = responsibleAuthority;
315
private String updateRules;
317
public void setUpdateRules( String updateRules )
319
this.updateRules = updateRules;
322
private String accessAuthority;
324
public void setAccessAuthority( String accessAuthority )
326
this.accessAuthority = accessAuthority;
329
private String updateFrequency;
331
public void setUpdateFrequency( String updateFrequency )
333
this.updateFrequency = updateFrequency;
336
private String location;
338
public void setLocation( String location )
340
this.location = location;
343
private String reportingMethods;
345
public void setReportingMethods( String reportingMethods )
347
this.reportingMethods = reportingMethods;
350
private String versionStatus;
352
public void setVersionStatus( String versionStatus )
354
this.versionStatus = versionStatus;
357
private String previousVersionReferences;
359
public void setPreviousVersionReferences( String previousVersionReferences )
361
this.previousVersionReferences = previousVersionReferences;
364
private String sourceDocument;
366
public void setSourceDocument( String sourceDocument )
368
this.sourceDocument = sourceDocument;
371
private String sourceOrganisation;
373
public void setSourceOrganisation( String sourceOrganisation )
375
this.sourceOrganisation = sourceOrganisation;
378
private String comment;
380
public void setComment( String comment )
382
this.comment = comment;
385
// -------------------------------------------------------------------------
386
// Action implementation
387
// -------------------------------------------------------------------------
389
public String execute()
392
// ---------------------------------------------------------------------
394
// ---------------------------------------------------------------------
396
if ( alternativeName != null && alternativeName.trim().length() == 0 )
398
alternativeName = null;
401
if ( code != null && code.trim().length() == 0 )
406
if ( description != null && description.trim().length() == 0 )
411
if ( numerator != null && numerator.trim().length() == 0 )
416
if ( numeratorDescription != null && numeratorDescription.trim().length() == 0 )
418
numeratorDescription = null;
421
if ( numeratorAggregationOperator != null && numeratorAggregationOperator.trim().length() == 0 )
423
numeratorAggregationOperator = DataElement.AGGREGATION_OPERATOR_SUM;
426
if ( denominator != null && denominator.trim().length() == 0 )
431
if ( denominatorDescription != null && denominatorDescription.trim().length() == 0 )
433
denominatorDescription = null;
436
if ( denominatorAggregationOperator != null && denominatorAggregationOperator.trim().length() == 0 )
438
denominatorAggregationOperator = DataElement.AGGREGATION_OPERATOR_SUM;
441
if ( context != null && context.trim().length() == 0 )
446
if ( synonyms != null && synonyms.trim().length() == 0 )
451
if ( hononyms != null && hononyms.trim().length() == 0 )
456
if ( statusDate != null && statusDate.trim().length() == 0 )
461
if ( representationalLayout != null && representationalLayout.trim().length() == 0 )
463
representationalLayout = null;
466
if ( dataDomain != null && dataDomain.trim().length() == 0 )
471
if ( validationRules != null && validationRules.trim().length() == 0 )
473
validationRules = null;
476
if ( relatedDataReferences != null && relatedDataReferences.trim().length() == 0 )
478
relatedDataReferences = null;
481
if ( guideForUse != null && guideForUse.trim().length() == 0 )
486
if ( collectionMethods != null && collectionMethods.trim().length() == 0 )
488
collectionMethods = null;
491
if ( updateRules != null && updateRules.trim().length() == 0 )
496
if ( accessAuthority != null && accessAuthority.trim().length() == 0 )
498
accessAuthority = null;
501
if ( updateFrequency != null && updateFrequency.trim().length() == 0 )
503
updateFrequency = null;
506
if ( previousVersionReferences != null && previousVersionReferences.trim().length() == 0 )
508
previousVersionReferences = null;
511
if ( sourceDocument != null && sourceDocument.trim().length() == 0 )
513
sourceDocument = null;
516
if ( sourceOrganisation != null && sourceOrganisation.trim().length() == 0 )
518
sourceOrganisation = null;
521
if ( comment != null && comment.trim().length() == 0 )
526
IndicatorType indicatorType = indicatorService.getIndicatorType( indicatorTypeId );
528
Indicator indicator = new Indicator();
530
// -------------------------------------------------------------------------
532
// -------------------------------------------------------------------------
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 ) );
548
ExtendedDataElement extendedDataElement = new ExtendedDataElement();
550
// -------------------------------------------------------------------------
551
// Identifying and Definitional attributes
552
// -------------------------------------------------------------------------
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 ) );
564
// -------------------------------------------------------------------------
565
// Relational and Representational attributes
566
// -------------------------------------------------------------------------
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 ) );
579
// -------------------------------------------------------------------------
580
// Administrative attributes
581
// -------------------------------------------------------------------------
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() );
597
indicator.setExtended( extendedDataElement );
599
indicatorService.addIndicator( indicator );