dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19134
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8229: Using iso period format instead of custom period format for report generation
------------------------------------------------------------
revno: 8229
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-09-24 14:52:15 +0200
message:
Using iso period format instead of custom period format for report generation
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java
dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java 2012-09-24 05:42:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java 2012-09-24 12:52:15 +0000
@@ -117,6 +117,14 @@
return relatives != null && !relatives.getRelativePeriods().isEmpty();
}
+ /**
+ * Indicates whether this report has report parameters set.
+ */
+ public boolean hasReportParams()
+ {
+ return reportParams != null && reportParams.isSet();
+ }
+
// -------------------------------------------------------------------------
// Equals and hashCode
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java 2012-09-24 06:03:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java 2012-09-24 12:52:15 +0000
@@ -27,11 +27,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.i18n.I18nFormat;
-
import java.io.OutputStream;
import java.util.Collection;
-import java.util.Date;
+
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.period.Period;
/**
* @author Lars Helge Overland
@@ -44,9 +44,26 @@
final String REPORTTYPE_XLS = "xls";
final String PARAM_RELATIVE_PERIODS = "periods";
- final String PARAM_ORG_UNITS = "orgunits";
+ final String PARAM_ORG_UNITS = "organisationunits";
- void renderReport( OutputStream out, String reportUid, Date reportingPeriod,
+ /**
+ * Renders a Jasper Report.
+ *
+ * Will make the following params available:
+ *
+ * "periods" String of relative period ids)
+ * "organisationunits" String of selected organisation unit uids)
+ * "reporting_month_name" Name of the selected period
+ * "param_organisationunit_name" Name of the selected organisation unit
+ *
+ * @param out the OutputStream to write the report to.
+ * @param reportUid the uid of the report to render.
+ * @param period the period to use as parameter.
+ * @param organisationUnitUid the uid of the org unit to use as parameter.
+ * @param type the type of the report, can be "xls" and "pdf".
+ * @param format the I18nFormat to use.
+ */
+ void renderReport( OutputStream out, String reportUid, Period period,
String organisationUnitUid, String type, I18nFormat format );
/**
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2012-09-23 15:49:44 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2012-09-24 12:52:15 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.reporttable.ReportTable.PARAM_ORGANISATIONUNIT_COLUMN_NAME;
+import static org.hisp.dhis.reporttable.ReportTable.REPORTING_MONTH_COLUMN_NAME;
import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
@@ -47,7 +49,9 @@
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.constant.ConstantService;
import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.report.Report;
@@ -100,6 +104,13 @@
this.statementManager = statementManager;
}
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
private OrganisationUnitGroupService organisationUnitGroupService;
public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
@@ -118,7 +129,7 @@
// ReportService implementation
// -------------------------------------------------------------------------
- public void renderReport( OutputStream out, String reportUid, Date reportingPeriod,
+ public void renderReport( OutputStream out, String reportUid, Period period,
String organisationUnitUid, String type, I18nFormat format )
{
Report report = getReport( reportUid );
@@ -127,6 +138,22 @@
params.putAll( constantService.getConstantParameterMap() );
+ Date reportDate = new Date();
+
+ if ( period != null )
+ {
+ params.put( REPORTING_MONTH_COLUMN_NAME, format.formatPeriod( period ) );
+
+ reportDate = period.getStartDate();
+ }
+
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
+
+ if ( orgUnit != null )
+ {
+ params.put( PARAM_ORGANISATIONUNIT_COLUMN_NAME, orgUnit.getName() );
+ }
+
try
{
JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report.getDesignContent() ) );
@@ -137,7 +164,7 @@
{
ReportTable reportTable = report.getReportTable();
- Grid grid = reportTableService.getReportTableGrid( reportTable.getUid(), format, reportingPeriod, organisationUnitUid );
+ Grid grid = reportTableService.getReportTableGrid( reportTable.getUid(), format, reportDate, organisationUnitUid );
if ( report.isUsingOrganisationUnitGroupSets() )
{
@@ -157,6 +184,11 @@
params.put( PARAM_RELATIVE_PERIODS, periodString );
}
+ if ( report.hasReportParams() && report.getReportParams().isParamOrganisationUnit() && orgUnit != null )
+ {
+ params.put( PARAM_ORG_UNITS, orgUnit.getUid() );
+ }
+
try
{
print = JasperFillManager.fillReport( jasperReport, params, connection );
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2012-09-24 06:10:48 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2012-09-24 12:52:15 +0000
@@ -165,6 +165,7 @@
{
return reportService.getReport( uid ).getReportTable();
}
+
return null;
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2012-09-23 14:24:14 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2012-09-24 12:52:15 +0000
@@ -38,6 +38,7 @@
<property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService" />
<property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
<property name="statementManager" ref="statementManager" />
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
<property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
</bean>
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java 2012-05-31 17:02:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java 2012-09-24 12:52:15 +0000
@@ -27,14 +27,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import javax.servlet.http.HttpServletResponse;
+
import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.report.Report;
import org.hisp.dhis.report.ReportService;
import org.hisp.dhis.system.util.CodecUtils;
-import org.hisp.dhis.system.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
@@ -42,12 +46,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Calendar;
-import java.util.Date;
-
-import static org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
* @author Lars Helge Overland
@@ -93,7 +91,7 @@
// Supportive methods
// -------------------------------------------------------------------------
- private void getReport( String uid, String organisationUnitUid, String period,
+ private void getReport( String uid, String organisationUnitUid, String isoPeriod,
HttpServletResponse response, String type, String contentType, boolean attachment ) throws Exception
{
Report report = reportService.getReport( uid );
@@ -104,12 +102,12 @@
organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
}
- Date date = period != null ? DateUtils.getMediumDate( period ) : new Cal().now().subtract( Calendar.MONTH, 1 ).time();
-
+ Period period = isoPeriod != null ? PeriodType.getPeriodFromIsoString( isoPeriod ) : new MonthlyPeriodType().createPeriod();
+
String filename = CodecUtils.filenameEncode( report.getName() ) + "." + type;
contextUtils.configureResponse( response, contentType, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, attachment );
- reportService.renderReport( response.getOutputStream(), uid, date, organisationUnitUid, type,
+ reportService.renderReport( response.getOutputStream(), uid, period, organisationUnitUid, type,
i18nManager.getI18nFormat() );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java 2012-07-02 19:27:19 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java 2012-09-24 12:52:15 +0000
@@ -35,9 +35,10 @@
import org.hisp.dhis.constant.ConstantService;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.reporttable.ReportTable;
import org.hisp.dhis.reporttable.ReportTableService;
-import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.util.SessionUtils;
import com.opensymphony.xwork2.Action;
@@ -174,7 +175,9 @@
}
else
{
- Date date = pe != null ? DateUtils.getMediumDate( pe ) : new Date();
+ Period period = PeriodType.getPeriodFromIsoString( pe );
+
+ Date date = period != null ? period.getStartDate() : new Date();
grid = reportTableService.getReportTableGrid( uid, format, date, ou );
}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2012-09-12 15:41:22 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2012-09-24 12:52:15 +0000
@@ -8,7 +8,7 @@
select_period=Please select a period
select_organisation_unit=Please select an organisation unit
report_organisation_unit= Report organisation unit
-dataset_report= Data set Report
+dataset_report= Data Set Report
add_selected= Add selected
add_all= Add all
add=Add
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm 2012-04-26 15:26:28 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/inputReportParamsForm.vm 2012-09-24 12:52:15 +0000
@@ -31,7 +31,7 @@
<td>
<select id="reportingPeriod" name="reportingPeriod" style="width:325px">
#foreach ( $period in $periods )
- <option value="${period.startDateString}">${period.name}</option>
+ <option value="${period.isoDate}">${period.name}</option>
#end
</select>
</td>