dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17006
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6627: Data export write as zip
------------------------------------------------------------
revno: 6627
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-04-17 23:38:26 +0200
message:
Data export write as zip
modified:
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.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-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2012-04-14 18:32:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2012-04-17 21:38:26 +0000
@@ -44,6 +44,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.util.StreamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
@@ -65,7 +66,9 @@
{
DataValueSet dataValueSet = new StreamingDataValueSet( XMLFactory.getXMLWriter( out ) );
- writeDataValueSet( dataSet, completeDate, period, orgUnit, dataElements, periods, orgUnits, dataValueSet );
+ writeDataValueSet( dataSet, completeDate, period, orgUnit, dataElements, periods, orgUnits, dataValueSet );
+
+ StreamUtils.closeOutputStream( out );
}
public void writeDataValueSetCsv( Set<DataElement> dataElements, Set<Period> periods, Set<OrganisationUnit> orgUnits, Writer writer )
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2012-04-14 18:32:00 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2012-04-17 21:38:26 +0000
@@ -27,13 +27,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
import static org.hisp.dhis.system.util.DateUtils.getMediumDate;
-import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
-import static org.hisp.dhis.util.ContextUtils.*;
+import static org.hisp.dhis.util.ContextUtils.CONTENT_TYPE_CSV;
+import static org.hisp.dhis.util.ContextUtils.CONTENT_TYPE_XML;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletResponse;
@@ -55,6 +61,8 @@
{
private final static String FILE_PREFIX = "Export";
private final static String FILE_SEPARATOR = "_";
+ private final static String EXTENSION_XML_ZIP = ".xml.zip";
+ private final static String EXTENSION_CSV_ZIP = ".csv.zip";
private final static String EXTENSION_XML = ".xml";
private final static String EXTENSION_CSV = ".csv";
private final static String FORMAT_CSV = "csv";
@@ -123,15 +131,17 @@
if ( FORMAT_CSV.equals( exportFormat ) )
{
- ContextUtils.configureResponse( response, CONTENT_TYPE_CSV, true, getFileName( EXTENSION_CSV ), true );
-
- dataValueSetService.writeDataValueSetCsv( selectedDataSets,getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, response.getWriter() );
+ ContextUtils.configureResponse( response, CONTENT_TYPE_CSV, true, getFileName( EXTENSION_CSV_ZIP ), true );
+
+ Writer writer = new OutputStreamWriter( getZipOut( response, EXTENSION_CSV ) );
+
+ dataValueSetService.writeDataValueSetCsv( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, writer );
}
else
{
- ContextUtils.configureResponse( response, CONTENT_TYPE_XML, true, getFileName( EXTENSION_XML ), true );
+ ContextUtils.configureResponse( response, CONTENT_TYPE_XML, true, getFileName( EXTENSION_XML_ZIP ), true );
- dataValueSetService.writeDataValueSet( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, response.getOutputStream() );
+ dataValueSetService.writeDataValueSet( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, getZipOut( response, EXTENSION_XML ) );
}
return SUCCESS;
@@ -152,4 +162,13 @@
return fileName + extension;
}
+
+ private ZipOutputStream getZipOut( HttpServletResponse response, String extension )
+ throws IOException
+ {
+ ZipOutputStream out = new ZipOutputStream( response.getOutputStream() );
+ out.putNextEntry( new ZipEntry( getFileName( extension ) ) );
+
+ return out;
+ }
}