~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/GetAllCaseAggregationConditionAction.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 java.util.ArrayList;
32
 
import java.util.Collection;
33
 
import java.util.Collections;
34
 
import java.util.HashSet;
35
 
import java.util.List;
36
 
 
37
 
import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
38
 
import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
39
 
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
40
 
import org.hisp.dhis.dataelement.DataElement;
41
 
import org.hisp.dhis.dataset.DataSet;
42
 
import org.hisp.dhis.dataset.DataSetService;
43
 
import org.hisp.dhis.paging.ActionPagingSupport;
44
 
 
45
 
/**
46
 
 * @author Chau Thu Tran
47
 
 * 
48
 
 * @version GetAllCaseAggregationConditionAction.java Nov 18, 2010 10:42:01 AM
49
 
 */
50
 
public class GetAllCaseAggregationConditionAction
51
 
    extends ActionPagingSupport<CaseAggregationCondition>
52
 
{
53
 
    // -------------------------------------------------------------------------
54
 
    // Dependency
55
 
    // -------------------------------------------------------------------------
56
 
 
57
 
    private CaseAggregationConditionService aggregationConditionService;
58
 
 
59
 
    public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
60
 
    {
61
 
        this.aggregationConditionService = aggregationConditionService;
62
 
    }
63
 
 
64
 
    public DataSetService dataSetService;
65
 
 
66
 
    public void setDataSetService( DataSetService dataSetService )
67
 
    {
68
 
        this.dataSetService = dataSetService;
69
 
    }
70
 
 
71
 
    // -------------------------------------------------------------------------
72
 
    // Getters && Setters
73
 
    // -------------------------------------------------------------------------
74
 
 
75
 
    private Integer dataSetId;
76
 
 
77
 
    public void setDataSetId( Integer dataSetId )
78
 
    {
79
 
        this.dataSetId = dataSetId;
80
 
    }
81
 
 
82
 
    public Integer getDataSetId()
83
 
    {
84
 
        return dataSetId;
85
 
    }
86
 
 
87
 
    private String key;
88
 
 
89
 
    public void setKey( String key )
90
 
    {
91
 
        this.key = key;
92
 
    }
93
 
 
94
 
    private Collection<CaseAggregationCondition> aggregationConditions;
95
 
 
96
 
    public Collection<CaseAggregationCondition> getAggregationConditions()
97
 
    {
98
 
        return aggregationConditions;
99
 
    }
100
 
 
101
 
    private List<DataSet> dataSets;
102
 
 
103
 
    public List<DataSet> getDataSets()
104
 
    {
105
 
        return dataSets;
106
 
    }
107
 
 
108
 
    // -------------------------------------------------------------------------
109
 
    // Action implementation
110
 
    // -------------------------------------------------------------------------
111
 
 
112
 
    @Override
113
 
    public String execute()
114
 
        throws Exception
115
 
    {
116
 
        Collection<DataSet> _datasets = new HashSet<>();
117
 
        aggregationConditions = aggregationConditionService.getAllCaseAggregationCondition();
118
 
 
119
 
        for ( CaseAggregationCondition aggCondition : aggregationConditions )
120
 
        {
121
 
            DataElement dataElement = aggCondition.getAggregationDataElement();
122
 
 
123
 
            _datasets.addAll( dataElement.getDataSets() );
124
 
        }
125
 
 
126
 
        dataSets = new ArrayList<>( _datasets );
127
 
        Collections.sort( dataSets, IdentifiableObjectNameComparator.INSTANCE );
128
 
 
129
 
        Collection<DataElement> dataElements = ( dataSetId == null ) ? null : dataSetService.getDataSet( dataSetId ).getDataElements();
130
 
        this.paging = createPaging( aggregationConditionService.countCaseAggregationCondition( dataElements, key ) );
131
 
        aggregationConditions = aggregationConditionService.getCaseAggregationConditions( dataElements, key,
132
 
            paging.getStartPos(), paging.getPageSize() );
133
 
        
134
 
        return SUCCESS;
135
 
    }
136
 
}