dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #00650
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 175: dhis-web-reporting: Added support for export to CSV for report table
------------------------------------------------------------
revno: 175
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2009-04-16 11:53:17 +0200
message:
dhis-web-reporting: Added support for export to CSV for report table
added:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/ReportTableDataConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/CSVExportPipeThread.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/images/csv.png
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetTableDataExportAction.java
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-reporting/pom.xml
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/resources/xwork.xml
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv'
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/ReportTableDataConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/ReportTableDataConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/ReportTableDataConverter.java 2009-04-16 09:53:17 +0000
@@ -0,0 +1,122 @@
+package org.hisp.dhis.importexport.csv.converter;
+
+/*
+ * Copyright (c) 2004-2007, 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.
+ */
+
+import static org.hisp.dhis.importexport.csv.util.CsvUtil.SEPARATOR;
+import static org.hisp.dhis.importexport.csv.util.CsvUtil.csvEncode;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.SortedMap;
+
+import org.hisp.dhis.importexport.CSVConverter;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.ImportParams;
+import org.hisp.dhis.reporttable.ReportTableData;
+import org.hisp.dhis.reporttable.ReportTableService;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class ReportTableDataConverter
+ implements CSVConverter
+{
+ private ReportTableService reportTableService;
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ /**
+ * Constructor for write operations.
+ *
+ * @param reportTableService the reportTableService to use.
+ */
+ public ReportTableDataConverter( ReportTableService reportTableService )
+ {
+ this.reportTableService = reportTableService;
+ }
+
+ // -------------------------------------------------------------------------
+ // CSVConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( BufferedWriter writer, ExportParams params )
+ {
+ try
+ {
+ for ( Integer id : params.getReportTables() ) //TODO more than one?
+ {
+ ReportTableData data = reportTableService.getReportTableData( id );
+
+ Iterator<String> columns = data.getPrettyPrintColumns().iterator();
+
+ while ( columns.hasNext() )
+ {
+ writer.write( csvEncode( columns.next() ) );
+
+ if ( columns.hasNext() )
+ {
+ writer.write( SEPARATOR );
+ }
+ }
+
+ writer.newLine();
+
+ for ( SortedMap<Integer, String> row : data.getRows() )
+ {
+ Iterator<String> values = row.values().iterator();
+
+ while ( values.hasNext() )
+ {
+ writer.write( values.next() );
+
+ if ( values.hasNext() )
+ {
+ writer.write( SEPARATOR );
+ }
+ }
+
+ writer.newLine();
+ }
+ }
+ }
+ catch ( IOException ex )
+ {
+ throw new RuntimeException( "Failed to write ReportTableData CSV", ex );
+ }
+ }
+
+ public void read( BufferedReader reader, ImportParams params )
+ {
+ // Not implemented
+ }
+}
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/CSVExportPipeThread.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/CSVExportPipeThread.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/CSVExportPipeThread.java 2009-04-16 09:53:17 +0000
@@ -0,0 +1,104 @@
+package org.hisp.dhis.importexport.csv.exporter;
+
+/*
+ * Copyright (c) 2004-2007, 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.
+ */
+
+import java.io.BufferedWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.importexport.CSVConverter;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.system.util.StreamUtils;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class CSVExportPipeThread
+ extends Thread
+{
+ private static final Log log = LogFactory.getLog( CSVExportPipeThread.class );
+
+ private BufferedWriter writer;
+
+ public void setWriter( BufferedWriter writer )
+ {
+ this.writer = writer;
+ }
+
+ private ExportParams params;
+
+ public void setParams( ExportParams params )
+ {
+ this.params = params;
+ }
+
+ private List<CSVConverter> converters = new ArrayList<CSVConverter>();
+
+ public void registerCSVConverter( CSVConverter converter )
+ {
+ this.converters.add( converter );
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ public CSVExportPipeThread()
+ {
+ }
+
+ // -------------------------------------------------------------------------
+ // Thread implementation
+ // -------------------------------------------------------------------------
+
+ public void run()
+ {
+ try
+ {
+ log.info( "Export started" );
+
+ for ( CSVConverter converter : converters )
+ {
+ converter.write( writer, params );
+ }
+
+ log.info( "Export finished" );
+ }
+ catch ( Exception ex )
+ {
+ throw new RuntimeException( ex );
+ }
+ finally
+ {
+ StreamUtils.closeWriter( writer );
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java 2009-04-16 09:53:17 +0000
@@ -0,0 +1,114 @@
+package org.hisp.dhis.importexport.csv.exporter;
+
+/*
+ * Copyright (c) 2004-2007, 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.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.ExportService;
+import org.hisp.dhis.importexport.csv.converter.ReportTableDataConverter;
+import org.hisp.dhis.reporttable.ReportTableService;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id: DefaultDXFExportService.java 5960 2008-10-17 14:07:50Z larshelg $
+ */
+public class DefaultCSVExportService
+ implements ExportService
+{
+ private static final String ZIP_ENTRY_NAME = "Export.csv";
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private ReportTableService reportTableService;
+
+ public void setReportTableService( ReportTableService reportTableService )
+ {
+ this.reportTableService = reportTableService;
+ }
+
+ // -------------------------------------------------------------------------
+ // ExportService implementation
+ // -------------------------------------------------------------------------
+
+ public InputStream exportData( ExportParams params )
+ {
+ try
+ {
+ // -----------------------------------------------------------------
+ // Pipes are input/output pairs. Data written on the output stream
+ // shows up on the input stream at the other end of the pipe.
+ // -----------------------------------------------------------------
+
+ PipedOutputStream out = new PipedOutputStream();
+
+ PipedInputStream in = new PipedInputStream( out );
+
+ ZipOutputStream zipOut = new ZipOutputStream( out );
+
+ zipOut.putNextEntry( new ZipEntry( ZIP_ENTRY_NAME ) );
+
+ BufferedWriter writer = new BufferedWriter( new OutputStreamWriter( zipOut ) );
+
+ // -----------------------------------------------------------------
+ // Writes to one end of the pipe
+ // -----------------------------------------------------------------
+
+ CSVExportPipeThread thread = new CSVExportPipeThread();
+
+ thread.setWriter( writer );
+ thread.setParams( params );
+
+ thread.registerCSVConverter( new ReportTableDataConverter( reportTableService ) );
+
+ thread.start();
+
+ // -----------------------------------------------------------------
+ // Reads at the other end of the pipe
+ // -----------------------------------------------------------------
+
+ InputStream bis = new BufferedInputStream( in );
+
+ return bis;
+ }
+ catch ( IOException ex )
+ {
+ throw new RuntimeException( "Error occured during export to stream", ex );
+ }
+ }
+}
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java 2009-04-16 09:53:17 +0000
@@ -0,0 +1,47 @@
+package org.hisp.dhis.importexport.csv.util;
+
+/*
+ * Copyright (c) 2004-2007, 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
+ * @version $Id$
+ */
+public class CsvUtil
+{
+ public static final char SEPARATOR = ',';
+
+ private static final String ENCLOSURE = "\"";
+
+ public static String csvEncode( String string )
+ {
+ string = string.replaceAll( ENCLOSURE, ENCLOSURE + ENCLOSURE );
+ string = ENCLOSURE + string + ENCLOSURE;
+
+ return string;
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2009-03-26 07:54:33 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2009-04-16 09:53:17 +0000
@@ -75,6 +75,10 @@
<key><value>DHIS14XML</value></key>
<ref bean="org.hisp.dhis.importexport.Dhis14XMLExportService"/>
</entry>
+ <entry>
+ <key><value>CSV</value></key>
+ <ref bean="org.hisp.dhis.importexport.CSVExportService"/>
+ </entry>
</map>
</property>
</bean>
@@ -451,6 +455,16 @@
</bean>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+ <!-- DHIS 1.4 XML Export -->
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+
+ <bean id="org.hisp.dhis.importexport.CSVExportService"
+ class="org.hisp.dhis.importexport.csv.exporter.DefaultCSVExportService">
+ <property name="reportTableService"
+ ref="org.hisp.dhis.reporttable.ReportTableService"/>
+ </bean>
+
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Mapping -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/images/csv.png'
Binary files dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/images/csv.png 1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/images/csv.png 2009-04-16 09:53:17 +0000 differ
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/pom.xml'
--- dhis-2/dhis-web/dhis-web-reporting/pom.xml 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/pom.xml 2009-04-16 09:53:17 +0000
@@ -56,6 +56,10 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-importexport</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-support-external</artifactId>
</dependency>
=== added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetTableDataExportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetTableDataExportAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetTableDataExportAction.java 2009-04-16 09:53:17 +0000
@@ -0,0 +1,83 @@
+package org.hisp.dhis.reporting.tablecreator.action;
+
+import java.io.InputStream;
+
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.ExportService;
+import org.hisp.dhis.importexport.ImportExportServiceManager;
+
+import com.opensymphony.xwork.Action;
+
+public class GetTableDataExportAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private ImportExportServiceManager serviceManager;
+
+ public void setServiceManager( ImportExportServiceManager serviceManager )
+ {
+ this.serviceManager = serviceManager;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private Integer id;
+
+ public void setId( Integer id )
+ {
+ this.id = id;
+ }
+
+ private String exportFormat;
+
+ public void setExportFormat( String exportFormat )
+ {
+ this.exportFormat = exportFormat;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private InputStream inputStream;
+
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+
+ private String fileName;
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute() throws Exception
+ {
+ ExportService exportService = serviceManager.getExportService( exportFormat );
+
+ ExportParams params = new ExportParams();
+
+ params.getReportTables().add( id );
+
+ inputStream = exportService.exportData( params );
+ /*
+ int l = 0;
+ while ( ( l = inputStream.read() ) != -1 )
+ System.out.println( l);
+ */
+ fileName = "ReportTable.zip";
+
+ 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 2009-04-02 12:32:16 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2009-04-16 09:53:17 +0000
@@ -252,6 +252,13 @@
ref="org.hisp.dhis.reporttable.ReportTableService"/>
</bean>
+ <bean id="org.hisp.dhis.reporting.tablecreator.action.GetTableDataExportAction"
+ class="org.hisp.dhis.reporting.tablecreator.action.GetTableDataExportAction"
+ scope="prototype">
+ <property name="serviceManager"
+ ref="org.hisp.dhis.importexport.ImportExportServiceManager"/>
+ </bean>
+
<!-- ReportViewer -->
<bean id="org.hisp.dhis.reporting.reportviewer.action.AddReportAction"
=== 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 2009-03-06 12:31:27 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2009-04-16 09:53:17 +0000
@@ -241,3 +241,4 @@
file = File
url = URL
type = Type
+export_to_csv = Export to CSV
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/xwork.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/xwork.xml 2009-03-24 10:31:31 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/xwork.xml 2009-04-16 09:53:17 +0000
@@ -226,6 +226,15 @@
<param name="onExceptionReturn">plainTextError</param>
</action>
+ <action name="getTableDataExport" class="org.hisp.dhis.reporting.tablecreator.action.GetTableDataExportAction">
+ <result name="success" type="stream">
+ <param name="contentType">text/plain</param>
+ <param name="inputName">inputStream</param>
+ <param name="contentDisposition">filename="${fileName}"</param>
+ <param name="bufferSize">10240</param>
+ </result>
+ </action>
+
<!-- PivotTable -->
<action name="displayPivotTableForm" class="org.hisp.dhis.reporting.action.NoAction">
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm 2009-03-23 19:20:18 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm 2009-04-16 09:53:17 +0000
@@ -11,8 +11,9 @@
<col width="20">
<col width="20">
<col width="20">
+ <col width="20">
<tr>
- <td colspan="5" style="text-align:right">
+ <td colspan="6" style="text-align:right">
<input type="button" value="$i18n.getString( 'add_indicator_reporttable' )" style="width:250px" onclick="window.location.href='displayAddTableForm.action?mode=indicators'"><br>
<input type="button" value="$i18n.getString( 'add_dataelement_reporttable' )" style="width:250px" onclick="window.location.href='displayAddTableForm.action?mode=dataelements'"><br>
<input type="button" value="$i18n.getString( 'add_dataelement_category_reporttable' )" style="width:250px" onclick="window.location.href='displayAddTableForm.action?mode=dataelements&category=true'"><br>
@@ -21,7 +22,7 @@
</tr>
<tr>
<th>$i18n.getString( "name" )</th>
- <th colspan="4">$i18n.getString( "operations" )</th>
+ <th colspan="5">$i18n.getString( "operations" )</th>
</tr>
#set( $mark = false )
#foreach ( $table in $tables )
@@ -29,6 +30,7 @@
<td#alternate( $mark )>$encoder.htmlEncode( $table.name )</td>
<td style="text-align:center"#alternate( $mark )><a href="getReportParams.action?id=$table.id&mode=table" title="$i18n.getString( "create" )"><img src="../images/start_process.png" alt="$i18n.getString( "create" )"></a></td>
<td style="text-align:center"#alternate( $mark )><a href="displayAddTableForm.action?id=$table.id&mode=$table.mode&category=$table.hasCategoryOptionCombos()" title="$i18n.getString( "edit" )"><img src="../images/edit.png" alt="$i18n.getString( "edit" )"></a></td>
+ <td style="text-align:center"#alternate( $mark )><a href="getTableDataExport.action?id=$table.id&exportFormat=CSV" title="$i18n.getString( "export_to_csv" )"><img src="../images/csv.png" alt="$i18n.getString( "export_to_csv" )"></a></td>
<td style="text-align:center"#alternate( $mark )><a href="javascript:removeTable( $table.id, '$encoder.jsEncode( $table.name )' )" title="$i18n.getString( "remove" )"><img src="../images/delete.png" alt="$i18n.getString( "remove" )"></a></td>
<td style="text-align:center"#alternate( $mark )><a href="javascript:showTableDetails( $table.id )" title="$i18n.getString( "show_details" )"><img src="../images/information.png" alt="$i18n.getString( "show_details" )"></a></td>
</tr>
--
Trunk
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.