← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16026: PDF form resource, removed pointless stream flushing

 

------------------------------------------------------------
revno: 16026
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-07-08 18:35:33 +0200
message:
  PDF form resource, removed pointless stream flushing
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PDFFormController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemSynchronizationSettings.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PDFFormController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PDFFormController.java	2014-07-06 15:55:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PDFFormController.java	2014-07-08 16:35:33 +0000
@@ -29,7 +29,6 @@
  */
 
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.text.SimpleDateFormat;
@@ -40,9 +39,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
-import org.hisp.dhis.webapi.utils.PdfDataEntryFormImportUtil;
 import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
@@ -59,6 +55,9 @@
 import org.hisp.dhis.system.notification.Notifier;
 import org.hisp.dhis.system.util.StreamUtils;
 import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
+import org.hisp.dhis.webapi.utils.PdfDataEntryFormImportUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
@@ -67,7 +66,6 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 
 import com.lowagie.text.Document;
-import com.lowagie.text.DocumentException;
 import com.lowagie.text.pdf.PdfWriter;
 
 /**
@@ -79,8 +77,6 @@
 {
     private static final Log log = LogFactory.getLog( PDFFormController.class );
 
-    //private static final String DATEFORMAT_DEFAULT = "MMMM dd, yyyy";
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -114,9 +110,8 @@
     //--------------------------------------------------------------------------
 
     @RequestMapping(value = "/dataSet/{dataSetUid}", method = RequestMethod.GET)
-    public void getFormPDF_DataSet( HttpServletRequest request, HttpServletResponse response,
-        @PathVariable String dataSetUid )
-        throws Exception
+    public void getFormPdfDataSet( @PathVariable String dataSetUid, HttpServletRequest request, 
+        HttpServletResponse response, OutputStream out ) throws Exception
     {
         // 1. - Create Document and PdfWriter
         
@@ -147,12 +142,12 @@
         
         // 4. - Output the data into Stream and close the stream.
         
-        writeToOutputStream( baos, response );
+        baos.writeTo( out );
     }
 
     @RequestMapping(value = "/dataSet", method = RequestMethod.POST)
     @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" )
-    public void sendFormPDF_DataSet( HttpServletRequest request, HttpServletResponse response )
+    public void sendFormPdfDataSet( HttpServletRequest request, HttpServletResponse response )
         throws Exception
     {
         // 1. Set up Import Option
@@ -191,9 +186,8 @@
     //--------------------------------------------------------------------------
 
     @RequestMapping(value = "/programStage/{programStageUid}", method = RequestMethod.GET)
-    public void getFormPDF_ProgramStage( HttpServletRequest request, HttpServletResponse response,
-        @PathVariable String programStageUid )
-        throws IOException, DocumentException
+    public void getFormPdfProgramStage( @PathVariable String programStageUid, HttpServletRequest request, 
+        HttpServletResponse response, OutputStream out  ) throws Exception
     {
         // 1. - Create Document and PdfWriter
         
@@ -222,8 +216,8 @@
         response.setContentLength( baos.size() );
 
         // 4. - write ByteArrayOutputStream to the ServletOutputStream
-        
-        writeToOutputStream( baos, response );
+
+        baos.writeTo( out );
     }
 
     @RequestMapping( value = "/programStage", method = RequestMethod.POST )
@@ -243,28 +237,4 @@
         
         ContextUtils.okResponse( response, "" );
     }
-
-    //--------------------------------------------------------------------------
-    // Helpers
-    //--------------------------------------------------------------------------
-
-    private void writeToOutputStream( ByteArrayOutputStream baos, HttpServletResponse response ) //TODO unnecessary?
-        throws IOException
-    {
-        OutputStream os = null;
-
-        try
-        {
-            os = response.getOutputStream();
-            baos.writeTo( os );
-        }
-        finally
-        {
-            if ( os != null )
-            {
-                os.flush();
-                os.close();
-            }
-        }
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemSynchronizationSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemSynchronizationSettings.vm	2014-07-08 16:14:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemSynchronizationSettings.vm	2014-07-08 16:35:33 +0000
@@ -15,7 +15,6 @@
 </script>
 
 <h3>$i18n.getString( "data_synchronization" )</h3>
-	
 
 <div class="settingLabel">$i18n.getString( "remote_server_url" ) <span class="tipText">(https:// $i18n.getString( "recommended" ))</span></div>
 <div class="setting">