1
package org.hisp.dhis.trackedentity.action.caseaggregation;
4
* Copyright (c) 2004-2016, 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.
12
* Redistributions in binary form must reproduce the above copyright notice,
13
* this list of conditions and the following disclaimer in the documentation
14
* and/or other materials provided with the distribution.
15
* Neither the name of the HISP project nor the names of its contributors may
16
* be used to endorse or promote products derived from this software without
17
* specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
32
import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
33
import org.hisp.dhis.dataelement.DataElement;
34
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
35
import org.hisp.dhis.dataelement.DataElementCategoryService;
36
import org.hisp.dhis.dataelement.DataElementService;
37
import org.hisp.dhis.i18n.I18n;
39
import com.opensymphony.xwork2.Action;
42
* @author Chau Thu Tran
43
* @version $ ValidateCaseAggregationConditionAction.java Jul 28, 2011 12:53:50
47
public class ValidateCaseAggregationConditionAction
50
// -------------------------------------------------------------------------
52
// -------------------------------------------------------------------------
54
private CaseAggregationConditionService aggregationConditionService;
56
public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
58
this.aggregationConditionService = aggregationConditionService;
61
private DataElementService dataElementService;
63
public void setDataElementService( DataElementService dataElementService )
65
this.dataElementService = dataElementService;
68
private DataElementCategoryService dataElementCategoryService;
70
public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
72
this.dataElementCategoryService = dataElementCategoryService;
75
// -------------------------------------------------------------------------
77
// -------------------------------------------------------------------------
80
public void setId( Integer id )
85
private String aggregationDataElementId;
87
public void setAggregationDataElementId( String aggregationDataElementId )
89
this.aggregationDataElementId = aggregationDataElementId;
92
private String message;
94
public String getMessage()
101
public void setI18n( I18n i18n )
106
// -------------------------------------------------------------------------
107
// Action implementation
108
// -------------------------------------------------------------------------
111
public String execute()
114
String[] ids = aggregationDataElementId.split( "\\." );
116
DataElement aggregationDataElement = dataElementService.getDataElement( Integer.parseInt( ids[0] ) );
118
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService
119
.getDataElementCategoryOptionCombo( Integer.parseInt( ids[1] ) );
121
CaseAggregationCondition condition = aggregationConditionService.getCaseAggregationCondition(
122
aggregationDataElement, optionCombo );
124
if ( id != null && condition != null )
126
CaseAggregationCondition match = aggregationConditionService.getCaseAggregationCondition( id );
128
if ( match != condition )
130
message = i18n.getString( "aggregation_data_element_in_use" );
134
else if ( condition != null )
136
message = i18n.getString( "aggregation_data_element_in_use" );
140
message = i18n.getString( "everything_is_ok" );