dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10579
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2900: Changed ReportTable to be generated as an in-memory JRDataSource rather as a physical database ta...
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 2900 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-02-23 20:26:40 +0100
message:
Changed ReportTable to be generated as an in-memory JRDataSource rather as a physical database table. More info on report migration later.
modified:
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/statement/CreateReportTableStatement.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java
dhis-2/dhis-web/dhis-web-commons/src/main/resources/grid.vm
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java
dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml
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/addReportForm.vm
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js
--
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-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 2011-02-23 14:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2011-02-23 19:20:08 +0000
@@ -86,6 +86,8 @@
private static final String MODE_REPORT = "report";
private static final String MODE_REPORT_TABLE = "table";
+ private static final String YES = "Yes";
+ private static final String NO = "No";
// ---------------------------------------------------------------------
// Dependencies
@@ -515,7 +517,7 @@
grid.addValue( reportTable.getReportingMonthName() );
grid.addValue( reportTable.getOrganisationUnitName() );
- grid.addValue( isCurrentParent( row ) ? 1 : 0 );
+ grid.addValue( isCurrentParent( row ) ? YES : NO );
for ( List<IdentifiableObject> column : reportTable.getColumns() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java 2011-02-17 16:56:33 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java 2011-02-23 19:20:08 +0000
@@ -100,7 +100,7 @@
// Organisation unit is parent
// ---------------------------------------------------------------------
- buffer.append( ReportTable.ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME + SPACE + NUMERIC_COLUMN_TYPE + SEPARATOR );
+ buffer.append( ReportTable.ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME + SPACE + SHORT_TEXT_COLUMN_TYPE + SEPARATOR );
// ---------------------------------------------------------------------
// Crosstab
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java 2011-01-26 11:28:54 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java 2011-02-23 19:20:08 +0000
@@ -28,7 +28,6 @@
*/
import java.io.StringWriter;
-import java.sql.Connection;
import javax.servlet.http.HttpServletResponse;
@@ -38,7 +37,6 @@
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
-import org.amplecode.quick.StatementManager;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.velocity.VelocityContext;
@@ -65,17 +63,6 @@
private static final String DEFAULT_FILENAME = "Grid";
// -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private StatementManager statementManager;
-
- public void setStatementManager( StatementManager statementManager )
- {
- this.statementManager = statementManager;
- }
-
- // -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
@@ -138,22 +125,8 @@
JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report ) );
- Connection connection = statementManager.getHolder().getConnection();
-
- JasperPrint print = null;
-
- try
- {
- print = JasperFillManager.fillReport( jasperReport, null, connection );
- }
- finally
- {
- connection.close();
- }
-
- if ( print != null )
- {
- JasperExportManager.exportReportToPdfStream( print, response.getOutputStream() );
- }
+ JasperPrint print = JasperFillManager.fillReport( jasperReport, null, grid );
+
+ JasperExportManager.exportReportToPdfStream( print, response.getOutputStream() );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/grid.vm'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/grid.vm 2011-01-18 10:28:31 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/grid.vm 2011-02-23 19:23:07 +0000
@@ -1,17 +1,6 @@
#set( $dollar = '$' )
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="dpt" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
- <subDataset name="chart">
- <queryString language="SQL">
- <![CDATA[select * from ${grid.table} where organisation_unit_is_parent='1';]]>
- </queryString>
- #foreach( $header in $grid.getHeaders() )
- <field name="${header.column}" class="${header.type}"/>
- #end
- </subDataset>
- <queryString>
- <![CDATA[select * from ${grid.table} order by organisation_unit_is_parent;]]>
- </queryString>
#foreach( $header in $grid.getHeaders() )
<field name="${header.column}" class="${header.type}"/>
#end
@@ -56,11 +45,11 @@
<chartLegend/>
</chart>
<categoryDataset>
- <dataset>
- <datasetRun subDataset="chart"/>
+ <dataset>
+ <incrementWhenExpression><![CDATA[${dollar}F{organisation_unit_is_parent}.equals( "Yes" )]]></incrementWhenExpression>
</dataset>
#foreach( $header in $grid.getHeaders() )
- #if ( !$header.meta )
+ #if ( !$header.meta )
<categorySeries>
<seriesExpression><![CDATA["${header.name}"]]></seriesExpression>
<categoryExpression><![CDATA[""]]></categoryExpression>
@@ -71,9 +60,7 @@
</categoryDataset>
<bar3DPlot isShowLabels="true">
<plot/>
- <itemLabel color="#000000" backgroundColor="#FFFFFF">
- <font isBold="true"/>
- </itemLabel>
+ <itemLabel color="#000000" backgroundColor="#FFFFFF"/>
<categoryAxisFormat>
<axisFormat>
<labelFont/>
@@ -97,7 +84,7 @@
<band height="51" splitType="Stretch">
#set( $x = 10 )
#foreach( $header in $grid.getVisibleHeaders() )
- #if( $header.meta ) #set( $offset = 110 ) #else #set( $offset = 60 ) #end
+ #if( $header.meta ) #set( $offset = 110 ) #else #set( $offset = 60 ) #end
<staticText>
<reportElement x="${x}" y="26" width="${offset}" height="20"/>
<textElement #if( !$header.meta )textAlignment="Center"#end>
@@ -116,7 +103,7 @@
<band height="21" splitType="Stretch">
#set( $x = 10 )
#foreach( $header in $grid.getVisibleHeaders() )
- #if( $header.meta ) #set( $offset = 110 ) #else #set( $offset = 60 ) #end
+ #if( $header.meta ) #set( $offset = 110 ) #else #set( $offset = 60 ) #end
<textField>
<reportElement x="${x}" y="0" width="${offset}" height="20"/>
<textElement #if( !$header.meta )textAlignment="Center"#end>
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java 2011-01-26 07:55:56 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java 2011-02-23 19:20:08 +0000
@@ -39,8 +39,12 @@
import net.sf.jasperreports.engine.JasperReport;
import org.amplecode.quick.StatementManager;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.report.Report;
import org.hisp.dhis.report.ReportService;
+import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.reporttable.ReportTableService;
import org.hisp.dhis.system.util.StreamUtils;
import org.hisp.dhis.util.ContextUtils;
import org.hisp.dhis.util.StreamActionSupport;
@@ -63,12 +67,26 @@
this.reportService = reportService;
}
+ private ReportTableService reportTableService;
+
+ public void setReportTableService( ReportTableService reportTableService )
+ {
+ this.reportTableService = reportTableService;
+ }
+
private StatementManager statementManager;
public void setStatementManager( StatementManager statementManager )
{
this.statementManager = statementManager;
}
+
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
// -------------------------------------------------------------------------
// Input
@@ -81,6 +99,20 @@
this.id = id;
}
+ private Integer reportingPeriod;
+
+ public void setReportingPeriod( Integer reportingPeriod )
+ {
+ this.reportingPeriod = reportingPeriod;
+ }
+
+ private Integer organisationUnitId;
+
+ public void setOrganisationUnitId( Integer organisationUnitId )
+ {
+ this.organisationUnitId = organisationUnitId;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -93,24 +125,37 @@
JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report.getDesignContent() ) );
- Connection connection = statementManager.getHolder().getConnection();
-
JasperPrint print = null;
-
- try
+
+ if ( report.hasReportTable() ) // Use JR data source
{
- print = JasperFillManager.fillReport( jasperReport, null, connection );
+ ReportTable reportTable = report.getReportTable();
+
+ Grid grid = reportTableService.getReportTableGrid( reportTable.getId(), format, reportingPeriod, organisationUnitId );
+
+ System.out.println( grid );
+
+ print = JasperFillManager.fillReport( jasperReport, null, grid );
}
- finally
- {
- connection.close();
+ else // Assume SQL report and provide JDBC connection
+ {
+ Connection connection = statementManager.getHolder().getConnection();
+
+ try
+ {
+ print = JasperFillManager.fillReport( jasperReport, null, connection );
+ }
+ finally
+ {
+ connection.close();
+ }
}
if ( print != null )
{
JasperExportManager.exportReportToPdfStream( print, out );
}
-
+
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-02-22 23:05:45 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-02-23 19:20:08 +0000
@@ -318,6 +318,8 @@
scope="prototype">
<property name="reportService"
ref="org.hisp.dhis.report.ReportService"/>
+ <property name="reportTableService"
+ ref="org.hisp.dhis.reporttable.ReportTableService"/>
<property name="statementManager"
ref="statementManager"/>
</bean>
=== 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 2011-02-19 00:09:05 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2011-02-23 19:20:08 +0000
@@ -118,7 +118,7 @@
generate_workbook= Generate Workbook
importing_report_tables= Importing report tables
completeness_configuration_explanation= Number of days refers to the maximum number of days after the end of the reporting month before the data must be submitted
-omit_report_table_explanation= If selecting no report table, the user is responsible for providing the data source table
+omit_report_table_explanation= If selecting no report table, the user is responsible for providing the data source
reporting_deadline= Reporting deadline
nr_of_days= Number of days
select_report_table_none= Select report table / none
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm 2011-02-22 23:05:45 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm 2011-02-23 19:20:08 +0000
@@ -23,13 +23,8 @@
<td><input type="button" value="$i18n.getString( 'get_current_design' )" onclick="window.location.href='getReportDesign.action?id=${report.id}'"></td>
</tr>
<tr>
- <td colspan="2" height="7px"></td>
- </tr>
- <tr>
- <th colspan="2">$i18n.getString( "report_table" )</th>
- </tr>
- <tr>
- <td colspan="2">
+ <td><label for="reportTableId">$i18n.getString( "report_table" )</td>
+ <td>
<select id="reportTableId" name="reportTableId" style="min-width:325px">
<option value="0">[ $i18n.getString( "none" ) ]</option>
#foreach( $table in $reportTables )
@@ -39,7 +34,8 @@
</td>
</tr>
<tr>
- <td colspan="2"><input type="button" value="$i18n.getString( 'save' )" style="width:10em" onclick="addReport()"><input
+ <td></td>
+ <td><input type="button" value="$i18n.getString( 'save' )" style="width:10em" onclick="addReport()"><input
type="button" value="$i18n.getString( 'cancel' )" style="width:10em"
onclick="window.location.href='displayViewReportForm.action'"></td>
</tr>
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js 2011-02-22 23:05:45 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js 2011-02-23 19:20:08 +0000
@@ -83,25 +83,25 @@
{
setMessage( i18n_process_completed );
+ var urlParams = "id=" + $( "#id" ).val();
+
+ if ( $( "#reportingPeriod" ).length )
+ {
+ urlParams += "&reportingPeriod=" + $( "#reportingPeriod" ).val();
+ }
+
+ if ( paramOrganisationUnit != null )
+ {
+ urlParams += "&organisationUnitId=" + paramOrganisationUnit;
+ }
+
if ( $( "#mode" ).val() == MODE_REPORT )
{
- window.location.href = "renderReport.action?id=" + $( "#id" ).val();
+ window.location.href = "renderReport.action?" + urlParams;
}
- else if ( $( "#mode" ).val() == MODE_TABLE )
+ else if ($( "#mode" ).val() == MODE_TABLE )
{
- var url = "exportTable.action?id=" + $( "#id" ).val() + "&type=html";
-
- if ( $( "#reportingPeriod" ).length )
- {
- url += "&reportingPeriod=" + $( "#reportingPeriod" ).val();
- }
-
- if ( paramOrganisationUnit != null )
- {
- url += "&organisationUnitId=" + paramOrganisationUnit;
- }
-
- window.location.href = url;
+ window.location.href = "exportTable.action?type=html&" + urlParams;
}
}
else if ( statusMessage == null )