dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15228
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5420: Web api: added report content resource for pdf and xls representations
------------------------------------------------------------
revno: 5420
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-12-14 17:53:56 +0100
message:
Web api: added report content resource for pdf and xls representations
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.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/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-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java
--
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/datavalue/DataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java 2011-11-23 18:07:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java 2011-12-14 16:53:56 +0000
@@ -79,7 +79,7 @@
private String comment;
- private boolean followup;
+ private Boolean followup;
// -------------------------------------------------------------------------
// Constructors
@@ -174,7 +174,12 @@
{
return value == null && comment == null;
}
-
+
+ public boolean isFollowup()
+ {
+ return followup != null && followup;
+ }
+
// -------------------------------------------------------------------------
// hashCode and equals
// -------------------------------------------------------------------------
@@ -301,12 +306,12 @@
this.comment = comment;
}
- public boolean isFollowup()
+ public Boolean getFollowup()
{
return followup;
}
- public void setFollowup( boolean followup )
+ public void setFollowup( Boolean followup )
{
this.followup = followup;
}
=== 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 2011-12-14 10:03:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java 2011-12-14 16:53:56 +0000
@@ -47,6 +47,9 @@
public void renderReport( OutputStream out, Report report, Date reportingPeriod,
Integer organisationUnitId, String type, I18nFormat format );
+ void renderReport( OutputStream out, String reportUid, Date reportingPeriod,
+ String organisationUnitUid, String type, I18nFormat format );
+
/**
* Saves a Report.
*
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2011-12-14 11:15:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2011-12-14 16:53:56 +0000
@@ -330,6 +330,46 @@
executeSql( "ALTER TABLE validationrule DROP COLUMN uuid" );
executeSql( "ALTER TABLE validationrulegroup DROP COLUMN uuid" );
+ // replace null with false for boolean fields
+
+ executeSql( "update chart set hidelegend = false where hidelegend is null" );
+ executeSql( "update chart set verticallabels = false where verticallabels is null" );
+ executeSql( "update chart set horizontalplotorientation = false where horizontalplotorientation is null" );
+ executeSql( "update chart set regression = false where regression is null" );
+ executeSql( "update chart set targetline = false where targetline is null" );
+ executeSql( "update chart set hidesubtitle = false where hidesubtitle is null" );
+ executeSql( "update chart set userorganisationunit = false where userorganisationunit is null" );
+ executeSql( "update indicator set annualized = false where annualized is null" );
+ executeSql( "update indicatortype set indicatornumber = false where indicatornumber is null" );
+ executeSql( "update dataset set mobile = false where mobile is null" );
+ executeSql( "update dataelement set zeroissignificant = false where zeroissignificant is null" );
+ executeSql( "update organisationunit set haspatients = false where haspatients is null" );
+
+ executeSql( "update reporttable set monthsthisyear = false where monthsthisyear is null" );
+ executeSql( "update reporttable set quartersthisyear = false where quartersthisyear is null" );
+ executeSql( "update reporttable set thisyear = false where thisyear is null" );
+ executeSql( "update reporttable set monthslastyear = false where monthslastyear is null" );
+ executeSql( "update reporttable set quartersthisyear = false where quartersthisyear is null" );
+ executeSql( "update reporttable set thisyear = false where thisyear is null" );
+ executeSql( "update reporttable set monthslastyear = false where monthslastyear is null" );
+ executeSql( "update reporttable set quarterslastyear = false where quarterslastyear is null" );
+ executeSql( "update reporttable set monthsthisyear = false where monthsthisyear is null" );
+ executeSql( "update reporttable set lastyear = false where lastyear is null" );
+ executeSql( "update reporttable set last5years = false where last5years is null" );
+ executeSql( "update reporttable set last4quarters = false where last4quarters is null" );
+ executeSql( "update reporttable set last12months = false where last12months is null" );
+
+ executeSql( "update chart set monthsthisyear = false where monthsthisyear is null" );
+ executeSql( "update chart set quartersthisyear = false where quartersthisyear is null" );
+ executeSql( "update chart set thisyear = false where thisyear is null" );
+ executeSql( "update chart set monthslastyear = false where monthslastyear is null" );
+ executeSql( "update chart set quartersthisyear = false where quartersthisyear is null" );
+ executeSql( "update chart set thisyear = false where thisyear is null" );
+ executeSql( "update chart set monthslastyear = false where monthslastyear is null" );
+ executeSql( "update chart set quarterslastyear = false where quarterslastyear is null" );
+ executeSql( "update chart set monthsthisyear = false where monthsthisyear is null" );
+ executeSql( "update chart set lastyear = false where lastyear is null" );
+
log.info( "Tables updated" );
}
=== 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 2011-12-14 10:03:38 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2011-12-14 16:53:56 +0000
@@ -36,7 +36,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.report.Report;
import org.hisp.dhis.report.ReportGroup;
import org.hisp.dhis.report.ReportService;
@@ -98,6 +100,13 @@
{
this.statementManager = statementManager;
}
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
private OrganisationUnitGroupService organisationUnitGroupService;
@@ -110,8 +119,17 @@
// ReportService implementation
// -------------------------------------------------------------------------
+ public void renderReport( OutputStream out, String reportUid, Date reportingPeriod,
+ String organisationUnitUid, String type, I18nFormat format )
+ {
+ Report report = getReport( reportUid );
+ OrganisationUnit unit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
+
+ renderReport( out, report, reportingPeriod, unit.getId(), type, format );
+ }
+
public void renderReport( OutputStream out, Report report, Date reportingPeriod,
- Integer organisationUnitId, String type, I18nFormat format )
+ Integer organisationUnitId, String type, I18nFormat format )
{
Map<String, Object> params = new HashMap<String, Object>();
=== 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 2011-12-09 20:14:06 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-12-14 16:53:56 +0000
@@ -60,6 +60,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" />
</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 2011-12-13 14:04:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java 2011-12-14 16:53:56 +0000
@@ -28,20 +28,28 @@
*/
import java.util.ArrayList;
+import java.util.Date;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.hisp.dhis.api.utils.IdentifiableObjectParams;
import org.hisp.dhis.api.utils.WebLinkPopulator;
+import org.hisp.dhis.i18n.I18nManager;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.report.Report;
import org.hisp.dhis.report.ReportService;
import org.hisp.dhis.report.Reports;
+import org.hisp.dhis.system.util.CodecUtils;
+import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.util.ContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping( value = ReportController.RESOURCE_PATH )
@@ -52,9 +60,15 @@
@Autowired
public ReportService reportService;
- //-------------------------------------------------------------------------------------------------------
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private I18nManager i18nManager;
+
+ // -------------------------------------------------------------------------------------------------------
// GET
- //-------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------
@RequestMapping( method = RequestMethod.GET )
public String getReports( IdentifiableObjectParams params, Model model, HttpServletRequest request )
@@ -82,7 +96,8 @@
}
@RequestMapping( value = "/{uid}", method = RequestMethod.GET )
- public String getReport( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request )
+ public String getReport( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model,
+ HttpServletRequest request )
{
Report report = reportService.getReport( uid );
@@ -96,4 +111,46 @@
return "report";
}
+
+ @RequestMapping( value = {"/{uid}/data","/{uid}/data.pdf"}, method = RequestMethod.GET )
+ public void getReportAsPdf( @PathVariable( "uid" ) String uid,
+ @RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
+ @RequestParam( value = "period", required = false ) String period, HttpServletResponse response )
+ throws Exception
+ {
+ getReport( uid, organisationUnitUid, period, response, "pdf", ContextUtils.CONTENT_TYPE_PDF, false );
+ }
+
+ @RequestMapping( value = "/{uid}/data.xls", method = RequestMethod.GET )
+ public void getReportAsXls( @PathVariable( "uid" ) String uid,
+ @RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
+ @RequestParam( value = "period", required = false ) String period, HttpServletResponse response )
+ throws Exception
+ {
+ getReport( uid, organisationUnitUid, period, response, "xls", ContextUtils.CONTENT_TYPE_EXCEL, true );
+ }
+
+ // -------------------------------------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------------------------------------
+
+ private void getReport( String uid, String organisationUnitUid, String period,
+ HttpServletResponse response, String type, String contentType, boolean attachment ) throws Exception
+ {
+ Report report = reportService.getReport( uid );
+
+ if ( report.hasReportTable() && report.getReportTable().hasReportParams()
+ && report.getReportTable().getReportParams().isOrganisationUnitSet() )
+ {
+ organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
+ }
+
+ Date date = period != null ? DateUtils.getMediumDate( period ) : new Date();
+
+ reportService.renderReport( response.getOutputStream(), uid, date, organisationUnitUid, type,
+ i18nManager.getI18nFormat() );
+
+ String filename = CodecUtils.filenameEncode( report.getName() ) + "." + type;
+ ContextUtils.configureResponse( response, contentType, true, filename, attachment );
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2011-12-14 13:18:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2011-12-14 16:53:56 +0000
@@ -29,7 +29,6 @@
import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
-import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
@@ -41,7 +40,6 @@
import org.hisp.dhis.api.utils.WebLinkPopulator;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.i18n.I18nManager;
-import org.hisp.dhis.i18n.I18nManagerException;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.reporttable.ReportTable;
import org.hisp.dhis.reporttable.ReportTableService;
@@ -124,7 +122,7 @@
public String getReportTableData( @PathVariable( "uid" ) String uid, Model model,
@RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
@RequestParam( value = "period", required = false ) String period,
- HttpServletResponse response ) throws I18nManagerException, IOException
+ HttpServletResponse response ) throws Exception
{
ReportTable reportTable = reportTableService.getReportTable( uid );
@@ -146,7 +144,7 @@
public void getReportTablePdf( @PathVariable( "uid" ) String uid,
@RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
@RequestParam( value = "period", required = false ) String period,
- HttpServletResponse response ) throws I18nManagerException, IOException
+ HttpServletResponse response ) throws Exception
{
ReportTable reportTable = reportTableService.getReportTable( uid );