← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3572: local vn - Fixed bug NPE when previewing importing data

 

------------------------------------------------------------
revno: 3572
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-05-11 15:13:37 +0700
message:
  local vn - Fixed bug NPE when previewing importing data
modified:
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetPeriodsByExcelItemGroupAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataFlowAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java
  local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties
  local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties
  local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml
  local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm
  local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js


--
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 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetPeriodsByExcelItemGroupAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetPeriodsByExcelItemGroupAction.java	2010-04-12 21:23:33 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetPeriodsByExcelItemGroupAction.java	2011-05-11 08:13:37 +0000
@@ -29,18 +29,17 @@
 import java.util.List;
 
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.reportexcel.action.ActionSupport;
 import org.hisp.dhis.reportexcel.excelitem.ExcelItemGroup;
 import org.hisp.dhis.reportexcel.excelitem.ExcelItemService;
 import org.hisp.dhis.reportexcel.period.generic.PeriodGenericManager;
 
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Chau Thu Tran
  * @version $Id$
  */
 public class GetPeriodsByExcelItemGroupAction
-    implements Action
+    extends ActionSupport
 {
 
     // -------------------------------------------------------------------------
@@ -57,7 +56,7 @@
 
     private List<Period> periods;
 
-    private Integer excelItemGroupId;
+    private String excelItemGroupId;
 
     // -------------------------------------------------------------------------
     // Getters & Setters
@@ -68,7 +67,7 @@
         return periods;
     }
 
-    public void setExcelItemGroupId( Integer excelItemGroupId )
+    public void setExcelItemGroupId( String excelItemGroupId )
     {
         this.excelItemGroupId = excelItemGroupId;
     }
@@ -90,8 +89,14 @@
     public String execute()
         throws Exception
     {
-
-        ExcelItemGroup excelItemGroup = excelItemService.getExcelItemGroup( excelItemGroupId );
+        if ( excelItemGroupId == null || excelItemGroupId.equals( "null" ) )
+        {
+            message = i18n.getString( "there_is_no_excel_item_group" );
+
+            return ERROR;
+        }
+
+        ExcelItemGroup excelItemGroup = excelItemService.getExcelItemGroup( Integer.parseInt( excelItemGroupId ) );
 
         periodGenericManager.setPeriodType( excelItemGroup.getPeriodType().getName() );
 

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataFlowAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataFlowAction.java	2010-04-12 21:23:33 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataFlowAction.java	2011-05-11 08:13:37 +0000
@@ -40,18 +40,17 @@
 public class ImportDataFlowAction
     implements Action
 {
-
-    // -------------------------------------------
+    // -------------------------------------------------------------------------
     // Dependency
-    // -------------------------------------------
+    // -------------------------------------------------------------------------
 
     private ExcelItemService excelItemService;
 
     private PeriodGenericManager periodGenericManager;
 
-    // -------------------------------------------
+    // -------------------------------------------------------------------------
     // Input & Output
-    // -------------------------------------------
+    // -------------------------------------------------------------------------
 
     private Integer excelItemGroupId;
 
@@ -61,9 +60,9 @@
 
     private Integer orgunitGroupId;
 
-    // -------------------------------------------
+    // -------------------------------------------------------------------------
     // Getter & Setter
-    // -------------------------------------------
+    // -------------------------------------------------------------------------
 
     public void setExcelItemGroupId( Integer excelItemGroupId )
     {
@@ -106,10 +105,13 @@
         this.orgunitGroupId = orgunitGroupId;
     }
 
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+    
     public String execute()
         throws Exception
     {
-
         periodGenericManager.setSelectedPeriodIndex( periodId );
 
         ExcelItemGroup excelItemGroup = excelItemService.getExcelItemGroup( excelItemGroupId );

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java	2010-09-06 09:12:16 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java	2011-05-11 08:13:37 +0000
@@ -62,10 +62,9 @@
 public class ImportDataNormalExcelGroupAction
     extends ActionSupport
 {
-
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // Dependencies
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     private DataValueService dataValueService;
 
@@ -85,17 +84,17 @@
 
     private PeriodGenericManager periodGenericManager;
 
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // Inputs && Outputs
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     private Integer excelItemGroupId;
 
     public Integer[] excelItemIds;
 
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // Getters and Setters
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     public void setOrganisationUnitSelectionManager( OrganisationUnitSelectionManager organisationUnitSelectionManager )
     {
@@ -152,9 +151,9 @@
         this.dataElementService = dataElementService;
     }
 
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // Action implementation
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     public String execute()
         throws Exception
@@ -177,6 +176,7 @@
             HSSFWorkbook wb = new HSSFWorkbook( upload );
 
             Collection<ExcelItem> excelItems = new ArrayList<ExcelItem>();
+            
             if ( excelItemIds != null )
             {
                 for ( int i = 0; i < excelItemIds.length; i++ )

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java	2011-05-05 21:16:42 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java	2011-05-11 08:13:37 +0000
@@ -51,9 +51,9 @@
 public class ViewDataNormalAction
     implements Action
 {
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // Inputs && Outputs
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     private File upload;
 
@@ -65,9 +65,9 @@
     
     private I18n i18n;
 
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // Getters and Setters
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     public void setUpload( File upload )
     {
@@ -94,9 +94,9 @@
         this.i18n = i18n;
     }
     
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
     // Action implementation
-    // --------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     public String execute()
     {

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties'
--- local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2011-03-28 06:49:08 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2011-05-11 08:13:37 +0000
@@ -272,4 +272,5 @@
 access_denied_to_folder     = Access denied to folder on server
 access_denied_to_file       = Access denied to file on server
 template_folder_is_not_empty= Warning\! The old template directory of system is not empty.\nWould you like to move its children to the new one before it deleted ?
-config_path_invalid			= Invalid configuration\! Only Alphabetic, Numbers, Undercore, Middlecore and Space alow.
\ No newline at end of file
+config_path_invalid			= Invalid configuration\! Only Alphabetic, Numbers, Undercore, Middlecore and Space alow.
+there_is_no_excel_item_group= There is no Excel item group in system
\ No newline at end of file

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties'
--- local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties	2011-03-28 06:49:08 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties	2011-05-11 08:13:37 +0000
@@ -264,4 +264,5 @@
 access_denied_to_folder     = Ba\u0323n kh\u00f4ng \u0111u\u0309 quy\u00ea\u0300n truy c\u00e2\u0323p va\u0300o th\u01b0 mu\u0323c tr\u00ean ma\u0301y chu\u0309
 access_denied_to_file       = Truy c\u1eadp b\u1ecb t\u1eeb ch\u1ed1i \u0111\u00ea\u0301n t\u1eadp tin tr\u00ean m\u00e1y ch\u1ee7
 template_folder_is_not_empty= C\u1ea3nh b\u00e1o! Th\u01b0 m\u1ee5c c\u0169 c\u1ee7a h\u1ec7 th\u1ed1ng hi\u1ec7n \u0111ang ch\u1ee9a c\u00e1c t\u1eadp tin excel m\u1eabu.\nB\u1ea1n c\u00f3 mu\u1ed1n di chuy\u1ec3n ch\u00fang qua th\u01b0 m\u1ee5c m\u1edbi tr\u01b0\u1edbc khi n\u00f3 b\u1ecb x\u00f3a \?
-config_path_invalid			= C\u1ea5u h\u00ecnh kh\u00f4ng h\u1ee3p l\u1ec7\! Ch\u1ec9 cho ph\u00e9p nh\u1eadp ch\u1eef c\u00e1i, ch\u1eef s\u1ed1, k\u00fd t\u1ef1 g\u1ea1ch d\u01b0\u1edbi, g\u1ea1ch ngang v\u00e0 kho\u1ea3ng tr\u1eafng.
\ No newline at end of file
+config_path_invalid			= C\u1ea5u h\u00ecnh kh\u00f4ng h\u1ee3p l\u1ec7\! Ch\u1ec9 cho ph\u00e9p nh\u1eadp ch\u1eef c\u00e1i, ch\u1eef s\u1ed1, k\u00fd t\u1ef1 g\u1ea1ch d\u01b0\u1edbi, g\u1ea1ch ngang v\u00e0 kho\u1ea3ng tr\u1eafng.
+there_is_no_excel_item_group= Ch\u01b0a c\u00f3 nh\u00f3m ph\u1ea7n t\u1eed import d\u1eef li\u1ec7u n\u00e0o \u0111\u01b0\u1ee3c t\u1ea1o trong h\u1ec7 th\u1ed1ng
\ No newline at end of file

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml'
--- local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml	2011-04-19 10:05:18 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml	2011-05-11 08:13:37 +0000
@@ -1059,6 +1059,8 @@
 			class="org.hisp.dhis.reportexcel.importing.action.GetPeriodsByExcelItemGroupAction">
 			<result name="success" type="velocity-xml">
 				/dhis-web-commons/ajax/xmlPeriods.vm</result>
+			<result name="error" type="velocity-xml">
+				/dhis-web-commons/ajax/xmlResponseError.vm</result>
 		</action>
 
 		<action name="openExcelItemGroupAssociations"

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm	2011-03-25 09:11:30 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm	2011-05-11 08:13:37 +0000
@@ -1,8 +1,8 @@
 <body>
 #if($!fileExcel)
-<div id="messageUpload">
-	$i18n.getString( "upload_file" ) $i18n.getString( "success" )<br>$fileExcel.getName()
-</div>
+	<div id="messageUpload">
+		$i18n.getString( "upload_file" ) $i18n.getString( "success" )<br>$fileExcel.getName()
+	</div>
 #end
 <span id="message" style="top:70px;right:5px;position:fixed;width:200px;z-index:100009" onclick="hideById(this.id);"></span>
 
@@ -20,9 +20,9 @@
 	<tr>
 		<td>$i18n.getString( 'excelitem_group' )</td>
 		<td>
-			<select type="text" id="excelItemGroupId" name="excelItemGroupId" #if(!$!fileExcel || !$!organisationUnit) disabled #end  style="min-width:20em;" onchange="getPeriodsByExcelItemGroup(this.value)">					
+			<select type="text" id="excelItemGroupId" name="excelItemGroupId" #if(!$!fileExcel || !$!organisationUnit) disabled #end style="min-width:20em;" onchange="getPeriodsByExcelItemGroup(this.value)">					
 			#foreach($excelItemGroup in $excelItemGroups)
-			<option value="$!excelItemGroup.id">$!encoder.htmlEncode($!excelItemGroup.name)</option>
+				<option value="$!excelItemGroup.id">$!encoder.htmlEncode($!excelItemGroup.name)</option>
 			#end
 			</select>
 			<input type="button" onClick="javascript: getPreviewImportData();" style="width:100px" value="$i18n.getString('preview')" #if(!$!fileExcel || !$!organisationUnit) disabled #end>
@@ -65,9 +65,8 @@
 	</div>
 <script language="javascript">	
 	
-	#if($!fileExcel && $!organisationUnit)
-		getPeriodsByExcelItemGroup($("#excelItemGroupId").val());
+	#if ( $!fileExcel && $!organisationUnit )
+		getPeriodsByExcelItemGroup( $("#excelItemGroupId").val() );
 	#end
 </script>
-</body>
-
+</body>
\ No newline at end of file

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js	2011-03-25 09:11:30 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js	2011-05-11 08:13:37 +0000
@@ -272,7 +272,7 @@
 // PERIOD TYPE
 // --------------------------------------------------------------------
 
-function getPeriodsByExcelItemGroup(excelItemGroupId) {
+function getPeriodsByExcelItemGroup( excelItemGroupId ) {
 	
 	var request = new Request();
 	request.setResponseTypeXML( 'xmlObject' );
@@ -283,14 +283,25 @@
 function responseListPeriodReceived( xmlObject ) {
 
 	clearListById('period');
-	var list = xmlObject.getElementsByTagName('period');
-	for ( var i = 0; i < list.length; i++ )
-    {
-        item = list[i];
-        var name = item.getElementsByTagName('name')[0].firstChild.nodeValue;
-        
-		addOption('period', name, i);
-    }
+	
+	var type = xmlObject.getAttribute( 'type' );
+
+	if ( (type != undefined) && (type == 'error') )
+	{
+		setHeaderDelayMessage( xmlObject.firstChild.nodeValue );
+	}
+	else
+	{
+		var list = xmlObject.getElementsByTagName('period');
+		
+		for ( var i = 0; i < list.length; i++ )
+		{
+			item = list[i];
+			var name = item.getElementsByTagName('name')[0].firstChild.nodeValue;
+			
+			addOption('period', name, i);
+		}
+	}
 }
 
 function lastPeriod() {