← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2486: Removed old ExportDataMartAction

 

------------------------------------------------------------
revno: 2486
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2011-01-07 15:48:39 +0000
message:
  Removed old ExportDataMartAction
  Renamed ExportPivotView to ExportDataMart
  Gzipped servlet output stream
  Remapped actions in preparation for indicator value export
removed:
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java
renamed:
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportPivotViewAction.java => dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java
modified:
  dhis-2/dhis-web/dhis-web-importexport/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.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
=== renamed file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportPivotViewAction.java' => 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportPivotViewAction.java	2010-12-19 00:24:59 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java	2011-01-07 15:48:39 +0000
@@ -45,21 +45,25 @@
 import org.hisp.dhis.importexport.synchronous.ExportPivotViewService;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.StreamUtils;
+import java.util.zip.GZIPOutputStream;
 
 /**
  * @author Bob Jolliffe
  *
- * This action is called to export a csv formatted selection from the datamart
+ * This action is called to export a csv formatted selection of aggregated indicator or
+ * data values from datamart.
  * It requires 4 parameters:
  * startdate and enddate: 8 character string representation of date - 20100624
  * root: id of root organization unit
  * level: level number to fetch aggregated values for
  */
-public class ExportPivotViewAction
+public class ExportDataMartAction
     implements Action
 {
+    // TODO: experiment with different sizes for this to stop data dribbling out
+    private static int GZIPBUFFER = 8192;
 
-    private static final Log log = LogFactory.getLog( ExportPivotViewAction.class );
+    private static final Log log = LogFactory.getLog( ExportDataMartAction.class );
 
     private static final DateFormat dateFormat = new SimpleDateFormat( "yyyyMMdd" );
     // parameter errors
@@ -74,9 +78,9 @@
 
     private static final String NO_ROOT = "The request is missing a non-zero dataSourceRoot parameter";
 
-    private static final String NO_LEVEL = "The request is missing a non-zero datasourceLevel parameter";
+    private static final String NO_LEVEL = "The request is missing a non-zero dataSourceLevel parameter";
+
     // http header result type
-
     private static final String CLIENT_ERROR = "client-error";
 
     private static final int HTTP_ERROR = 400;
@@ -147,6 +151,13 @@
         // Check all parameters
         // ---------------------------------------------------------------------
 
+
+        // first see how we action was called
+        String servletPath = request.getServletPath();
+        String requestType = servletPath.substring(servletPath.lastIndexOf( '/') + 1 );
+
+        log.info( "Request type : " + requestType );
+
         String paramError = null;
 
         if ( startDate == null )
@@ -205,14 +216,14 @@
         // prepare to write output
         OutputStream out = null;
 
-        // response.setContentType( "application/gzip");
-        // response.addHeader( "Content-Disposition", "attachment; filename=\"test.csv\"" );
+        response.setContentType( "application/gzip");
+        response.addHeader( "Content-Disposition", "attachment; filename=\"datavalues.csv.gz\"" );
         response.addHeader( "Cache-Control", "no-cache" );
         response.addHeader( "Expires", DateUtils.getExpiredHttpDateString() );
 
         try
         {
-            out = response.getOutputStream();
+            out = new GZIPOutputStream(response.getOutputStream(), GZIPBUFFER);
             exportPivotViewService.execute(out, start, end, dataSourceLevel, dataSourceRoot);
         }
         finally

=== removed file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java	2010-06-24 11:50:08 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java	1970-01-01 00:00:00 +0000
@@ -1,214 +0,0 @@
-package org.hisp.dhis.importexport.action.exp;
-
-/*
- * 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.
- */
-
-import static org.hisp.dhis.datamart.DataMartInternalProcess.PROCESS_TYPE;
-import static org.hisp.dhis.system.util.DateUtils.getMediumDate;
-import static org.hisp.dhis.util.InternalProcessUtil.PROCESS_KEY_EXPORT;
-import static org.hisp.dhis.util.InternalProcessUtil.setCurrentRunningProcess;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.amplecode.cave.process.ProcessCoordinator;
-import org.amplecode.cave.process.ProcessExecutor;
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.datamart.DataMartExport;
-import org.hisp.dhis.datamart.DataMartInternalProcess;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.oust.manager.SelectionTreeManager;
-import org.hisp.dhis.period.PeriodService;
-import org.hisp.dhis.user.CurrentUserService;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Lars Helge Overland
- * @version $Id$
- */
-public class ExportDataMartAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private ProcessCoordinator processCoordinator;
-
-    public void setProcessCoordinator( ProcessCoordinator processCoordinator )
-    {
-        this.processCoordinator = processCoordinator;
-    }
-    
-    private CurrentUserService currentUserService;
-
-    public void setCurrentUserService( CurrentUserService currentUserService )
-    {
-        this.currentUserService = currentUserService;
-    }
-    
-    private SelectionTreeManager selectionTreeManager;
-
-    public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
-    {
-        this.selectionTreeManager = selectionTreeManager;
-    }
-
-    private OrganisationUnitService organisationUnitService;
-
-    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
-    {
-        this.organisationUnitService = organisationUnitService;
-    }
-    
-    private DataSetService dataSetService;
-
-    public void setDataSetService( DataSetService dataSetService )
-    {
-        this.dataSetService = dataSetService;
-    }
-
-    private PeriodService periodService;
-
-    public void setPeriodService( PeriodService periodService )
-    {
-        this.periodService = periodService;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Collection<String> selectedDataSets;
-
-    public void setSelectedDataSets( Collection<String> selectedDataSets )
-    {
-        this.selectedDataSets = selectedDataSets;
-    }
-
-    private String startDate;
-
-    public void setStartDate( String startDate )
-    {
-        this.startDate = startDate;
-    }
-    
-    private String endDate;
-
-    public void setEndDate( String endDate )
-    {
-        this.endDate = endDate;
-    }
-
-    private int dataSourceLevel;
-
-    public void setDataSourceLevel( int dataSourceLevel )
-    {
-        this.dataSourceLevel = dataSourceLevel;
-    }
-    
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    // TODO CompleteDataSetRegistrations
-    // TODO intersecting periods?
-    
-    public String execute()
-    {
-        DataMartExport export = new DataMartExport();
-
-        // ---------------------------------------------------------------------
-        // Get DataElements
-        // ---------------------------------------------------------------------
-
-        if ( selectedDataSets != null )
-        {
-            Set<DataElement> distinctDataElements = new HashSet<DataElement>();
-            
-            for ( String dataSetId : selectedDataSets )
-            {
-                DataSet dataSet = dataSetService.getDataSet( Integer.parseInt( dataSetId ) );
-                
-                distinctDataElements.addAll( dataSet.getDataElements() );
-            }
-            
-            export.setDataElements( distinctDataElements );
-        }
-        
-        // ---------------------------------------------------------------------
-        // Get Periods
-        // ---------------------------------------------------------------------
-
-        if ( startDate != null && startDate.trim().length() > 0 && endDate != null && endDate.trim().length() > 0 )
-        {
-            Date selectedStartDate = getMediumDate( startDate );
-        
-            Date selectedEndDate = getMediumDate( endDate );
-        
-            export.getPeriods().addAll( periodService.getPeriodsBetweenDates( selectedStartDate, selectedEndDate ) );
-        }
-        
-        // ---------------------------------------------------------------------
-        // Get OrganisationUnit
-        // ---------------------------------------------------------------------
-        
-        Collection<OrganisationUnit> selectedUnits = selectionTreeManager.getReloadedSelectedOrganisationUnits();
-        
-        if ( selectedUnits != null )
-        {
-            for ( OrganisationUnit unit : selectedUnits )
-            {
-                export.getOrganisationUnits().addAll( organisationUnitService.getOrganisationUnitsAtLevel( dataSourceLevel, unit ) );
-            }
-        }
-
-        // ---------------------------------------------------------------------
-        // Start DataMartInternalProcess
-        // ---------------------------------------------------------------------
-        
-        String owner = currentUserService.getCurrentUsername();
-        
-        ProcessExecutor executor = processCoordinator.newProcess( PROCESS_TYPE, owner );
-        
-        DataMartInternalProcess process = (DataMartInternalProcess) executor.getProcess();
-        
-        process.setExport( export );
-        
-        processCoordinator.requestProcessExecution( executor );
-        
-        setCurrentRunningProcess( PROCESS_KEY_EXPORT, executor.getId() );
-        
-        return SUCCESS;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/META-INF/dhis/beans.xml	2010-12-19 00:24:59 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/META-INF/dhis/beans.xml	2011-01-07 15:48:39 +0000
@@ -173,22 +173,10 @@
 			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
 	</bean>
 
-	<bean id="org.hisp.dhis.importexport.action.exp.ExportDataMartAction"
+
+    <bean id="org.hisp.dhis.importexport.action.exp.ExportDataMartAction"
 		class="org.hisp.dhis.importexport.action.exp.ExportDataMartAction"
 		scope="prototype">
-		<property name="processCoordinator" ref="processCoordinator" />
-		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
-		<property name="selectionTreeManager"
-			ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
-		<property name="organisationUnitService"
-			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
-		<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
-		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
-	</bean>
-
-        <bean id="org.hisp.dhis.importexport.action.exp.ExportPivotViewAction"
-		class="org.hisp.dhis.importexport.action.exp.ExportPivotViewAction"
-		scope="prototype">
 		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 		<property name="exportPivotViewService" ref="org.hisp.dhis.importexport.synchronous.ExportPivotViewService" />
 	</bean>

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml	2010-12-19 00:24:59 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml	2011-01-07 15:48:39 +0000
@@ -191,12 +191,6 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 
-    <action name="exportPivotView" class="org.hisp.dhis.importexport.action.exp.ExportPivotViewAction">
-      <result name="success" type="outputStreamResult" />
-      <result name="client-error" type="httpheader">
-      </result>
-    </action>
-
     <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
     <!-- Dhis 1.4 Configuration                                        -->
     <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
@@ -218,4 +212,21 @@
     </action>
     
   </package>
+
+  <!-- Create a new namespace to map actions for exporting datamart -->
+  <package name="dhis-web-exportdatamart" extends="dhis-web-commons" namespace="/dhis-web-exportdatamart">
+
+      <!-- route all export value requests through same action -->
+
+      <action name="dataValues" class="org.hisp.dhis.importexport.action.exp.ExportDataMartAction">
+        <result name="success" type="outputStreamResult" />
+        <result name="client-error" type="httpheader" />
+      </action>
+
+      <action name="indicatorValues" class="org.hisp.dhis.importexport.action.exp.ExportDataMartAction">
+        <result name="success" type="outputStreamResult" />
+        <result name="client-error" type="httpheader" />
+      </action>
+
+  </package>
 </struts>