← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2571: Impl Jrxml struts result

 

------------------------------------------------------------
revno: 2571
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-01-14 19:10:02 +0100
message:
  Impl Jrxml struts result
added:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/grid.vm
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.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/resources/struts.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/reportTableGrid.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-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java	2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java	2011-01-14 18:10:02 +0000
@@ -210,7 +210,7 @@
         {
             ResultSet resultSet = holder.getStatement().executeQuery( "SELECT * FROM " + reportTable.getExistingTableName() );
             
-            Grid grid = new ListGrid().setTitle( reportTable.getName() );
+            Grid grid = new ListGrid().setTitle( reportTable.getName() ).setTable( reportTable.getExistingTableName() );
 
             // -----------------------------------------------------------------
             // Columns

=== added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java	2011-01-14 18:10:02 +0000
@@ -0,0 +1,113 @@
+package org.hisp.dhis.result;
+
+import java.io.Writer;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.struts2.ServletActionContext;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.system.util.CodecUtils;
+import org.hisp.dhis.util.ContextUtils;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.Result;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GridJrxmlResult
+    implements Result
+{
+    private static final String KEY_GRID = "grid";
+    private static final String TEMPLATE = "grid.vm";
+    private static final String RESOURCE_LOADER_NAME = "class";
+    private static final String DEFAULT_FILENAME = "Grid";
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Grid grid;
+    
+    public void setGrid( Grid grid )
+    {
+        this.grid = grid;
+    }
+
+    // -------------------------------------------------------------------------
+    // Result implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void execute( ActionInvocation invocation )
+        throws Exception
+    {
+        // ---------------------------------------------------------------------
+        // Get grid
+        // ---------------------------------------------------------------------
+
+        Grid _grid = (Grid) invocation.getStack().findValue( "grid" );
+        
+        grid = _grid != null ? _grid : grid; 
+
+        // ---------------------------------------------------------------------
+        // Configure response
+        // ---------------------------------------------------------------------
+
+        HttpServletResponse response = ServletActionContext.getResponse();
+        
+        Writer writer = response.getWriter();
+
+        String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".jrxml";
+        
+        ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, true, filename, false );
+        
+        // ---------------------------------------------------------------------
+        // Write jrxml based on Velocity template
+        // ---------------------------------------------------------------------
+
+        VelocityEngine velocity = new VelocityEngine();
+        
+        velocity.setProperty( Velocity.RESOURCE_LOADER, RESOURCE_LOADER_NAME );
+        velocity.setProperty( RESOURCE_LOADER_NAME + ".resource.loader.class", ClasspathResourceLoader.class.getName() );
+        velocity.init();
+        
+        VelocityContext context = new VelocityContext();
+        
+        context.put( KEY_GRID, grid );
+        
+        velocity.getTemplate( TEMPLATE ).merge( context, writer );
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java	2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java	2011-01-14 18:10:02 +0000
@@ -52,7 +52,7 @@
 public class GridPdfResult
     implements Result
 {
-    private static final String DEFAULT_FILENAME = "Grid.pdf";
+    private static final String DEFAULT_FILENAME = "Grid";
 
     // -------------------------------------------------------------------------
     // Input

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-01-14 17:42:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-01-14 18:10:02 +0000
@@ -39,6 +39,8 @@
 				class="org.hisp.dhis.result.GridPdfResult" />
 			<result-type name="gridJasperResult"
 				class="org.hisp.dhis.result.GridJasperResult" />
+			<result-type name="gridJrxmlResult"
+				class="org.hisp.dhis.result.GridJrxmlResult" />
 		</result-types>
 
 		<interceptors>

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/grid.vm	2011-01-14 18:10:02 +0000
@@ -0,0 +1,190 @@
+#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
+	<background>
+		<band splitType="Stretch"/>
+	</background>
+	<title>
+		<band height="326" splitType="Stretch">
+			<staticText>
+				<reportElement x="12" y="15" width="532" height="41" forecolor="#184F73"/>
+				<textElement textAlignment="Center">
+					<font size="24"/>
+				</textElement>
+				<text><![CDATA[${grid.title}]]></text>
+			</staticText>
+			<bar3DChart>
+				<chart evaluationTime="Report">
+					<reportElement x="12" y="114" width="532" height="210"/>
+					<chartTitle/>
+					<chartSubtitle/>
+					<chartLegend/>
+				</chart>
+				<categoryDataset>
+					<dataset>
+						<datasetRun subDataset="chart"/>
+					</dataset>
+					<categorySeries>
+						<seriesExpression><![CDATA["DPT 1"]]></seriesExpression>
+						<categoryExpression><![CDATA[""]]></categoryExpression>
+						<valueExpression><![CDATA[${dollar}F{dpt1_doses_given}]]></valueExpression>
+					</categorySeries>
+					<categorySeries>
+						<seriesExpression><![CDATA["DPT 2"]]></seriesExpression>
+						<categoryExpression><![CDATA[""]]></categoryExpression>
+						<valueExpression><![CDATA[${dollar}F{dpt2_doses_given}]]></valueExpression>
+					</categorySeries>
+					<categorySeries>
+						<seriesExpression><![CDATA["DPT 3"]]></seriesExpression>
+						<categoryExpression><![CDATA[""]]></categoryExpression>
+						<valueExpression><![CDATA[${dollar}F{dpt3_doses_given}]]></valueExpression>
+					</categorySeries>
+					<categorySeries>
+						<seriesExpression><![CDATA["Measles"]]></seriesExpression>
+						<categoryExpression><![CDATA[""]]></categoryExpression>
+						<valueExpression><![CDATA[${dollar}F{measles_doses_given}]]></valueExpression>
+					</categorySeries>
+					<categorySeries>
+						<seriesExpression><![CDATA["Fully Imm"]]></seriesExpression>
+						<categoryExpression><![CDATA[""]]></categoryExpression>
+						<valueExpression><![CDATA[${dollar}F{fully_immunised}]]></valueExpression>
+					</categorySeries>
+				</categoryDataset>
+				<bar3DPlot>
+					<plot/>
+					<itemLabel color="#000000" backgroundColor="#FFFFFF"/>
+					<categoryAxisFormat>
+						<axisFormat>
+							<labelFont/>
+							<tickLabelFont/>
+						</axisFormat>
+					</categoryAxisFormat>
+					<valueAxisFormat>
+						<axisFormat>
+							<labelFont/>
+							<tickLabelFont/>
+						</axisFormat>
+					</valueAxisFormat>
+				</bar3DPlot>
+			</bar3DChart>
+		</band>
+	</title>
+	<pageHeader>
+		<band height="15" splitType="Stretch"/>
+	</pageHeader>
+	<columnHeader>
+		<band height="51" splitType="Stretch">
+			<staticText>
+				<reportElement x="170" y="26" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="10" isBold="true"/>
+				</textElement>
+				<text><![CDATA[DPT 1 given]]></text>
+			</staticText>
+			<staticText>
+				<reportElement x="234" y="26" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="10" isBold="true"/>
+				</textElement>
+				<text><![CDATA[DPT 2 given]]></text>
+			</staticText>
+			<staticText>
+				<reportElement x="298" y="26" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="10" isBold="true"/>
+				</textElement>
+				<text><![CDATA[DPT 3 given]]></text>
+			</staticText>
+			<staticText>
+				<reportElement x="362" y="26" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="10" isBold="true"/>
+				</textElement>
+				<text><![CDATA[Measles given]]></text>
+			</staticText>
+			<staticText>
+				<reportElement x="426" y="26" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="10" isBold="true"/>
+				</textElement>
+				<text><![CDATA[Fully imm]]></text>
+			</staticText>
+			<staticText>
+				<reportElement x="12" y="26" width="148" height="20"/>
+				<textElement>
+					<font size="10" isBold="true"/>
+				</textElement>
+				<text><![CDATA[Organisation unit]]></text>
+			</staticText>
+		</band>
+	</columnHeader>
+	<detail>
+		<band height="21" splitType="Stretch">
+			<textField>
+				<reportElement x="170" y="0" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="9"/>
+				</textElement>
+				<textFieldExpression class="java.lang.Double"><![CDATA[${dollar}F{dpt1_doses_given}]]></textFieldExpression>
+			</textField>
+			<textField>
+				<reportElement x="234" y="0" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="9"/>
+				</textElement>
+				<textFieldExpression class="java.lang.Double"><![CDATA[${dollar}F{dpt2_doses_given}]]></textFieldExpression>
+			</textField>
+			<textField>
+				<reportElement x="298" y="0" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="9"/>
+				</textElement>
+				<textFieldExpression class="java.lang.Double"><![CDATA[${dollar}F{dpt3_doses_given}]]></textFieldExpression>
+			</textField>
+			<textField>
+				<reportElement x="362" y="0" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="9"/>
+				</textElement>
+				<textFieldExpression class="java.lang.Double"><![CDATA[${dollar}F{measles_doses_given}]]></textFieldExpression>
+			</textField>
+			<textField>
+				<reportElement x="426" y="0" width="64" height="20"/>
+				<textElement textAlignment="Center">
+					<font size="9"/>
+				</textElement>
+				<textFieldExpression class="java.lang.Double"><![CDATA[${dollar}F{fully_immunised}]]></textFieldExpression>
+			</textField>
+			<textField>
+				<reportElement x="12" y="0" width="148" height="20"/>
+				<textElement>
+					<font size="9" isBold="false"/>
+				</textElement>
+				<textFieldExpression class="java.lang.String"><![CDATA[${dollar}F{organisationunitname}]]></textFieldExpression>
+			</textField>
+		</band>
+	</detail>
+	<columnFooter>
+		<band height="22" splitType="Stretch"/>
+	</columnFooter>
+	<pageFooter>
+		<band height="20" splitType="Stretch"/>
+	</pageFooter>
+	<summary>
+		<band height="42" splitType="Stretch"/>
+	</summary>
+</jasperReport>

=== 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-01-13 15:44:09 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-01-14 18:10:02 +0000
@@ -306,4 +306,6 @@
 get_report_as_xls = Download as Excel
 get_report_as_csv = Download as CSV
 get_report_as_pdf = Download as PDF
+get_report_as_jasper = Download as Jasper
+get_report_as_jrxml = Download as JRXML
 user_organisation_unit = Include current user organisation unit
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2011-01-06 22:22:18 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2011-01-14 18:10:02 +0000
@@ -251,6 +251,8 @@
       <result name="csv" type="gridCsvResult"/>
       <result name="xls" type="gridXlsResult"/>
       <result name="pdf" type="gridPdfResult"/>
+      <result name="jasper" type="gridJasperResult"/>
+      <result name="jrxml" type="gridJrxmlResult"/>
       <result name="html" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-reporting/reportTableGrid.vm</param>
       <param name="menu">/dhis-web-reporting/menu.vm</param>   

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/reportTableGrid.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/reportTableGrid.vm	2011-01-06 12:40:57 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/reportTableGrid.vm	2011-01-14 18:10:02 +0000
@@ -3,6 +3,8 @@
 <input type="button" value="$i18n.getString( 'get_report_as_xls' )" onclick="exportReport( 'xls' )" style="width:140px">
 <input type="button" value="$i18n.getString( 'get_report_as_csv' )" onclick="exportReport( 'csv' )" style="width:140px">
 <input type="button" value="$i18n.getString( 'get_report_as_pdf' )" onclick="exportReport( 'pdf' )" style="width:140px">
+<input type="button" value="$i18n.getString( 'get_report_as_jasper' )" onclick="exportReport( 'jasper' )" style="width:140px">
+<input type="button" value="$i18n.getString( 'get_report_as_jrxml' )" onclick="exportReport( 'jrxml' )" style="width:140px">
 <input type="button" value="$i18n.getString( 'back' )" onclick="javascript:window.location.href='displayManageTableForm.action'" style="width:140px">
 </div>