~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to local/vn/dhis-web-hue-reporttool/src/main/java/org/hisp/dhis/rt/action/ViewReportAction.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.rt.action;
 
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.ArrayList;
 
31
import java.util.Collection;
 
32
import java.util.Collections;
 
33
import java.util.Comparator;
 
34
import java.util.List;
 
35
 
 
36
import org.hisp.dhis.dataelement.DataElement;
 
37
import org.hisp.dhis.indicator.Indicator;
 
38
import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
 
39
import org.hisp.dhis.rt.dataaccess.ReportDataAccess;
 
40
import org.hisp.dhis.rt.dataaccess.ReportDataAccessException;
 
41
import org.hisp.dhis.rt.report.ReportStore;
 
42
import org.hisp.dhis.rt.report.ReportStoreException;
 
43
 
 
44
/**
 
45
 * @author Lars Helge Overland
 
46
 * @version $Id: ViewReportAction.java 2871 2007-02-20 16:04:11Z andegje $
 
47
 */
 
48
public class ViewReportAction
 
49
    extends AbstractAction
 
50
{    
 
51
    // -----------------------------------------------------------------------
 
52
    // Dependencies
 
53
    // -----------------------------------------------------------------------
 
54
 
 
55
    ReportDataAccess reportDataAccess;
 
56
    
 
57
    public void setReportDataAccess( ReportDataAccess reportDataAccess )
 
58
    {
 
59
        this.reportDataAccess = reportDataAccess;
 
60
    }
 
61
 
 
62
    // -------------------------------------------------------------------------
 
63
    // Comparator
 
64
    // -------------------------------------------------------------------------
 
65
 
 
66
    private Comparator<DataElement> dataElementComparator;
 
67
 
 
68
    public void setDataElementComparator( Comparator<DataElement> dataElementComparator )
 
69
    {
 
70
        this.dataElementComparator = dataElementComparator;
 
71
    }
 
72
    
 
73
    private Comparator<Indicator> indicatorComparator;    
 
74
 
 
75
    public void setIndicatorComparator( Comparator<Indicator> indicatorComparator )
 
76
    {
 
77
        this.indicatorComparator = indicatorComparator;
 
78
    }
 
79
    
 
80
    // -------------------------------------------------------------------------
 
81
    // DisplayPropertyHandler
 
82
    // -------------------------------------------------------------------------
 
83
 
 
84
    private DisplayPropertyHandler displayPropertyHandler;
 
85
 
 
86
    public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler )
 
87
    {
 
88
        this.displayPropertyHandler = displayPropertyHandler;
 
89
    }    
 
90
    
 
91
    // -----------------------------------------------------------------------
 
92
    // Parameters
 
93
    // -----------------------------------------------------------------------
 
94
 
 
95
    private String reportName;
 
96
    
 
97
    private List<DataElement> dataElements;
 
98
    
 
99
    private List<Indicator> indicators;
 
100
    
 
101
    private Collection dataElementGroups;
 
102
    
 
103
    private Collection indicatorGroups;
 
104
 
 
105
    private Collection currentReportElements;
 
106
    
 
107
    private Collection currentChartElements;
 
108
    
 
109
    private boolean showChartElements;
 
110
        
 
111
    public String getReportName()
 
112
    {
 
113
        return reportName;
 
114
    }
 
115
 
 
116
    public List<DataElement> getDataElements()
 
117
    {
 
118
        return dataElements;
 
119
    }
 
120
    
 
121
    public List<Indicator> getIndicators()
 
122
    {
 
123
        return indicators;
 
124
    }
 
125
 
 
126
    public Collection getDataElementGroups()
 
127
    {
 
128
        return dataElementGroups;
 
129
    }
 
130
 
 
131
    public Collection getIndicatorGroups()
 
132
    {
 
133
        return indicatorGroups;
 
134
    }
 
135
 
 
136
    public Collection getCurrentReportElements()
 
137
    {
 
138
        return currentReportElements;
 
139
    }
 
140
 
 
141
    public Collection getCurrentChartElements()
 
142
    {
 
143
        return currentChartElements;
 
144
    }
 
145
 
 
146
    public boolean isShowChartElements()
 
147
    {
 
148
        return showChartElements;
 
149
    }
 
150
 
 
151
    public void setShowChartElements( boolean showChartElements )
 
152
    {
 
153
        this.showChartElements = showChartElements;
 
154
    }
 
155
    
 
156
    // -----------------------------------------------------------------------
 
157
    // Execute
 
158
    // -----------------------------------------------------------------------
 
159
    
 
160
    public String execute()
 
161
        throws ReportDataAccessException, ReportStoreException
 
162
    {
 
163
        report = (String) getSessionVar( REPORT );
 
164
        
 
165
        int reportType = Integer.parseInt( getSessionVar( REPORT_TYPE ).toString() );
 
166
        
 
167
        reportName = report + " (" + getReportTypeName( reportType ) + ")";
 
168
        
 
169
        dataElementGroups = reportDataAccess.getAllDataElementGroups();
 
170
        
 
171
        indicatorGroups = reportDataAccess.getAllIndicatorGroups();
 
172
        
 
173
        if ( dataElementGroupId == ALL )
 
174
        {
 
175
            dataElements = new ArrayList<DataElement>( reportDataAccess.getAllDataElements() );
 
176
        }
 
177
        else
 
178
        {
 
179
            dataElements = new ArrayList<DataElement>( reportDataAccess.getMembersOfDataElementGroup( dataElementGroupId ) );
 
180
        }
 
181
        
 
182
        Collections.sort( dataElements, dataElementComparator );
 
183
        
 
184
        dataElements = displayPropertyHandler.handleDataElements( dataElements );
 
185
        
 
186
        if ( indicatorGroupId == ALL )
 
187
        {
 
188
            indicators = new ArrayList<Indicator>( reportDataAccess.getAllIndicators() );
 
189
        }
 
190
        else
 
191
        {
 
192
            indicators = new ArrayList<Indicator>( reportDataAccess.getMembersOfIndicatorGroup( indicatorGroupId ) );
 
193
        }
 
194
        
 
195
        Collections.sort( indicators, indicatorComparator );
 
196
        
 
197
        indicators = displayPropertyHandler.handleIndicators( indicators );
 
198
        
 
199
        if ( report != null )
 
200
        {
 
201
            designTemplate = reportStore.getDesignTemplate( report );
 
202
            
 
203
            chartTemplate = reportStore.getChartTemplate( report );
 
204
            
 
205
            currentReportElements = reportStore.getAllReportElements( report );
 
206
            
 
207
            currentChartElements = reportStore.getAllChartElements( report );
 
208
        }
 
209
        
 
210
        return SUCCESS;
 
211
    }
 
212
    
 
213
    private String getReportTypeName( int reportType )
 
214
    {
 
215
        String reportTypeName = new String();
 
216
        
 
217
        if ( reportType == ReportStore.GENERIC )
 
218
        {
 
219
            reportTypeName = i18n.getString( "generic" ); 
 
220
        }
 
221
        else if ( reportType == ReportStore.ORGUNIT_SPESIFIC )
 
222
        {
 
223
            reportTypeName = i18n.getString( "org_unit_spesific" );
 
224
        }
 
225
        
 
226
        return reportTypeName;
 
227
    }
 
228
    
 
229
    
 
230
}
 
231