1
package org.hisp.dhis.rt.action;
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.ArrayList;
31
import java.util.Collection;
32
import java.util.Collections;
33
import java.util.Comparator;
34
import java.util.List;
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;
45
* @author Lars Helge Overland
46
* @version $Id: ViewReportAction.java 2871 2007-02-20 16:04:11Z andegje $
48
public class ViewReportAction
49
extends AbstractAction
51
// -----------------------------------------------------------------------
53
// -----------------------------------------------------------------------
55
ReportDataAccess reportDataAccess;
57
public void setReportDataAccess( ReportDataAccess reportDataAccess )
59
this.reportDataAccess = reportDataAccess;
62
// -------------------------------------------------------------------------
64
// -------------------------------------------------------------------------
66
private Comparator<DataElement> dataElementComparator;
68
public void setDataElementComparator( Comparator<DataElement> dataElementComparator )
70
this.dataElementComparator = dataElementComparator;
73
private Comparator<Indicator> indicatorComparator;
75
public void setIndicatorComparator( Comparator<Indicator> indicatorComparator )
77
this.indicatorComparator = indicatorComparator;
80
// -------------------------------------------------------------------------
81
// DisplayPropertyHandler
82
// -------------------------------------------------------------------------
84
private DisplayPropertyHandler displayPropertyHandler;
86
public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler )
88
this.displayPropertyHandler = displayPropertyHandler;
91
// -----------------------------------------------------------------------
93
// -----------------------------------------------------------------------
95
private String reportName;
97
private List<DataElement> dataElements;
99
private List<Indicator> indicators;
101
private Collection dataElementGroups;
103
private Collection indicatorGroups;
105
private Collection currentReportElements;
107
private Collection currentChartElements;
109
private boolean showChartElements;
111
public String getReportName()
116
public List<DataElement> getDataElements()
121
public List<Indicator> getIndicators()
126
public Collection getDataElementGroups()
128
return dataElementGroups;
131
public Collection getIndicatorGroups()
133
return indicatorGroups;
136
public Collection getCurrentReportElements()
138
return currentReportElements;
141
public Collection getCurrentChartElements()
143
return currentChartElements;
146
public boolean isShowChartElements()
148
return showChartElements;
151
public void setShowChartElements( boolean showChartElements )
153
this.showChartElements = showChartElements;
156
// -----------------------------------------------------------------------
158
// -----------------------------------------------------------------------
160
public String execute()
161
throws ReportDataAccessException, ReportStoreException
163
report = (String) getSessionVar( REPORT );
165
int reportType = Integer.parseInt( getSessionVar( REPORT_TYPE ).toString() );
167
reportName = report + " (" + getReportTypeName( reportType ) + ")";
169
dataElementGroups = reportDataAccess.getAllDataElementGroups();
171
indicatorGroups = reportDataAccess.getAllIndicatorGroups();
173
if ( dataElementGroupId == ALL )
175
dataElements = new ArrayList<DataElement>( reportDataAccess.getAllDataElements() );
179
dataElements = new ArrayList<DataElement>( reportDataAccess.getMembersOfDataElementGroup( dataElementGroupId ) );
182
Collections.sort( dataElements, dataElementComparator );
184
dataElements = displayPropertyHandler.handleDataElements( dataElements );
186
if ( indicatorGroupId == ALL )
188
indicators = new ArrayList<Indicator>( reportDataAccess.getAllIndicators() );
192
indicators = new ArrayList<Indicator>( reportDataAccess.getMembersOfIndicatorGroup( indicatorGroupId ) );
195
Collections.sort( indicators, indicatorComparator );
197
indicators = displayPropertyHandler.handleIndicators( indicators );
199
if ( report != null )
201
designTemplate = reportStore.getDesignTemplate( report );
203
chartTemplate = reportStore.getChartTemplate( report );
205
currentReportElements = reportStore.getAllReportElements( report );
207
currentChartElements = reportStore.getAllChartElements( report );
213
private String getReportTypeName( int reportType )
215
String reportTypeName = new String();
217
if ( reportType == ReportStore.GENERIC )
219
reportTypeName = i18n.getString( "generic" );
221
else if ( reportType == ReportStore.ORGUNIT_SPESIFIC )
223
reportTypeName = i18n.getString( "org_unit_spesific" );
226
return reportTypeName;