← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2555: Applied patch from lars to neaten up passing parameter to action

 

------------------------------------------------------------
revno: 2555
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2011-01-13 11:20:59 +0000
message:
  Applied patch from lars to neaten up passing parameter to action
  Minor mods to csv output - timestamped filename and quoted strings
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.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/resources/struts.xml


--
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-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java	2011-01-08 15:48:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java	2011-01-13 11:20:59 +0000
@@ -52,7 +52,6 @@
  * Exports pivot view synchronously (using calling thread)
  *
  * TODO: use exportparams and abstract service
- * TODO: implement indicator and width-wise queries
  *
  * @author bobj
  */
@@ -144,13 +143,14 @@
 
         AggregatedDataValue adv = Iterator.next();
 
+        writer.write("# period, orgunit, dataelement, catoptcombo, value\n");
         while (adv != null)
         {
             // process adv ..
             int periodId = adv.getPeriodId();
             String period = periodService.getPeriod( periodId).getIsoDate();
 
-            writer.write( period + ",");
+            writer.write( "'" + period + "',");
             writer.write( adv.getOrganisationUnitId() + ",");
             writer.write( adv.getDataElementId() + ",");
             writer.write( adv.getCategoryOptionComboId() + ",");
@@ -172,19 +172,20 @@
 
         AggregatedIndicatorValue aiv = Iterator.next();
 
+        writer.write("# period, orgunit, indicator, factor, numerator, denominator, annualized, value\n");
         while (aiv != null)
         {
             // process adv ..
             int periodId = aiv.getPeriodId();
             String period = periodService.getPeriod( periodId).getIsoDate();
 
-            writer.write( period + ",");
+            writer.write( "'" + period + "',");
             writer.write( aiv.getOrganisationUnitId() + ",");
             writer.write( aiv.getIndicatorId() + ",");
             writer.write( aiv.getFactor() + ",");
             writer.write( aiv.getNumeratorValue() + ",");
             writer.write( aiv.getDenominatorValue() + ",");
-            writer.write( aiv.getAnnualized() + ",");
+            writer.write( "'" + aiv.getAnnualized() + "',");
             writer.write( aiv.getValue() + "\n");
 
             aiv = Iterator.next();

=== modified 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	2011-01-10 12:05:06 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java	2011-01-13 11:20:59 +0000
@@ -28,6 +28,7 @@
  */
 
 
+import java.sql.Timestamp;
 import java.util.Date;
 
 import org.hisp.dhis.user.CurrentUserService;
@@ -42,6 +43,7 @@
 import java.io.OutputStream;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.apache.commons.logging.Log;
@@ -135,6 +137,13 @@
     {
         this.dataSourceRoot = dataSourceRoot;
     }
+    
+    private RequestType requestType;
+
+    public void setRequestType( RequestType requestType )
+    {
+        this.requestType = requestType;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -153,15 +162,6 @@
         // Check all parameters
         // ---------------------------------------------------------------------
 
-        // first see how action was called
-        String servletPath = request.getServletPath();
-        String requestTypeStr = servletPath.substring(servletPath.lastIndexOf( '/') + 1 );
-
-        log.info( "Request type : " + requestTypeStr );
-
-        RequestType requestType
-            = requestTypeStr.equals( "dataValues.action") ? RequestType.DATAVALUE : RequestType.INDICATORVALUE ;
-
         String paramError = null;
 
         if ( startDate == null )
@@ -217,11 +217,15 @@
             return CLIENT_ERROR;
         }
 
+        // timestamp filename
+        SimpleDateFormat format = new SimpleDateFormat( "_yyyy_MM_dd_HHmm_ss" );
+        String fileName = requestType + format.format(Calendar.getInstance().getTime()) + ".csv.gz";
+
         // prepare to write output
         OutputStream out = null;
 
         response.setContentType( "application/gzip");
-        response.addHeader( "Content-Disposition", "attachment; filename=\"datavalues.csv.gz\"" );
+        response.addHeader( "Content-Disposition", "attachment; filename=\""+fileName+"\"" );
         response.addHeader( "Cache-Control", "no-cache" );
         response.addHeader( "Expires", DateUtils.getExpiredHttpDateString() );
 

=== 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	2011-01-11 16:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml	2011-01-13 11:20:59 +0000
@@ -223,11 +223,13 @@
       <action name="dataValues" class="org.hisp.dhis.importexport.action.exp.ExportDataMartAction">
         <result name="success" type="outputStreamResult" />
         <result name="client-error" type="httpheader" />
+        <param name="requestType">DATAVALUE</param>
       </action>
 
       <action name="indicatorValues" class="org.hisp.dhis.importexport.action.exp.ExportDataMartAction">
         <result name="success" type="outputStreamResult" />
         <result name="client-error" type="httpheader" />
+        <param name="requestType">INDICATORVALUE</param>
       </action>
 
   </package>