← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4104: local vn - Added new validation on excel formula. Applied excel formula type unneccessary into re...

 

------------------------------------------------------------
revno: 4104
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-07-08 14:52:59 +0700
message:
  local vn - Added new validation on excel formula. Applied excel formula type unneccessary into report Normal only.
added:
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationFormulaAction.java
modified:
  local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java
  local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java
  local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportCategoryAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportNormalAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportOrgGroupListingAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportPeriodColumnListingAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationExportItemAction.java
  local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java
  local/vn/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml
  local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml
  local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/import/importItems.vm
  local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exportItem.js
  local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/periodcolumns.vm
  local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/excelFormulaExpressionBuilderForm.vm
  local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/exportItems.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 'local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java'
--- local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java	2011-05-24 07:48:23 +0000
+++ local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java	2011-07-08 07:52:59 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.reportexcel;
 
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

=== modified file 'local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java'
--- local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java	2011-05-24 07:48:23 +0000
+++ local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java	2011-07-08 07:52:59 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.reportexcel;
 
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

=== modified file 'local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java'
--- local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java	2011-05-24 07:48:23 +0000
+++ local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java	2011-07-08 07:52:59 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.reportexcel;
 
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -116,7 +116,6 @@
         types.add( ReportExcelItem.TYPE.ORGANISATION );
         types.add( ReportExcelItem.TYPE.INDICATOR );
         types.add( ReportExcelItem.TYPE.SERIAL );
-        types.add( ReportExcelItem.TYPE.FORMULA_EXCEL );
 
         return types;
     }

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportCategoryAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportCategoryAction.java	2011-05-24 07:48:23 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportCategoryAction.java	2011-07-08 07:52:59 +0000
@@ -1,5 +1,7 @@
+package org.hisp.dhis.reportexcel.exporting.action;
+
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,7 +26,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.hisp.dhis.reportexcel.exporting.action;
 
 import java.util.Collection;
 
@@ -84,8 +85,6 @@
     {
         for ( ReportExcelItem reportItem : exportReportItems )
         {
-            int iRow = 0;
-            int iCol = 0;
             int rowBegin = reportItem.getRow();
 
             for ( DataElementGroupOrder dataElementGroup : exportReport.getDataElementOrders() )
@@ -123,11 +122,6 @@
                         ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( serial ),
                             ExcelUtils.NUMBER, sheet, this.csTextSerial );
                     }
-                    else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.FORMULA_EXCEL ) )
-                    {
-                        ExcelUtils.writeFormulaByPOI( rowBegin, reportItem.getColumn(), ExcelUtils
-                            .checkingExcelFormula( reportItem.getExpression(), iRow, iCol ), sheet, this.csFormula );
-                    }
                     else
                     {
                         ReportExcelItem newReportItem = new ReportExcelItem();
@@ -150,7 +144,6 @@
                     }
                     rowBegin++;
                     serial++;
-                    iRow++;
                 }
 
                 if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) )

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportNormalAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportNormalAction.java	2011-05-24 07:48:23 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportNormalAction.java	2011-07-08 07:52:59 +0000
@@ -1,5 +1,7 @@
+package org.hisp.dhis.reportexcel.exporting.action;
+
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,7 +26,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.hisp.dhis.reportexcel.exporting.action;
 
 import java.util.Collection;
 
@@ -51,7 +52,7 @@
         throws Exception
     {
         OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
-        
+
         ReportExcelNormal exportReportInstance = (ReportExcelNormal) exportReport;
 
         this.installReadTemplateFile( exportReportInstance, period, organisationUnit );
@@ -72,7 +73,7 @@
             this.recalculatingFormula( sheet );
         }
     }
-    
+
     // -------------------------------------------------------------------------
     // Supportive method
     // -------------------------------------------------------------------------
@@ -88,16 +89,20 @@
 
                 ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn(), String.valueOf( value ),
                     ExcelUtils.NUMBER, sheet, this.csNumber );
-
             }
-
-            if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.INDICATOR ) )
+            else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.INDICATOR ) )
             {
                 double value = getIndicatorValue( reportItem, organisationUnit );
 
                 ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn(), String.valueOf( value ),
                     ExcelUtils.NUMBER, sheet, this.csNumber );
             }
+            else
+            // EXCEL FORMULA
+            {
+                ExcelUtils.writeFormulaByPOI( reportItem.getRow(), reportItem.getColumn(), reportItem.getExpression(),
+                    sheet, this.csFormula );
+            }
         }
     }
 

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportOrgGroupListingAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportOrgGroupListingAction.java	2011-05-24 07:48:23 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportOrgGroupListingAction.java	2011-07-08 07:52:59 +0000
@@ -1,5 +1,7 @@
+package org.hisp.dhis.reportexcel.exporting.action;
+
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,7 +26,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.hisp.dhis.reportexcel.exporting.action;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -71,13 +72,13 @@
     // -------------------------------------------------------------------------
     // Override
     // -------------------------------------------------------------------------
-    
+
     @Override
     protected void executeGenerateOutputFile( ReportExcel exportReport, Period period )
         throws Exception
     {
         OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
-        
+
         ReportExcelOganiztionGroupListing exportReportInstance = (ReportExcelOganiztionGroupListing) exportReport;
 
         Map<OrganisationUnitGroup, OrganisationUnitLevel> orgUniGroupAtLevels = new HashMap<OrganisationUnitGroup, OrganisationUnitLevel>(
@@ -106,7 +107,7 @@
     // -------------------------------------------------------------------------
     // Supportive method
     // -------------------------------------------------------------------------
-    
+
     private void generateOutPutFile( ReportExcelOganiztionGroupListing exportReport,
         Map<OrganisationUnitGroup, OrganisationUnitLevel> orgUniGroupAtLevels,
         Collection<ReportExcelItem> exportReportItems, OrganisationUnit organisationUnit, Sheet sheet )
@@ -114,8 +115,6 @@
 
         for ( ReportExcelItem reportItem : exportReportItems )
         {
-            int iRow = 0;
-            int iCol = 0;
             int chapperNo = 0;
             int firstRow = reportItem.getRow();
             int rowBegin = firstRow + 1;
@@ -193,15 +192,9 @@
                         ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ),
                             ExcelUtils.NUMBER, sheet, this.csNumber );
                     }
-                    else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.FORMULA_EXCEL ) )
-                    {
-                        ExcelUtils.writeFormulaByPOI( rowBegin, reportItem.getColumn(), ExcelUtils
-                            .checkingExcelFormula( reportItem.getExpression(), iRow, iCol ), sheet, this.csFormula );
-                    }
 
                     rowBegin++;
                     serial++;
-                    iRow++;
                 }
 
                 if ( (reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) || reportItem
@@ -215,7 +208,6 @@
 
                     totalFormula += columnName + beginChapter + ",";
                 }
-
             }
 
             if ( (reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) || reportItem

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportPeriodColumnListingAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportPeriodColumnListingAction.java	2011-05-24 07:48:23 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exporting/action/GenerateReportPeriodColumnListingAction.java	2011-07-08 07:52:59 +0000
@@ -1,5 +1,7 @@
+package org.hisp.dhis.reportexcel.exporting.action;
+
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,7 +26,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.hisp.dhis.reportexcel.exporting.action;
 
 import java.util.Collection;
 import java.util.Set;

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationExportItemAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationExportItemAction.java	2011-06-24 07:04:01 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationExportItemAction.java	2011-07-08 07:52:59 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.reportexcel.exportitem.action;
 
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -102,7 +102,6 @@
 
     public String execute()
         throws Exception
-
     {
         if ( sheetNo == null )
         {

=== added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationFormulaAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationFormulaAction.java	1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/exportitem/action/ValidationFormulaAction.java	2011-07-08 07:52:59 +0000
@@ -0,0 +1,69 @@
+package org.hisp.dhis.reportexcel.exportitem.action;
+
+/*
+ * Copyright (c) 2004-2011, 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.reportexcel.utils.ExcelUtils.isValidFormula;
+
+import org.hisp.dhis.reportexcel.action.ActionSupport;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class ValidationFormulaAction
+    extends ActionSupport
+{
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private String formula;
+
+    public void setFormula( String formula )
+    {
+        this.formula = formula;
+    }
+
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {       
+        if ( formula != null && !isValidFormula( formula ) )
+        {
+            message = i18n.getString( "formula_is_invalid" );
+            
+            return ERROR;
+        }
+        
+        return SUCCESS;
+    }
+}

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java	2011-01-25 17:29:41 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java	2011-07-08 07:52:59 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.reportexcel.utils;
 
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,11 @@
 import jxl.write.WriteException;
 import jxl.write.biff.RowsExceededException;
 
+import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.FormulaParser;
+import org.apache.poi.ss.formula.FormulaParsingWorkbook;
+
 /**
  * @author Tran Thanh Tri
  * @author Chau Thu Tran
@@ -53,6 +58,8 @@
 
     private static Matcher matcher = null;
 
+    private static FormulaParsingWorkbook evaluationWorkbook = HSSFEvaluationWorkbook.create( new HSSFWorkbook() );
+
     private static final String PATTERN_FOR_ROW = "(\\d{1,})";
 
     private static final String PATTERN_FOR_COLUMN = "([a-zA-Z])";
@@ -74,7 +81,7 @@
     public static final String NUMBER = "NUMBER";
 
     public static final String EXTENSION_XLS = ".xls";
-    
+
     // -------------------------------------------------------------------------
     //
     // -------------------------------------------------------------------------
@@ -454,6 +461,20 @@
         return string_formula;
     }
 
+    public static boolean isValidFormula( String formula )
+    {
+        try
+        {
+            FormulaParser.parse( formula, evaluationWorkbook );
+        }
+        catch ( Exception e )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- local/vn/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-06-07 10:07:02 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-07-08 07:52:59 +0000
@@ -351,6 +351,11 @@
 		scope="prototype">
 		<property name="exportReportService" ref="org.hisp.dhis.reportexcel.ExportReportService" />
 	</bean>
+	
+	<bean
+		id="org.hisp.dhis.reportexcel.exportitem.action.ValidationFormulaAction"
+		class="org.hisp.dhis.reportexcel.exportitem.action.ValidationFormulaAction"
+		scope="prototype"/>
 
 	<bean
 		id="org.hisp.dhis.reportexcel.exportitem.action.DeleteExportItemAction"

=== 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-07-05 07:08:32 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml	2011-07-08 07:52:59 +0000
@@ -314,6 +314,15 @@
 			<param name="onExceptionReturn">plainTextError</param>
 		</action>
 
+		<action name="validationFormula"
+			class="org.hisp.dhis.reportexcel.exportitem.action.ValidationFormulaAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+			<result name="error" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseError.vm</result>
+			<param name="onExceptionReturn">plainTextError</param>
+		</action>
+
 		<action name="addExportItemForm"
 			class="org.hisp.dhis.reportexcel.exportitem.action.SetupExportItemFormAction">
 			<result name="success" type="velocity">/main.vm</result>

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/import/importItems.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/import/importItems.vm	2011-07-05 07:08:32 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/import/importItems.vm	2011-07-08 07:52:59 +0000
@@ -26,9 +26,9 @@
 			$i18n.getString( "filter_by_name" ): <input type="text" onkeyup="filterValues( this.value , 2)" style="width:300px;"/>
 		</td>
 		<td align="right">	
-			<input type="button" onclick="window.location.href='addImportItemForm.action?importReportId=$importReport.id' " value="$i18n.getString('add')" style="width:150px"/> <br>
-			<input type="button" onclick="copySelectedItemToGroup()" value="$i18n.getString('copy_import_item_to_importreport')" style="width:150px"/><br>
-			<input type="button" onclick="window.location='listAllImportReport.action'" value="$i18n.getString('cancel')" style="width:150px"/>
+			<input type="button" onclick="window.location.href='addImportItemForm.action?importReportId=$importReport.id' " value="$i18n.getString('add')" style="width:200px"/> <br>
+			<input type="button" onclick="copySelectedItemToGroup()" value="$i18n.getString('copy_import_item_to_importreport')" style="width:200px"/><br>
+			<input type="button" onclick="window.location='listAllImportReport.action'" value="$i18n.getString('cancel')" style="width:200px"/>
 		</td>
 	</tr>
 </table>

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exportItem.js'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exportItem.js	2011-07-05 07:08:32 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exportItem.js	2011-07-08 07:52:59 +0000
@@ -81,16 +81,15 @@
 	});		
 }
 
-
 function validateAddExportItem( form )
 {
 	jQuery.postJSON('validationExportItem.action',
 	{
 		exportReportId: getFieldValue( 'exportReportId' ),
+		name: getFieldValue( 'name' ),
 		sheetNo: getFieldValue( 'sheetNo' ),
 		row: getFieldValue( 'row' ),
-		column: getFieldValue( 'column' ),
-		name: getFieldValue( 'name' )
+		column: getFieldValue( 'column' )
 
 	},function( json ){
 		if(json.response == 'success'){					
@@ -107,10 +106,10 @@
 	{
 		id: getFieldValue( 'id' ),
 		exportReportId: getFieldValue( 'exportReportId' ),
+		name: getFieldValue( 'name' ),
 		sheetNo: getFieldValue( 'sheetNo' ),
 		row: getFieldValue( 'row' ),
-		column: getFieldValue( 'column' ),
-		name: getFieldValue( 'name' )
+		column: getFieldValue( 'column' )
 
 	},function( json ){
 		if(json.response == 'success'){

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/periodcolumns.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/periodcolumns.vm	2011-07-05 07:08:32 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/periodcolumns.vm	2011-07-08 07:52:59 +0000
@@ -1,1 +1,1 @@
-<script>

	jQuery(document).ready(function(){
		datePickerInRange( 'startdate' , 'enddate' );	
		tableSorter( 'listTable' );
		
		validation( 'periodColumnForm', function( form ){ 
			form.action = getFieldValue('action');
			form.submit();
		});
		
		periodColumnDialog = setUpDialog( 'periodColumn', i18n_expression, 410, 210 );
	});
	
	var i18n_startdate_null = "$encoder.jsEscape($i18n.getString( 'startdate_null' ) , "'")";
	var i18n_enddate_null = "$encoder.jsEscape($i18n.getString( 'enddate_null' ) , "'")";
	var i18n_column_is_null = "$encoder.jsEscape($i18n.getString( 'column_is_null' ) , "'")";
	var i18n_confirm_delete = '$encoder.jsEscape($i18n.getString( 'confirm_delete' ) , "'")';
	var i18n_expression = '$encoder.jsEscape( $i18n.getString( "expression" ) , "'")';
	var periodColumnDialog = null;
	
</script>

<h3>$!encoder.htmlEncode($!exportReport.name)</h3>
<table width="100%">
<tr style="vertical-align:bottom;">
<td>
	$i18n.getString( "filter_by_name" ): <input type="text" onkeyup="filterValues(this.value, 1)" style="width:300px"/>	
</td>
<td align="right">		
	<input type="button" onclick="openAddPeriodColumn()" value="$i18n.getString('add')" style="width:150px"/><br>
	<input type="button" onclick="window.location='listAllExportReport.action'" value="$i18n.getString('cancel')" style="width:150px"/><br>	
</td>
</tr>
</table>
<table width="100%" id="listTable" class="listTable">
	<thead>
		<tr>		
			<th>$i18n.getString('start_date')</th>	
			<th>$i18n.getString('end_date')</th>	
			<th>$i18n.getString('period_type')</th>		
			<th>$i18n.getString('column')</th>
			<th width="70px" class="{sorter: false}">$i18n.getString('operations')</th>		
		</tr>
	</thead>
	<tbody id="list">
	#set( $mark = false )
	#foreach($periodColumn in $exportReport.periodColumns)
		<tr #alternate( $mark )>
			<td>$format.formatDate($periodColumn.startdate)</td>	
			<td>$format.formatDate($periodColumn.enddate)</td>			
			<td>$i18n.getString( $periodColumn.periodType )</td>			
			<td>$periodColumn.column</td>
			<td align="center">				
				<a href="javascript:deletePeriodColumn($exportReport.id, $periodColumn.id );" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"></a>
				<a href="javascript:openUpdatePeriodColumn( $periodColumn.id );" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
			</td>
		</tr>
		#if( $mark )
			#set( $mark = false )
		#else
			#set( $mark = true )
		#end
	#end
	</tbody>
</table>

<div id="periodColumn" style="padding:10px">	
<form id="periodColumnForm" method="POST">
<input type="hidden" id="action" value=""/>
<input type="hidden" name="id" id="id"/>
<input type="hidden" value="$!exportReport.id" name="exportReportId"/>
	<table width="100%">
		<tr>
			<td><label>$i18n.getString('period_type')<em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
			<td>
				<select type="text" id="periodType" name="periodType" style="min-width:20em">
					<option value='selected_month'>$i18n.getString('selected_month')</option>
					<option value='last_3_month'>$i18n.getString('last_3_month')</option>
					<option value='last_6_month'>$i18n.getString('last_6_month')</option>
					<option value='so_far_this_year'>$i18n.getString('so_far_this_year')</option>
					<option value='quaterly'>$i18n.getString('quaterly')</option>
					<option value='6_month'>$i18n.getString('six_monthly')</option>
					<option value='yealy'>$i18n.getString('yearly')</option>
				</select>
			</td>			
		</tr>
		<tr>
			<td>$i18n.getString('start_date')</td>
			<td>
				<input id="startdate" name="startdate" type="text" readonly="readonly" /><em title="$i18n.getString( 'required' )" class="required">*</em>				
			</td>				
		</tr>
		<tr>
			<td>$i18n.getString('end_date')</td>
			<td>
				<input id="enddate" name="enddate" type="text" readonly="readonly"/><em title="$i18n.getString( 'required' )" class="required">*</em>				
			</td>				
		</tr>
		<tr>
			<td>$i18n.getString('column')</td>
			<td>
				<input id="column" name="column" type="text" class="{validate:{required:true, number:true}}"/><em title="$i18n.getString( 'required' )" class="required">*</em>			
			</td>				
		</tr>
		<tr style="height:50px">
			<td></td>
			<td>
				<input type="submit" id="action" value="$i18n.getString('save')" style="width:100px"/>
				<input type="button" value="$i18n.getString('cancel')" style="width:100px" onclick="closeDialog( periodColumnDialog )"/>
			</td>
		</tr>		
	</table>
</form>
</div>

<script>
	
	// ---------------------------------------------------------------------------
	// Dialog
	// ---------------------------------------------------------------------------

	function setUpDialog( elementId, title, width, height )
	{
		var dialog = jQuery( '#'+elementId ).dialog({
			title: title,
			modal: true,
			autoOpen: false,
			minWidth: width,
			minHeight: height,
			width: width,
			height: height
		});
		
		return dialog;
	}

	function openDialog( _dialog )
	{
		_dialog.dialog( 'open' );
	}

	function closeDialog( _dialog )
	{
		_dialog.dialog( 'close' );
	}
	
	function openAddPeriodColumn()
	{
		setFieldValue( "action", "savePeriodColumn.action" );
		openDialog( periodColumnDialog );
	}
		
	function openUpdatePeriodColumn( id )
	{
		var request = new Request();
		request.setResponseTypeXML( 'xmlObject' );
		request.setCallbackSuccess( openUpdatePeriodColumnCompleted );
		request.send( "getPeriodColumn.action?id=" + id );	
	}

	function openUpdatePeriodColumnCompleted( xmlObject )
	{	
		
		var id = xmlObject.getElementsByTagName("id")[0].firstChild.nodeValue;	
		var startdate = xmlObject.getElementsByTagName("startdate")[0].firstChild.nodeValue;
		var enddate = xmlObject.getElementsByTagName("enddate")[0].firstChild.nodeValue;
		var periodType = xmlObject.getElementsByTagName("periodType")[0].firstChild.nodeValue;
		var column = xmlObject.getElementsByTagName("column")[0].firstChild.nodeValue;
		
		byId("startdate").value = startdate;
		byId("enddate").value = enddate;
		byId("periodType").value = periodType;
		byId("column").value = column;
		byId("id").value = id;

		setFieldValue('action', 'updatePeriodColumn.action' );
		
		openDialog( periodColumnDialog );
	}

	function deletePeriodColumn( exportReportId, periodColumnId )
	{
		if(window.confirm(i18n_confirm_delete)){
			window.location="deletePeriodColumn.action?exportReportId=" + exportReportId + "&id=" + periodColumnId;
		}	
	}
</script>
\ No newline at end of file
+<script>

	jQuery(document).ready(function(){
		datePickerInRange( 'startdate' , 'enddate' );	
		tableSorter( 'listTable' );
		
		validation( 'periodColumnForm', function( form ){ 
			form.action = getFieldValue('action');
			form.submit();
		});
		
		periodColumnDialog = setUpDialog( 'periodColumn', i18n_expression, 410, 210 );
	});
	
	var i18n_startdate_null = "$encoder.jsEscape($i18n.getString( 'startdate_null' ) , "'")";
	var i18n_enddate_null = "$encoder.jsEscape($i18n.getString( 'enddate_null' ) , "'")";
	var i18n_column_is_null = "$encoder.jsEscape($i18n.getString( 'column_is_null' ) , "'")";
	var i18n_confirm_delete = '$encoder.jsEscape($i18n.getString( 'confirm_delete' ) , "'")';
	var i18n_expression = '$encoder.jsEscape( $i18n.getString( "expression" ) , "'")';
	var periodColumnDialog = null;
</script>

<h3>$!encoder.htmlEncode($!exportReport.name)</h3>
<table width="100%">
<tr style="vertical-align:bottom;">
<td>
	$i18n.getString( "filter_by_name" ): <input type="text" onkeyup="filterValues(this.value, 1)" style="width:300px"/>	
</td>
<td align="right">		
	<input type="button" onclick="openAddPeriodColumn()" value="$i18n.getString('add')" style="width:150px"/><br>
	<input type="button" onclick="window.location='listAllExportReport.action'" value="$i18n.getString('cancel')" style="width:150px"/><br>	
</td>
</tr>
</table>
<table width="100%" id="listTable" class="listTable">
	<thead>
		<tr>		
			<th>$i18n.getString('start_date')</th>	
			<th>$i18n.getString('end_date')</th>	
			<th>$i18n.getString('period_type')</th>		
			<th>$i18n.getString('column')</th>
			<th width="70px" class="{sorter: false}">$i18n.getString('operations')</th>		
		</tr>
	</thead>
	<tbody id="list">
	#set( $mark = false )
	#foreach($periodColumn in $exportReport.periodColumns)
		<tr #alternate( $mark )>
			<td>$format.formatDate($periodColumn.startdate)</td>	
			<td>$format.formatDate($periodColumn.enddate)</td>			
			<td>$i18n.getString( $periodColumn.periodType )</td>			
			<td>$periodColumn.column</td>
			<td align="center">				
				<a href="javascript:deletePeriodColumn($exportReport.id, $periodColumn.id );" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"></a>
				<a href="javascript:openUpdatePeriodColumn( $periodColumn.id );" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
			</td>
		</tr>
		#if( $mark )
			#set( $mark = false )
		#else
			#set( $mark = true )
		#end
	#end
	</tbody>
</table>

<div id="periodColumn" style="padding:10px">	
<form id="periodColumnForm" method="POST">
<input type="hidden" id="action" value=""/>
<input type="hidden" name="id" id="id"/>
<input type="hidden" value="$!exportReport.id" name="exportReportId"/>
	<table width="100%">
		<tr>
			<td><label>$i18n.getString('period_type')<em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
			<td>
				<select type="text" id="periodType" name="periodType" style="min-width:20em">
					<option value='selected_month'>$i18n.getString('selected_month')</option>
					<option value='last_3_month'>$i18n.getString('last_3_month')</option>
					<option value='last_6_month'>$i18n.getString('last_6_month')</option>
					<option value='so_far_this_year'>$i18n.getString('so_far_this_year')</option>
					<option value='quaterly'>$i18n.getString('quaterly')</option>
					<option value='6_month'>$i18n.getString('six_monthly')</option>
					<option value='yealy'>$i18n.getString('yearly')</option>
				</select>
			</td>			
		</tr>
		<tr>
			<td>$i18n.getString('start_date')</td>
			<td>
				<input id="startdate" name="startdate" type="text" readonly="readonly" /><em title="$i18n.getString( 'required' )" class="required">*</em>				
			</td>				
		</tr>
		<tr>
			<td>$i18n.getString('end_date')</td>
			<td>
				<input id="enddate" name="enddate" type="text" readonly="readonly"/><em title="$i18n.getString( 'required' )" class="required">*</em>				
			</td>				
		</tr>
		<tr>
			<td>$i18n.getString('column')</td>
			<td>
				<input id="column" name="column" type="text" class="{validate:{required:true, number:true}}"/><em title="$i18n.getString( 'required' )" class="required">*</em>			
			</td>				
		</tr>
		<tr style="height:50px">
			<td></td>
			<td>
				<input type="submit" id="action" value="$i18n.getString('save')" style="width:100px"/>
				<input type="button" value="$i18n.getString('cancel')" style="width:100px" onclick="closeDialog( periodColumnDialog )"/>
			</td>
		</tr>		
	</table>
</form>
</div>

<script>
	
	// ---------------------------------------------------------------------------
	// Dialog
	// ---------------------------------------------------------------------------

	function setUpDialog( elementId, title, width, height )
	{
		var dialog = jQuery( '#'+elementId ).dialog({
			title: title,
			modal: true,
			autoOpen: false,
			minWidth: width,
			minHeight: height,
			width: width,
			height: height
		});
		
		return dialog;
	}

	function openDialog( _dialog )
	{
		_dialog.dialog( 'open' );
	}

	function closeDialog( _dialog )
	{
		_dialog.dialog( 'close' );
	}
	
	function openAddPeriodColumn()
	{
		setFieldValue( "action", "savePeriodColumn.action" );
		openDialog( periodColumnDialog );
	}
		
	function openUpdatePeriodColumn( id )
	{
		var request = new Request();
		request.setResponseTypeXML( 'xmlObject' );
		request.setCallbackSuccess( openUpdatePeriodColumnCompleted );
		request.send( "getPeriodColumn.action?id=" + id );	
	}

	function openUpdatePeriodColumnCompleted( xmlObject )
	{	
		
		var id = xmlObject.getElementsByTagName("id")[0].firstChild.nodeValue;	
		var startdate = xmlObject.getElementsByTagName("startdate")[0].firstChild.nodeValue;
		var enddate = xmlObject.getElementsByTagName("enddate")[0].firstChild.nodeValue;
		var periodType = xmlObject.getElementsByTagName("periodType")[0].firstChild.nodeValue;
		var column = xmlObject.getElementsByTagName("column")[0].firstChild.nodeValue;
		
		byId("startdate").value = startdate;
		byId("enddate").value = enddate;
		byId("periodType").value = periodType;
		byId("column").value = column;
		byId("id").value = id;

		setFieldValue('action', 'updatePeriodColumn.action' );
		
		openDialog( periodColumnDialog );
	}

	function deletePeriodColumn( exportReportId, periodColumnId )
	{
		if(window.confirm(i18n_confirm_delete)){
			window.location="deletePeriodColumn.action?exportReportId=" + exportReportId + "&id=" + periodColumnId;
		}	
	}
</script>
\ No newline at end of file

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/excelFormulaExpressionBuilderForm.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/excelFormulaExpressionBuilderForm.vm	2011-07-05 07:08:32 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/excelFormulaExpressionBuilderForm.vm	2011-07-08 07:52:59 +0000
@@ -12,16 +12,29 @@
 	<br/>
 	<br/>
 	<center>
-		<input type="button" value="$i18n.getString('ok')" onclick="updateExExpression()" style="width:100px"/>		
+		<input type="button" value="$i18n.getString('ok')" onclick="validateFormula()" style="width:100px"/>		
 		<input type="button" value="$i18n.getString('cancel')" onclick="closeDialog( excelFormulaDialog )" style="width:100px"/>
 	</center>
 </div>
 
-<script>
-	function updateExExpression()
+<script>		
+	
+	var expression = null;
+	
+	function validateFormula()
 	{
-		expression = jQuery( '#excelformula textarea[id=elementSelect]' ).val();		
-		closeDialog( excelFormulaDialog );
+		expression = getFieldValue( 'excelformula textarea[id=elementSelect]' );
+	
+		jQuery.postJSON('validationFormula.action',
+		{
+			formula: expression
+		},function( json ) {
+			if ( json.response == 'success' ) {
+				setFieldValue( 'expression', expression );
+				closeDialog( excelFormulaDialog );
+			}
+			else showErrorMessage( json.message );
+		});
 	}
 	
 	function excelFormulaExpressionBuilderForm()

=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/exportItems.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/exportItems.vm	2011-07-05 07:08:32 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/exportItems.vm	2011-07-08 07:52:59 +0000
@@ -43,11 +43,11 @@
 			</select>
 		</td>
 		<td align="right">		
-			<input type="button" onclick="window.location='addExportItemForm.action?exportReportId=$exportReport.id'" value="$i18n.getString('add')" style="width:150px"/><br/>
-			<input type="button" onclick="window.location='listAllExportReport.action'" value="$i18n.getString('cancel')" style="width:150px"/><br/>
-			<input type="button" onclick="copySelectedExportItemToExportReport()" value="$i18n.getString('copy_export_item_to_exportreport')" style="width:150px"/><br/>
-			<input type="button" onclick="copySelectedExportItemToImportReport()" value="$i18n.getString('copy_export_item_to_importreport')" style="width:150px"/><br/>
-			<input type="button" onclick="deleteMultiExportItem( '$i18n.getString( 'confirm_delete' )')" value="$i18n.getString('remove')" style="width:150px"/>
+			<input type="button" onclick="window.location='addExportItemForm.action?exportReportId=$exportReport.id'" value="$i18n.getString('add')" style="width:200px"/><br/>
+			<input type="button" onclick="window.location='listAllExportReport.action'" value="$i18n.getString('cancel')" style="width:200px"/><br/>
+			<input type="button" onclick="copySelectedExportItemToExportReport()" value="$i18n.getString('copy_export_item_to_exportreport')" style="width:200px"/><br/>
+			<input type="button" onclick="copySelectedExportItemToImportReport()" value="$i18n.getString('copy_export_item_to_importreport')" style="width:200px"/><br/>
+			<input type="button" onclick="deleteMultiExportItem( '$i18n.getString( 'confirm_delete' )')" value="$i18n.getString('remove_item')" style="width:200px"/>
 		</td>
 	</tr>
 </table>