=== 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 orgUniGroupAtLevels = new HashMap( @@ -106,7 +107,7 @@ // ------------------------------------------------------------------------- // Supportive method // ------------------------------------------------------------------------- - + private void generateOutPutFile( ReportExcelOganiztionGroupListing exportReport, Map orgUniGroupAtLevels, Collection 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"> + + plainTextError + + + /dhis-web-commons/ajax/jsonResponseSuccess.vm + + /dhis-web-commons/ajax/jsonResponseError.vm + plainTextError + + /main.vm === 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" ): -
-
- +
+
+ === 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 @@ -

$!encoder.htmlEncode($!exportReport.name)

$i18n.getString( "filter_by_name" ):

#set( $mark = false ) #foreach($periodColumn in $exportReport.periodColumns) #if( $mark ) #set( $mark = false ) #else #set( $mark = true ) #end #end
$i18n.getString('start_date') $i18n.getString('end_date') $i18n.getString('period_type') $i18n.getString('column') $i18n.getString('operations')
$format.formatDate($periodColumn.startdate) $format.formatDate($periodColumn.enddate) $i18n.getString( $periodColumn.periodType ) $periodColumn.column $i18n.getString( 'remove' ) $i18n.getString( 'edit' )
$i18n.getString('start_date') *
$i18n.getString('end_date') *
$i18n.getString('column') *
\ No newline at end of file +

$!encoder.htmlEncode($!exportReport.name)

$i18n.getString( "filter_by_name" ):

#set( $mark = false ) #foreach($periodColumn in $exportReport.periodColumns) #if( $mark ) #set( $mark = false ) #else #set( $mark = true ) #end #end
$i18n.getString('start_date') $i18n.getString('end_date') $i18n.getString('period_type') $i18n.getString('column') $i18n.getString('operations')
$format.formatDate($periodColumn.startdate) $format.formatDate($periodColumn.enddate) $i18n.getString( $periodColumn.periodType ) $periodColumn.column $i18n.getString( 'remove' ) $i18n.getString( 'edit' )
$i18n.getString('start_date') *
$i18n.getString('end_date') *
$i18n.getString('column') *
\ 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 @@

- +
-