← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2377: Fix bug: if user doesn't choose anything and click Generate Workbook button, an exception occurred.

 

------------------------------------------------------------
revno: 2377
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-10-15 16:47:16 +0700
message:
  Fix bug: if user doesn't choose anything and click Generate Workbook button, an exception occurred.
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessWorkbookAction.java
  dhis-2/dhis-web/dhis-web-reporting/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-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java	2010-08-30 06:24:45 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java	2010-10-15 09:47:16 +0000
@@ -365,16 +365,19 @@
 
             row = 7;
 
-            for ( DataSetCompletenessResult result : results )
+            if ( results != null )
             {
-                sheet.addCell( new Label( MARGIN_LEFT, row, result.getName(), text ) );
-                sheet.addCell( new Number( MARGIN_LEFT + 1, row, result.getRegistrations(), text ) );
-                sheet.addCell( new Number( MARGIN_LEFT + 2, row, result.getSources(), text ) );
-                sheet.addCell( new Number( MARGIN_LEFT + 3, row, result.getPercentage(), text ) );
-                sheet.addCell( new Number( MARGIN_LEFT + 4, row, result.getRegistrationsOnTime(), text ) );
-                sheet.addCell( new Number( MARGIN_LEFT + 5, row, result.getPercentageOnTime(), text ) );
+                for ( DataSetCompletenessResult result : results )
+                {
+                    sheet.addCell( new Label( MARGIN_LEFT, row, result.getName(), text ) );
+                    sheet.addCell( new Number( MARGIN_LEFT + 1, row, result.getRegistrations(), text ) );
+                    sheet.addCell( new Number( MARGIN_LEFT + 2, row, result.getSources(), text ) );
+                    sheet.addCell( new Number( MARGIN_LEFT + 3, row, result.getPercentage(), text ) );
+                    sheet.addCell( new Number( MARGIN_LEFT + 4, row, result.getRegistrationsOnTime(), text ) );
+                    sheet.addCell( new Number( MARGIN_LEFT + 5, row, result.getPercentageOnTime(), text ) );
 
-                row++;
+                    row++;
+                }
             }
 
             workbook.write();
@@ -456,7 +459,7 @@
                 workbook.write();
 
                 workbook.close();
-                
+
             }
         }
         catch ( IOException ex )

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessWorkbookAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessWorkbookAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessWorkbookAction.java	2010-10-15 09:47:16 +0000
@@ -96,13 +96,18 @@
     public String execute()
         throws Exception
     {
+        OrganisationUnit unit = selectionTreeManager.getSelectedOrganisationUnit();
+        
+        if ( unit == null )
+        {
+            return ERROR;
+        }
+
+        DataSet dataSet = (DataSet) SessionUtils.getSessionVar( KEY_DATA_COMPLETENESS_DATASET );
+        
         Collection<DataSetCompletenessResult> results = 
             (Collection<DataSetCompletenessResult>) SessionUtils.getSessionVar( KEY_DATA_COMPLETENESS );
 
-        DataSet dataSet = (DataSet) SessionUtils.getSessionVar( KEY_DATA_COMPLETENESS_DATASET );
-        
-        OrganisationUnit unit = selectionTreeManager.getSelectedOrganisationUnit();
-        
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         
         workbookService.writeDataSetCompletenessResult( results, out, i18n, unit, dataSet );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2010-09-20 08:49:55 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2010-10-15 09:47:16 +0000
@@ -338,6 +338,12 @@
 		<param name="menu">/dhis-web-reporting/menu.vm</param>
 	</action>
 	
+	<action name="dataCompletenessWorkbookError" class="org.hisp.dhis.reporting.action.NoAction">
+		<result name="success" type="velocity">/main.vm</result>
+		<param name="page">/dhis-web-commons/oust/selectedOrgunitError.vm</param>
+		<param name="menu">/dhis-web-reporting/menu.vm</param>
+	</action>
+	
     <action name="getDataCompletenessWorkbook" class="org.hisp.dhis.reporting.completeness.action.GetDataCompletenessWorkbookAction">
       <result name="success" type="stream">
         <param name="contentType">application/vnd.ms-excel</param>
@@ -345,6 +351,7 @@
         <param name="contentDisposition">filename="DataCompletenessReport.xls"</param>
         <param name="bufferSize">10240</param>        
       </result>
+      <result name="error" type="redirect">dataCompletenessWorkbookError.action</result>
     </action>
     
     <action name="displayConfigureDataCompletenessForm" class="org.hisp.dhis.reporting.completeness.action.GetDataCompletenessConfigurationAction">