~stian-sandvold/dhis2/UserSettingFallback

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/caseaggregation/ValidateCaseAggregationConditionAction.java

  • Committer: Stian Sandvold
  • Date: 2016-03-14 12:16:33 UTC
  • mfrom: (21871.1.422 dhis2)
  • Revision ID: stian.sandvold@gmail.com-20160314121633-ojggeaoszdunzltj
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.hisp.dhis.trackedentity.action.caseaggregation;
2
 
 
3
 
/*
4
 
 * Copyright (c) 2004-2016, 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
 
 *
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.
18
 
 *
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.
29
 
 */
30
 
 
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;
38
 
 
39
 
import com.opensymphony.xwork2.Action;
40
 
 
41
 
/**
42
 
 * @author Chau Thu Tran
43
 
 * @version $ ValidateCaseAggregationConditionAction.java Jul 28, 2011 12:53:50
44
 
 *          PM $
45
 
 * 
46
 
 */
47
 
public class ValidateCaseAggregationConditionAction
48
 
    implements Action
49
 
{
50
 
    // -------------------------------------------------------------------------
51
 
    // Dependencies
52
 
    // -------------------------------------------------------------------------
53
 
 
54
 
    private CaseAggregationConditionService aggregationConditionService;
55
 
 
56
 
    public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
57
 
    {
58
 
        this.aggregationConditionService = aggregationConditionService;
59
 
    }
60
 
 
61
 
    private DataElementService dataElementService;
62
 
 
63
 
    public void setDataElementService( DataElementService dataElementService )
64
 
    {
65
 
        this.dataElementService = dataElementService;
66
 
    }
67
 
 
68
 
    private DataElementCategoryService dataElementCategoryService;
69
 
 
70
 
    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
71
 
    {
72
 
        this.dataElementCategoryService = dataElementCategoryService;
73
 
    }
74
 
 
75
 
    // -------------------------------------------------------------------------
76
 
    // Input
77
 
    // -------------------------------------------------------------------------
78
 
    private Integer id;
79
 
 
80
 
    public void setId( Integer id )
81
 
    {
82
 
        this.id = id;
83
 
    }
84
 
 
85
 
    private String aggregationDataElementId;
86
 
 
87
 
    public void setAggregationDataElementId( String aggregationDataElementId )
88
 
    {
89
 
        this.aggregationDataElementId = aggregationDataElementId;
90
 
    }
91
 
 
92
 
    private String message;
93
 
 
94
 
    public String getMessage()
95
 
    {
96
 
        return message;
97
 
    }
98
 
 
99
 
    private I18n i18n;
100
 
 
101
 
    public void setI18n( I18n i18n )
102
 
    {
103
 
        this.i18n = i18n;
104
 
    }
105
 
 
106
 
    // -------------------------------------------------------------------------
107
 
    // Action implementation
108
 
    // -------------------------------------------------------------------------
109
 
 
110
 
    @Override
111
 
    public String execute()
112
 
        throws Exception
113
 
    {
114
 
        String[] ids = aggregationDataElementId.split( "\\." );
115
 
 
116
 
        DataElement aggregationDataElement = dataElementService.getDataElement( Integer.parseInt( ids[0] ) );
117
 
 
118
 
        DataElementCategoryOptionCombo optionCombo = dataElementCategoryService
119
 
            .getDataElementCategoryOptionCombo( Integer.parseInt( ids[1] ) );
120
 
 
121
 
        CaseAggregationCondition condition = aggregationConditionService.getCaseAggregationCondition(
122
 
            aggregationDataElement, optionCombo );
123
 
 
124
 
        if ( id != null && condition != null )
125
 
        {
126
 
            CaseAggregationCondition match = aggregationConditionService.getCaseAggregationCondition( id );
127
 
 
128
 
            if ( match != condition )
129
 
            {
130
 
                message = i18n.getString( "aggregation_data_element_in_use" );
131
 
                return INPUT;
132
 
            }
133
 
        }
134
 
        else if ( condition != null )
135
 
        {
136
 
            message = i18n.getString( "aggregation_data_element_in_use" );
137
 
            return INPUT;
138
 
        }
139
 
 
140
 
        message = i18n.getString( "everything_is_ok" );
141
 
        return SUCCESS;
142
 
    }
143
 
}