=== modified file 'local/vn/dhis-service-excel-reporting/src/main/resources/META-INF/dhis/beans.xml' --- local/vn/dhis-service-excel-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-05-26 05:00:59 +0000 +++ local/vn/dhis-service-excel-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-06-07 05:41:55 +0000 @@ -34,8 +34,7 @@ ref="org.hisp.dhis.reportexcel.importitem.ImportItemStore" /> - - + reportTypes = new ArrayList(); + private Map mapTemplateFiles = new HashMap(); - private List reportTypes = new ArrayList(); - // ------------------------------------------------------------------------- // Getter && Setter // ------------------------------------------------------------------------- + public void setId( Integer id ) + { + this.id = id; + } + + public ReportExcel getExportReport() + { + return exportReport; + } + public Map getMapTemplateFiles() { return mapTemplateFiles; @@ -149,6 +163,17 @@ public String execute() throws Exception { + if ( id != null ) + { + selectionManager.setSelectedReportId( id ); + + exportReport = exportReportService.getExportReport( id ); + } + else + { + return ERROR; + } + File templateDirectory = reportLocationManager.getReportExcelTemplateDirectory(); if ( templateDirectory == null || !templateDirectory.exists() ) === added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/ImportDataGeneric.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/ImportDataGeneric.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/ImportDataGeneric.java 2011-06-07 05:41:55 +0000 @@ -0,0 +1,171 @@ +package org.hisp.dhis.reportexcel.importing; + +/* + * 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 java.io.FileInputStream; + +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; +import org.hisp.dhis.dataelement.DataElementCategoryService; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.expression.ExpressionService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.reportexcel.action.ActionSupport; +import org.hisp.dhis.reportexcel.importitem.ImportItemService; +import org.hisp.dhis.reportexcel.period.generic.PeriodGenericManager; +import org.hisp.dhis.reportexcel.state.SelectionManager; +import org.hisp.dhis.user.CurrentUserService; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public abstract class ImportDataGeneric + extends ActionSupport +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + protected CurrentUserService currentUserService; + + public void setCurrentUserService( CurrentUserService currentUserService ) + { + this.currentUserService = currentUserService; + } + + protected DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + protected DataElementCategoryService categoryService; + + public void setCategoryService( DataElementCategoryService categoryService ) + { + this.categoryService = categoryService; + } + + protected DataValueService dataValueService; + + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + protected ExpressionService expressionService; + + public void setExpressionService( ExpressionService expressionService ) + { + this.expressionService = expressionService; + } + + protected ImportItemService importItemService; + + public void setImportItemService( ImportItemService importItemService ) + { + this.importItemService = importItemService; + } + + protected OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + protected OrganisationUnitSelectionManager organisationUnitSelectionManager; + + public void setOrganisationUnitSelectionManager( OrganisationUnitSelectionManager organisationUnitSelectionManager ) + { + this.organisationUnitSelectionManager = organisationUnitSelectionManager; + } + + protected PeriodGenericManager periodGenericManager; + + public void setPeriodGenericManager( PeriodGenericManager periodGenericManager ) + { + this.periodGenericManager = periodGenericManager; + } + + protected SelectionManager selectionManager; + + public void setSelectionManager( SelectionManager selectionManager ) + { + this.selectionManager = selectionManager; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + String[] importItemIds = selectionManager.getListObject(); + + if ( importItemIds == null ) + { + message = i18n.getString( "choose_import_item" ); + + return ERROR; + } + + OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); + + if ( organisationUnit != null ) + { + FileInputStream inputStream = new FileInputStream( selectionManager.getUploadFilePath() ); + + Workbook wb = new HSSFWorkbook( inputStream ); + + Period period = periodGenericManager.getSelectedPeriod(); + + executeToImport( organisationUnit, period, importItemIds, wb ); + } + + message = i18n.getString( "import_successfully" ); + + return SUCCESS; + } + + // ------------------------------------------------------------------------- + // Abstract method + // ------------------------------------------------------------------------- + + public abstract void executeToImport( OrganisationUnit organisationUnit, Period period, String[] importItemIds, + Workbook wb ); + +} === added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryAction.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryAction.java 2011-06-07 05:41:55 +0000 @@ -0,0 +1,104 @@ +package org.hisp.dhis.reportexcel.importing.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 java.util.Date; + +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.DataElementOperand; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.reportexcel.importing.ImportDataGeneric; +import org.hisp.dhis.reportexcel.importitem.ExcelItem; +import org.hisp.dhis.reportexcel.utils.ExcelUtils; + +/** + * @author Chau Thu Tran + * @version $Id$ + */ + +public class ImportDataCategoryAction + extends ImportDataGeneric +{ + // ------------------------------------------------------------------------- + // Override the abstract method + // ------------------------------------------------------------------------- + + public void executeToImport( OrganisationUnit organisationUnit, Period period, String[] importItemIds, Workbook wb ) + { + for ( int i = 0; i < importItemIds.length; i++ ) + { + int importItemId = Integer.parseInt( importItemIds[i].split( "-" )[0] ); + + int rowIndex = Integer.parseInt( importItemIds[i].split( "-" )[1] ); + + String expression = importItemIds[i].split( "-" )[2]; + + ExcelItem importItem = importItemService.getImportItem( importItemId ); + + Sheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); + + String value = ExcelUtils.readValueImportingByPOI( rowIndex, importItem.getColumn(), sheet ); + + addDataValue( expression, value, organisationUnit, period ); + } + } + + private void addDataValue( String expression, String value, OrganisationUnit organisationUnit, Period period ) + { + DataElementOperand operand = expressionService.getOperandsInExpression( expression ).iterator().next(); + + DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); + + DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( operand + .getOptionComboId() ); + + String storedBy = currentUserService.getCurrentUsername(); + + DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, period, optionCombo ); + + if ( dataValue == null ) + { + dataValue = new DataValue( dataElement, period, organisationUnit, value + "", storedBy, new Date(), null, + optionCombo ); + dataValueService.addDataValue( dataValue ); + } + else + { + dataValue.setValue( value + "" ); + dataValue.setTimestamp( new Date() ); + dataValue.setStoredBy( storedBy ); + + dataValueService.updateDataValue( dataValue ); + } + } +} \ No newline at end of file === removed file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryExcelGroupAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryExcelGroupAction.java 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryExcelGroupAction.java 1970-01-01 00:00:00 +0000 @@ -1,216 +0,0 @@ -package org.hisp.dhis.reportexcel.importing.action; - -/* - * Copyright (c) 2004-2010, 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 java.io.FileInputStream; -import java.util.Date; - -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementOperand; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.expression.ExpressionService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.reportexcel.action.ActionSupport; -import org.hisp.dhis.reportexcel.importitem.ExcelItem; -import org.hisp.dhis.reportexcel.importitem.ImportItemService; -import org.hisp.dhis.reportexcel.period.generic.PeriodGenericManager; -import org.hisp.dhis.reportexcel.state.SelectionManager; -import org.hisp.dhis.reportexcel.utils.ExcelUtils; -import org.hisp.dhis.user.CurrentUserService; - -/** - * @author Chau Thu Tran - * @version $Id$ - */ - -public class ImportDataCategoryExcelGroupAction - extends ActionSupport -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private CurrentUserService currentUserService; - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - - private DataElementService dataElementService; - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private DataElementCategoryService categoryService; - - public void setCategoryService( DataElementCategoryService categoryService ) - { - this.categoryService = categoryService; - } - - private ExpressionService expressionService; - - public void setExpressionService( ExpressionService expressionService ) - { - this.expressionService = expressionService; - } - - private ImportItemService importItemService; - - public void setImportItemService( ImportItemService importItemService ) - { - this.importItemService = importItemService; - } - - private OrganisationUnitSelectionManager organisationUnitSelectionManager; - - public void setOrganisationUnitSelectionManager( OrganisationUnitSelectionManager organisationUnitSelectionManager ) - { - this.organisationUnitSelectionManager = organisationUnitSelectionManager; - } - - private PeriodGenericManager periodGenericManager; - - public void setPeriodGenericManager( PeriodGenericManager periodGenericManager ) - { - this.periodGenericManager = periodGenericManager; - } - - private SelectionManager selectionManager; - - public void setSelectionManager( SelectionManager selectionManager ) - { - this.selectionManager = selectionManager; - } - - // ------------------------------------------------------------------------- - // Inputs && Outputs - // ------------------------------------------------------------------------- - - public String[] importItemIds; - - public void setExcelItemIds( String[] importItemIds ) - { - this.importItemIds = importItemIds; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - - if ( importItemIds == null ) - { - message = i18n.getString( "choose_excelItem" ); - - return ERROR; - } - - if ( organisationUnit != null ) - { - FileInputStream upload = new FileInputStream( selectionManager.getUploadFilePath() ); - - HSSFWorkbook wb = new HSSFWorkbook( upload ); - - Period period = periodGenericManager.getSelectedPeriod(); - - for ( int i = 0; i < importItemIds.length; i++ ) - { - int importItemId = Integer.parseInt( importItemIds[i].split( "-" )[0] ); - - int rowIndex = Integer.parseInt( importItemIds[i].split( "-" )[1] ); - - String expression = importItemIds[i].split( "-" )[2]; - - ExcelItem importItem = importItemService.getImportItem( importItemId ); - - HSSFSheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); - - String value = ExcelUtils.readValueImportingByPOI( rowIndex, importItem.getColumn(), sheet ); - - addDataValue( expression, value, organisationUnit, period ); - } - - }// end if (organisationUnit ... - - message = i18n.getString( "success" ); - - return SUCCESS; - } - - private void addDataValue( String expression, String value, OrganisationUnit organisationUnit, Period period ) - { - DataElementOperand operand = expressionService.getOperandsInExpression( expression ).iterator().next(); - - DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); - - DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( operand - .getOptionComboId() ); - - String storedBy = currentUserService.getCurrentUsername(); - - DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, period, optionCombo ); - - if ( dataValue == null ) - { - dataValue = new DataValue( dataElement, period, organisationUnit, value + "", storedBy, new Date(), null, - optionCombo ); - dataValueService.addDataValue( dataValue ); - } - else - { - dataValue.setValue( value + "" ); - dataValue.setTimestamp( new Date() ); - dataValue.setStoredBy( storedBy ); - - dataValueService.updateDataValue( dataValue ); - } - } -} \ No newline at end of file === removed file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataExcelOrganizationGroupAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataExcelOrganizationGroupAction.java 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataExcelOrganizationGroupAction.java 1970-01-01 00:00:00 +0000 @@ -1,234 +0,0 @@ -package org.hisp.dhis.reportexcel.importing.action; - -/* - * Copyright (c) 2004-2010, 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 java.io.FileInputStream; -import java.util.Date; - -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementOperand; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.expression.ExpressionService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.reportexcel.action.ActionSupport; -import org.hisp.dhis.reportexcel.importitem.ExcelItem; -import org.hisp.dhis.reportexcel.importitem.ImportItemService; -import org.hisp.dhis.reportexcel.period.generic.PeriodGenericManager; -import org.hisp.dhis.reportexcel.state.SelectionManager; -import org.hisp.dhis.reportexcel.utils.ExcelUtils; -import org.hisp.dhis.user.CurrentUserService; - -/** - * @author Chau Thu Tran - * @version $Id$ - */ - -public class ImportDataExcelOrganizationGroupAction - extends ActionSupport -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private CurrentUserService currentUserService; - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - - private DataElementService dataElementService; - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - - private DataElementCategoryService categoryService; - - public void setCategoryService( DataElementCategoryService categoryService ) - { - this.categoryService = categoryService; - } - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private ExpressionService expressionService; - - public void setExpressionService( ExpressionService expressionService ) - { - this.expressionService = expressionService; - } - - private ImportItemService importItemService; - - public void setImportItemService( ImportItemService importItemService ) - { - this.importItemService = importItemService; - } - - private OrganisationUnitService organisationUnitService; - - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) - { - this.organisationUnitService = organisationUnitService; - } - - private OrganisationUnitSelectionManager organisationUnitSelectionManager; - - public void setOrganisationUnitSelectionManager( OrganisationUnitSelectionManager organisationUnitSelectionManager ) - { - this.organisationUnitSelectionManager = organisationUnitSelectionManager; - } - - private PeriodGenericManager periodGenericManager; - - public void setPeriodGenericManager( PeriodGenericManager periodGenericManager ) - { - this.periodGenericManager = periodGenericManager; - } - - private SelectionManager selectionManager; - - public void setSelectionManager( SelectionManager selectionManager ) - { - this.selectionManager = selectionManager; - } - - // ------------------------------------------------------------------------- - // Inputs && Outputs - // ------------------------------------------------------------------------- - - public String[] importItemIds; - - public void setExcelItemIds( String[] importItemIds ) - { - this.importItemIds = importItemIds; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - - if ( importItemIds == null ) - { - message = i18n.getString( "choose_import_item" ); - - return ERROR; - } - - if ( organisationUnit != null ) - { - FileInputStream inputStream = new FileInputStream( selectionManager.getUploadFilePath() ); - - HSSFWorkbook wb = new HSSFWorkbook( inputStream ); - - Period period = periodGenericManager.getSelectedPeriod(); - - for ( int i = 0; i < importItemIds.length; i++ ) - { - int orgunitId = Integer.parseInt( importItemIds[i].split( "-" )[0] ); - - OrganisationUnit o = organisationUnitService.getOrganisationUnit( orgunitId ); - - int row = Integer.parseInt( importItemIds[i].split( "-" )[1] ); - - int importItemId = Integer.parseInt( importItemIds[i].split( "-" )[2] ); - - ExcelItem importItem = importItemService.getImportItem( importItemId ); - - if ( importItem.getId() == importItemId ) - { - writeDataValue( importItem, wb, row, o, period ); - }// end if( importItem ... - - }// end for (int i ... - - }// end if (organisationUnit ... - - message = i18n.getString( "success" ); - - return SUCCESS; - } - - private void writeDataValue( ExcelItem importItem, HSSFWorkbook wb, int row, OrganisationUnit o, Period period ) - { - HSSFSheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); - - String value = ExcelUtils.readValueImportingByPOI( importItem.getRow() + row, importItem.getColumn(), sheet ); - - if ( value.length() > 0 ) - { - DataElementOperand operand = expressionService.getOperandsInExpression( importItem.getExpression() ) - .iterator().next(); - - DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); - - DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( operand - .getOptionComboId() ); - - String storedBy = currentUserService.getCurrentUsername(); - - DataValue dataValue = dataValueService.getDataValue( o, dataElement, period, optionCombo ); - - if ( dataValue == null ) - { - dataValue = new DataValue( dataElement, period, o, value + "", storedBy, new Date(), null, optionCombo ); - dataValueService.addDataValue( dataValue ); - } - else - { - dataValue.setValue( value + "" ); - dataValue.setTimestamp( new Date() ); - dataValue.setStoredBy( storedBy ); - - dataValueService.updateDataValue( dataValue ); - } - } - } - -} === 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 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataFlowAction.java 2011-06-07 05:41:55 +0000 @@ -30,6 +30,7 @@ import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; import org.hisp.dhis.reportexcel.importitem.ImportItemService; import org.hisp.dhis.reportexcel.period.generic.PeriodGenericManager; +import org.hisp.dhis.reportexcel.state.SelectionManager; import com.opensymphony.xwork2.Action; @@ -58,6 +59,13 @@ this.periodGenericManager = periodGenericManager; } + private SelectionManager selectionManager; + + public void setSelectionManager( SelectionManager selectionManager ) + { + this.selectionManager = selectionManager; + } + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -70,10 +78,17 @@ private Integer orgunitGroupId; + public String[] importItemIds; + // ------------------------------------------------------------------------- // Getter & Setter // ------------------------------------------------------------------------- + public Integer getImportReportId() + { + return importReportId; + } + public void setImportReportId( Integer importReportId ) { this.importReportId = importReportId; @@ -104,6 +119,11 @@ this.orgunitGroupId = orgunitGroupId; } + public void setImportItemIds( String[] importItemIds ) + { + this.importItemIds = importItemIds; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -113,6 +133,8 @@ { periodGenericManager.setSelectedPeriodIndex( periodId ); + selectionManager.setListObject( importItemIds ); + ExcelItemGroup importReport = importItemService.getImportReport( importReportId ); return importReport.getType(); === added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalAction.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalAction.java 2011-06-07 05:41:55 +0000 @@ -0,0 +1,122 @@ +package org.hisp.dhis.reportexcel.importing.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 java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.DataElementOperand; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.reportexcel.importing.ImportDataGeneric; +import org.hisp.dhis.reportexcel.importitem.ExcelItem; +import org.hisp.dhis.reportexcel.utils.ExcelUtils; + +/** + * @author Chau Thu Tran + * @version $Id$ + */ + +public class ImportDataNormalAction + extends ImportDataGeneric +{ + // ------------------------------------------------------------------------- + // Inputs && Outputs + // ------------------------------------------------------------------------- + + private Integer importReportId; + + public void setImportReportId( Integer importReportId ) + { + this.importReportId = importReportId; + } + + // ------------------------------------------------------------------------- + // Override the abstract method + // ------------------------------------------------------------------------- + + public void executeToImport( OrganisationUnit organisationUnit, Period period, String[] importItemIds, Workbook wb ) + { + Collection importItems = new ArrayList(); + + if ( importItemIds != null ) + { + for ( int i = 0; i < importItemIds.length; i++ ) + { + importItems.add( importItemService.getImportItem( importItemIds[i] ) ); + } + } + else + { + importItems = importItemService.getImportReport( importReportId ).getExcelItems(); + } + + for ( ExcelItem importItem : importItems ) + { + Sheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); + + String value = ExcelUtils.readValueImportingByPOI( importItem.getRow(), importItem.getColumn(), sheet ); + + if ( value.length() > 0 ) + { + DataElementOperand operand = expressionService.getOperandsInExpression( importItem.getExpression() ) + .iterator().next(); + + DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); + + DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( operand + .getOptionComboId() ); + + String storedBy = currentUserService.getCurrentUsername(); + + DataValue dataValue = dataValueService + .getDataValue( organisationUnit, dataElement, period, optionCombo ); + + if ( dataValue == null ) + { + dataValue = new DataValue( dataElement, period, organisationUnit, value + "", storedBy, new Date(), + null, optionCombo ); + dataValueService.addDataValue( dataValue ); + } + else + { + dataValue.setValue( value + "" ); + dataValue.setTimestamp( new Date() ); + dataValue.setStoredBy( storedBy ); + dataValueService.updateDataValue( dataValue ); + } + } + } + } +} \ No newline at end of file === removed 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 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java 1970-01-01 00:00:00 +0000 @@ -1,238 +0,0 @@ -package org.hisp.dhis.reportexcel.importing.action; - -/* - * Copyright (c) 2004-2010, 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 java.io.FileInputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; - -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementOperand; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.expression.ExpressionService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.reportexcel.action.ActionSupport; -import org.hisp.dhis.reportexcel.importitem.ExcelItem; -import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; -import org.hisp.dhis.reportexcel.importitem.ImportItemService; -import org.hisp.dhis.reportexcel.period.generic.PeriodGenericManager; -import org.hisp.dhis.reportexcel.state.SelectionManager; -import org.hisp.dhis.reportexcel.utils.ExcelUtils; -import org.hisp.dhis.user.CurrentUserService; - -/** - * @author Chau Thu Tran - * @version $Id$ - */ - -public class ImportDataNormalExcelGroupAction - extends ActionSupport -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataValueService dataValueService; - - private OrganisationUnitSelectionManager organisationUnitSelectionManager; - - private ExpressionService expressionService; - - private DataElementService dataElementService; - - private DataElementCategoryService categoryService; - - private CurrentUserService currentUserService; - - private ImportItemService importItemService; - - private SelectionManager selectionManager; - - private PeriodGenericManager periodGenericManager; - - // ------------------------------------------------------------------------- - // Inputs && Outputs - // ------------------------------------------------------------------------- - - private Integer importReportId; - - public Integer[] importItemIds; - - // ------------------------------------------------------------------------- - // Getters and Setters - // ------------------------------------------------------------------------- - - public void setOrganisationUnitSelectionManager( OrganisationUnitSelectionManager organisationUnitSelectionManager ) - { - this.organisationUnitSelectionManager = organisationUnitSelectionManager; - } - - public void setSelectionManager( SelectionManager selectionManager ) - { - this.selectionManager = selectionManager; - } - - public void setPeriodGenericManager( PeriodGenericManager periodGenericManager ) - { - this.periodGenericManager = periodGenericManager; - } - - public void setExpressionService( ExpressionService expressionService ) - { - this.expressionService = expressionService; - } - - public void setCategoryService( DataElementCategoryService categoryService ) - { - this.categoryService = categoryService; - } - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - - public void setImportItemService( ImportItemService importItemService ) - { - this.importItemService = importItemService; - } - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - public void setImportReportId( Integer importReportId ) - { - this.importReportId = importReportId; - } - - public void setExcelItemIds( Integer[] importItemIds ) - { - this.importItemIds = importItemIds; - } - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - ExcelItemGroup importItemGroup = importItemService.getImportReport( importReportId.intValue() ); - - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - - if ( importItemIds == null ) - { - message = i18n.getString( "choose_importItem" ); - - return ERROR; - } - - if ( organisationUnit != null ) - { - FileInputStream upload = new FileInputStream( selectionManager.getUploadFilePath() ); - - HSSFWorkbook wb = new HSSFWorkbook( upload ); - - Collection importItems = new ArrayList(); - - if ( importItemIds != null ) - { - for ( int i = 0; i < importItemIds.length; i++ ) - { - importItems.add( importItemService.getImportItem( importItemIds[i] ) ); - } - } - else - { - importItems = importItemGroup.getExcelItems(); - } - - Period period = periodGenericManager.getSelectedPeriod(); - - for ( ExcelItem importItem : importItems ) - { - HSSFSheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); - - String value = ExcelUtils.readValueImportingByPOI( importItem.getRow(), importItem.getColumn(), sheet ); - - if ( value.length() > 0 ) - { - DataElementOperand operand = expressionService.getOperandsInExpression( importItem.getExpression() ).iterator() - .next(); - - DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); - - DataElementCategoryOptionCombo optionCombo = categoryService - .getDataElementCategoryOptionCombo( operand.getOptionComboId() ); - - String storedBy = currentUserService.getCurrentUsername(); - - DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, period, - optionCombo ); - - if ( dataValue == null ) - { - dataValue = new DataValue( dataElement, period, organisationUnit, value + "", storedBy, - new Date(), null, optionCombo ); - dataValueService.addDataValue( dataValue ); - } - else - { - dataValue.setValue( value + "" ); - dataValue.setTimestamp( new Date() ); - dataValue.setStoredBy( storedBy ); - dataValueService.updateDataValue( dataValue ); - } - } - }// end for (ImportItem ... - - }// end if (organisationUnit ... - - message = i18n.getString( "success" ); - - return SUCCESS; - } - -} \ No newline at end of file === added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataOrganizationGroupAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataOrganizationGroupAction.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataOrganizationGroupAction.java 2011-06-07 05:41:55 +0000 @@ -0,0 +1,113 @@ +package org.hisp.dhis.reportexcel.importing.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 java.util.Date; + +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.DataElementOperand; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.reportexcel.importing.ImportDataGeneric; +import org.hisp.dhis.reportexcel.importitem.ExcelItem; +import org.hisp.dhis.reportexcel.utils.ExcelUtils; + +/** + * @author Chau Thu Tran + * @version $Id$ + */ + +public class ImportDataOrganizationGroupAction + extends ImportDataGeneric +{ + // ------------------------------------------------------------------------- + // Override the abstract method + // ------------------------------------------------------------------------- + + @Override + public void executeToImport( OrganisationUnit organisationUnit, Period period, String[] importItemIds, Workbook wb ) + { + for ( int i = 0; i < importItemIds.length; i++ ) + { + int orgunitId = Integer.parseInt( importItemIds[i].split( "-" )[0] ); + + OrganisationUnit o = organisationUnitService.getOrganisationUnit( orgunitId ); + + int row = Integer.parseInt( importItemIds[i].split( "-" )[1] ); + + int importItemId = Integer.parseInt( importItemIds[i].split( "-" )[2] ); + + ExcelItem importItem = importItemService.getImportItem( importItemId ); + + if ( importItem.getId() == importItemId ) + { + writeDataValue( importItem, wb, row, o, period ); + } + } + } + + private void writeDataValue( ExcelItem importItem, Workbook wb, int row, OrganisationUnit o, Period period ) + { + Sheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); + + String value = ExcelUtils.readValueImportingByPOI( importItem.getRow() + row, importItem.getColumn(), sheet ); + + if ( value.length() > 0 ) + { + DataElementOperand operand = expressionService.getOperandsInExpression( importItem.getExpression() ) + .iterator().next(); + + DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); + + DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( operand + .getOptionComboId() ); + + String storedBy = currentUserService.getCurrentUsername(); + + DataValue dataValue = dataValueService.getDataValue( o, dataElement, period, optionCombo ); + + if ( dataValue == null ) + { + dataValue = new DataValue( dataElement, period, o, value + "", storedBy, new Date(), null, optionCombo ); + dataValueService.addDataValue( dataValue ); + } + else + { + dataValue.setValue( value + "" ); + dataValue.setTimestamp( new Date() ); + dataValue.setStoredBy( storedBy ); + + dataValueService.updateDataValue( dataValue ); + } + } + } +} === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataCategoryAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataCategoryAction.java 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataCategoryAction.java 2011-06-07 05:41:55 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.reportexcel.importing.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 @@ -31,15 +31,20 @@ import java.io.FileInputStream; import java.util.ArrayList; import java.util.Collections; +import java.util.List; -import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.reportexcel.DataElementGroupOrder; import org.hisp.dhis.reportexcel.importing.ImportItemValue; import org.hisp.dhis.reportexcel.importitem.ExcelItem; import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; +import org.hisp.dhis.reportexcel.importitem.ImportItemService; import org.hisp.dhis.reportexcel.importitem.comparator.ImportItemComparator; +import org.hisp.dhis.reportexcel.state.SelectionManager; import org.hisp.dhis.reportexcel.utils.ExcelUtils; import com.opensymphony.xwork2.Action; @@ -53,41 +58,52 @@ implements Action { // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private ImportItemService importItemService; + + public void setImportItemService( ImportItemService importItemService ) + { + this.importItemService = importItemService; + } + + private SelectionManager selectionManager; + + public void setSelectionManager( SelectionManager selectionManager ) + { + this.selectionManager = selectionManager; + } + + // ------------------------------------------------------------------------- // Inputs && Outputs // ------------------------------------------------------------------------- - private ExcelItemGroup importReport; - - private ArrayList importItemValues; - - private File upload; - - public String[] importItemIds; + private List importItemValues = new ArrayList(); + + private String message; + + private I18n i18n; // ------------------------------------------------------------------------- // Getters and Setters // ------------------------------------------------------------------------- - public void setUpload( File upload ) - { - this.upload = upload; - } - - public void setImportReport( ExcelItemGroup importReport ) - { - this.importReport = importReport; - } - - public void setImportItemIds( String[] importItemIds ) - { - this.importItemIds = importItemIds; - } - - public ArrayList getImportItemValues() + public List getImportItemValues() { return importItemValues; } + public String getMessage() + { + return message; + } + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -96,19 +112,26 @@ { try { - FileInputStream inputStream = new FileInputStream( upload ); - - HSSFWorkbook wb = new HSSFWorkbook( inputStream ); - - ArrayList importItems = new ArrayList( importReport.getExcelItems() ); + FileInputStream inputStream = new FileInputStream( new File( selectionManager.getUploadFilePath() ) ); + + Workbook wb = new HSSFWorkbook( inputStream ); + + ExcelItemGroup importReport = importItemService.getImportReport( selectionManager.getSelectedReportId() ); + + List importItems = new ArrayList( importReport.getExcelItems() ); + + if ( importItems == null || importItems.isEmpty() ) + { + message = i18n.getString( "import_excel_items_cannot_be_empty" ); + + return ERROR; + } Collections.sort( importItems, new ImportItemComparator() ); - importItemValues = new ArrayList(); - for ( ExcelItem importItem : importItems ) { - HSSFSheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); + Sheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); int rowBegin = importItem.getRow(); === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataFlowAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataFlowAction.java 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataFlowAction.java 2011-06-07 05:41:55 +0000 @@ -1,5 +1,5 @@ /* - * 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 @@ -26,14 +26,8 @@ */ package org.hisp.dhis.reportexcel.importing.action; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; - -import org.hisp.dhis.reportexcel.importitem.ExcelItem; import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; import org.hisp.dhis.reportexcel.importitem.ImportItemService; -import org.hisp.dhis.reportexcel.importitem.comparator.ImportItemComparator; import org.hisp.dhis.reportexcel.state.SelectionManager; import com.opensymphony.xwork2.Action; @@ -70,36 +64,11 @@ private Integer importReportId; - private ExcelItemGroup importReport; - - private ArrayList importItems; - - private File upload; - - // ------------------------------------------------------------------------- - // Getters and Setters - // ------------------------------------------------------------------------- - - public File getUpload() - { - return upload; - } - - public ExcelItemGroup getImportReport() - { - return importReport; - } - public void setImportReportId( Integer importReportId ) { this.importReportId = importReportId; } - public ArrayList getImportItems() - { - return importItems; - } - // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -108,12 +77,9 @@ public String execute() throws Exception { - upload = new File( selectionManager.getUploadFilePath() ); - - importReport = importItemService.getImportReport( importReportId ); - importItems = new ArrayList( importReport.getExcelItems() ); - - Collections.sort( importItems, new ImportItemComparator() ); + selectionManager.setSelectedReportId( importReportId ); + + ExcelItemGroup importReport = importItemService.getImportReport( importReportId ); return importReport.getType(); } === 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-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java 2011-06-07 05:41:55 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.reportexcel.importing.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 @@ -30,6 +30,7 @@ import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -38,6 +39,10 @@ import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.reportexcel.importing.ImportItemValue; import org.hisp.dhis.reportexcel.importitem.ExcelItem; +import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; +import org.hisp.dhis.reportexcel.importitem.ImportItemService; +import org.hisp.dhis.reportexcel.importitem.comparator.ImportItemComparator; +import org.hisp.dhis.reportexcel.state.SelectionManager; import org.hisp.dhis.reportexcel.utils.ExcelUtils; import com.opensymphony.xwork2.Action; @@ -52,33 +57,37 @@ implements Action { // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private ImportItemService importItemService; + + public void setImportItemService( ImportItemService importItemService ) + { + this.importItemService = importItemService; + } + + private SelectionManager selectionManager; + + public void setSelectionManager( SelectionManager selectionManager ) + { + this.selectionManager = selectionManager; + } + + // ------------------------------------------------------------------------- // Inputs && Outputs // ------------------------------------------------------------------------- - private File upload; - - private List importItemValues; - - private ArrayList importItems; - + private List importItemValues = new ArrayList(); + private String message; - + private I18n i18n; // ------------------------------------------------------------------------- // Getters and Setters // ------------------------------------------------------------------------- - public void setUpload( File upload ) - { - this.upload = upload; - } - - public void setImportItems( ArrayList importItems ) - { - this.importItems = importItems; - } - public List getImportItemValues() { return importItemValues; @@ -93,7 +102,7 @@ { this.i18n = i18n; } - + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -102,18 +111,22 @@ { try { - FileInputStream inputStream = new FileInputStream( upload ); + FileInputStream inputStream = new FileInputStream( new File( selectionManager.getUploadFilePath() ) ); Workbook wb = new HSSFWorkbook( inputStream ); - importItemValues = new ArrayList(); + ExcelItemGroup importReport = importItemService.getImportReport( selectionManager.getSelectedReportId() ); + + List importItems = new ArrayList( importReport.getExcelItems() ); if ( importItems == null || importItems.isEmpty() ) { message = i18n.getString( "import_excel_items_cannot_be_empty" ); - + return ERROR; } + + Collections.sort( importItems, new ImportItemComparator() ); for ( ExcelItem importItem : importItems ) { @@ -131,7 +144,7 @@ } catch ( Exception ex ) { - throw new RuntimeException("Error while previewing the imported value", ex); + throw new RuntimeException( "Error while previewing the imported value", ex ); } } } === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataOrganizationGroupAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataOrganizationGroupAction.java 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataOrganizationGroupAction.java 2011-06-07 05:41:55 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.reportexcel.importing.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 @@ -34,8 +34,10 @@ import java.util.Collections; import java.util.List; -import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitGroup; import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; @@ -44,6 +46,9 @@ import org.hisp.dhis.reportexcel.importing.ImportItemValueByOrganisationUnit; import org.hisp.dhis.reportexcel.importitem.ExcelItem; import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; +import org.hisp.dhis.reportexcel.importitem.ImportItemService; +import org.hisp.dhis.reportexcel.importitem.comparator.ImportItemComparator; +import org.hisp.dhis.reportexcel.state.SelectionManager; import org.hisp.dhis.reportexcel.utils.ExcelUtils; import com.opensymphony.xwork2.Action; @@ -56,10 +61,23 @@ public class ViewDataOrganizationGroupAction implements Action { - - // -------------------------------------------------------------------- + // ------------------------------------------------------------------------- // Dependency - // -------------------------------------------------------------------- + // ------------------------------------------------------------------------- + + private ImportItemService importItemService; + + public void setImportItemService( ImportItemService importItemService ) + { + this.importItemService = importItemService; + } + + private SelectionManager selectionManager; + + public void setSelectionManager( SelectionManager selectionManager ) + { + this.selectionManager = selectionManager; + } private OrganisationUnitSelectionManager organisationUnitSelectionManager; @@ -68,64 +86,71 @@ this.organisationUnitSelectionManager = organisationUnitSelectionManager; } - // -------------------------------------------------------------------- + // ------------------------------------------------------------------------- // Inputs && Outputs - // -------------------------------------------------------------------- - - private File upload; + // ------------------------------------------------------------------------- private List importItemValueByOrgUnits; - private ArrayList importItems; - - private ExcelItemGroup importReport; - - // -------------------------------------------------------------------- + private String message; + + private I18n i18n; + + // ------------------------------------------------------------------------- // Getters and Setters - // -------------------------------------------------------------------- - - public void setUpload( File upload ) - { - this.upload = upload; - } - - public void setImportReport( ExcelItemGroup importReport ) - { - this.importReport = importReport; - } - - public void setImportItems( ArrayList importItems ) - { - this.importItems = importItems; - } + // ------------------------------------------------------------------------- public List getImportItemValueByOrgUnits() { return importItemValueByOrgUnits; } - // -------------------------------------------------------------------- + public String getMessage() + { + return message; + } + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + // ------------------------------------------------------------------------- // Action implementation - // -------------------------------------------------------------------- + // ------------------------------------------------------------------------- public String execute() { try { - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - - FileInputStream inputStream = new FileInputStream( upload ); - - HSSFWorkbook wb = new HSSFWorkbook( inputStream ); - - importItemValueByOrgUnits = new ArrayList(); - - if ( organisationUnit != null ) + OrganisationUnit unit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); + + if ( unit != null ) { + FileInputStream inputStream = new FileInputStream( new File( selectionManager.getUploadFilePath() ) ); + + Workbook wb = new HSSFWorkbook( inputStream ); + + ExcelItemGroup importReport = importItemService + .getImportReport( selectionManager.getSelectedReportId() ); + + List importItems = new ArrayList( importReport.getExcelItems() ); + + if ( importItems == null || importItems.isEmpty() ) + { + message = i18n.getString( "import_excel_items_cannot_be_empty" ); + + return ERROR; + } + + Collections.sort( importItems, new ImportItemComparator() ); + + importItemValueByOrgUnits = new ArrayList(); + for ( OrganisationUnitGroup organisationUnitGroup : importReport.getOrganisationUnitGroups() ) { List organisationUnits = new ArrayList( getOrganisationUnits( - organisationUnitGroup, organisationUnit ) ); + organisationUnitGroup, unit ) ); Collections.sort( organisationUnits, new OrganisationUnitNameComparator() ); @@ -135,11 +160,11 @@ { ImportItemValueByOrganisationUnit importItemValueByOrgUnit = new ImportItemValueByOrganisationUnit( o ); - ArrayList importItemValues = new ArrayList(); + List importItemValues = new ArrayList(); for ( ExcelItem importItem : importItems ) { - HSSFSheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); + Sheet sheet = wb.getSheetAt( importItem.getSheetNo() - 1 ); String value = ExcelUtils.readValueImportingByPOI( importItem.getRow() + row, importItem .getColumn(), sheet ); === added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importitem/action/ShowUpdateImportItemFormAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importitem/action/ShowUpdateImportItemFormAction.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importitem/action/ShowUpdateImportItemFormAction.java 2011-06-07 05:41:55 +0000 @@ -0,0 +1,126 @@ +package org.hisp.dhis.reportexcel.importitem.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 java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataelement.comparator.DataElementGroupNameComparator; +import org.hisp.dhis.reportexcel.importitem.ExcelItem; +import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; +import org.hisp.dhis.reportexcel.importitem.ImportItemService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public class ShowUpdateImportItemFormAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private ImportItemService importItemService; + + public void setImportItemService( ImportItemService importItemService ) + { + this.importItemService = importItemService; + } + + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + // ------------------------------------------------------------------------- + // Input && Output + // ------------------------------------------------------------------------- + + private Integer importReportId; + + public void setImportReportId( Integer importReportId ) + { + this.importReportId = importReportId; + } + + private Integer importItemId; + + public void setImportItemId( Integer importItemId ) + { + this.importItemId = importItemId; + } + + public ExcelItemGroup importReport; + + public ExcelItemGroup getImportReport() + { + return importReport; + } + + private ExcelItem importItem; + + public ExcelItem getImportItem() + { + return importItem; + } + + private List dataElementGroups; + + public List getDataElementGroups() + { + return dataElementGroups; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() + throws Exception + { + importReport = importItemService.getImportReport( importReportId ); + + importItem = importItemService.getImportItem( importItemId ); + + dataElementGroups = new ArrayList( dataElementService.getAllDataElementGroups() ); + + Collections.sort( dataElementGroups, new DataElementGroupNameComparator() ); + + return SUCCESS; + } +} === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importreport/action/GetImportReportByIdAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importreport/action/GetImportReportByIdAction.java 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importreport/action/GetImportReportByIdAction.java 2011-06-07 05:41:55 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.reportexcel.importreport.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 === added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importreport/action/ShowUpdateImportReportFormAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importreport/action/ShowUpdateImportReportFormAction.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importreport/action/ShowUpdateImportReportFormAction.java 2011-06-07 05:41:55 +0000 @@ -0,0 +1,103 @@ +package org.hisp.dhis.reportexcel.importreport.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 java.util.ArrayList; +import java.util.List; + +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.period.PeriodType; +import org.hisp.dhis.reportexcel.importitem.ExcelItemGroup; +import org.hisp.dhis.reportexcel.importitem.ImportItemService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ +public class ShowUpdateImportReportFormAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependency + // ------------------------------------------------------------------------- + + private ImportItemService importItemService; + + public void setImportItemService( ImportItemService importItemService ) + { + this.importItemService = importItemService; + } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + // ------------------------------------------------------------------------- + // Input && Output + // ------------------------------------------------------------------------- + + private int id; + + public void setId( int id ) + { + this.id = id; + } + + private ExcelItemGroup importReport; + + public ExcelItemGroup getImportReport() + { + return importReport; + } + + private List periodTypes; + + public List getPeriodTypes() + { + return periodTypes; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + importReport = importItemService.getImportReport( id ); + + periodTypes = new ArrayList( periodService.getAllPeriodTypes() ); + + return SUCCESS; + } +} === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/jchart/action/GetJChartAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/jchart/action/GetJChartAction.java 2010-09-30 09:37:41 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/jchart/action/GetJChartAction.java 2011-06-07 05:41:55 +0000 @@ -38,9 +38,9 @@ public class GetJChartAction implements Action { - // ------------------------------------------- + // ------------------------------------------------------------------------- // Dependency - // ------------------------------------------- + // ------------------------------------------------------------------------- private JChartSevice jchartService; @@ -49,9 +49,9 @@ this.jchartService = jchartService; } - // ------------------------------------------- + // ------------------------------------------------------------------------- // Input & Output - // ------------------------------------------- + // ------------------------------------------------------------------------- private Integer id; @@ -67,7 +67,10 @@ return jchart; } - @Override + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + public String execute() throws Exception { === added file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/jchart/action/PrepareDataForAddOrUpdateJChartAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/jchart/action/PrepareDataForAddOrUpdateJChartAction.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/jchart/action/PrepareDataForAddOrUpdateJChartAction.java 2011-06-07 05:41:55 +0000 @@ -0,0 +1,126 @@ +package org.hisp.dhis.reportexcel.jchart.action; + +/* + * Copyright (c) 2004-2010, 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.apache.commons.lang.StringUtils.isNotBlank; + +import java.util.ArrayList; +import java.util.List; + +import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.indicator.IndicatorService; +import org.hisp.dhis.jchart.JChart; +import org.hisp.dhis.jchart.JChartSevice; +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.period.PeriodType; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + */ +public class PrepareDataForAddOrUpdateJChartAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependency + // ------------------------------------------------------------------------- + + private JChartSevice jchartService; + + public void setJchartService( JChartSevice jchartService ) + { + this.jchartService = jchartService; + } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + private IndicatorService indicatorService; + + public void setIndicatorService( IndicatorService indicatorService ) + { + this.indicatorService = indicatorService; + } + + // ------------------------------------------------------------------------- + // Input & Output + // ------------------------------------------------------------------------- + + private Integer id; + + public void setId( Integer id ) + { + this.id = id; + } + + private JChart jchart; + + public JChart getJchart() + { + return jchart; + } + + private List periodTypes; + + public List getPeriodTypes() + { + return periodTypes; + } + + private List indicatorGroups; + + public List getIndicatorGroups() + { + return indicatorGroups; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + if ( isNotBlank( String.valueOf( id ) ) ) + { + jchart = jchartService.getJChart( id ); + } + + periodTypes = new ArrayList( periodService.getAllPeriodTypes() ); + + indicatorGroups = new ArrayList( indicatorService.getAllIndicatorGroups() ); + + return SUCCESS; + } + +} === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/ExportXMLAction.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/ExportXMLAction.java 2011-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/ExportXMLAction.java 2011-06-07 05:41:55 +0000 @@ -49,9 +49,9 @@ private static final String ENCODING = "UTF8"; - // ------------------------------------------- + // ------------------------------------------------------------------------- // Dependency - // ------------------------------------------- + // ------------------------------------------------------------------------- private ExportReportService exportReportService; @@ -67,30 +67,18 @@ this.selectionManager = selectionManager; } - // ------------------------------------------- + // ------------------------------------------------------------------------- // Input && Output - // ------------------------------------------- - - private String outputXLS; - + // ------------------------------------------------------------------------- + private String xmlStructureResponse; private File FILE_XLS; - // ------------------------------------------- + // ------------------------------------------------------------------------- // Getter & Setter // ------------------------------------------- - public String getOutputXLS() - { - return outputXLS; - } - - public void setOutputXLS( String outputXLS ) - { - this.outputXLS = outputXLS; - } - public String getXmlStructureResponse() { return xmlStructureResponse; @@ -134,5 +122,4 @@ // inputStream.close(); } - } === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/state/DefaultSelectionManager.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/state/DefaultSelectionManager.java 2010-07-13 15:50:08 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/state/DefaultSelectionManager.java 2011-06-07 05:41:55 +0000 @@ -46,6 +46,8 @@ private static final String SESSION_KEY_SELECTED_REPORT_ID = "SESSION_KEY_SELECTED_REPORT_ID"; private static final String SESSION_KEY_BOOKMARK_TYPE = "SESSION_KEY_BOOKMARK_TYPE"; + + private static final String SESSION_KEY_LIST_OBJECT = "SESSION_KEY_LIST_OBJECT"; @Override public String getDownloadFilePath() @@ -112,10 +114,21 @@ } @SuppressWarnings( "unchecked" ) - @Override public void setBookmarkType( String type ) { getSession().put( SESSION_KEY_BOOKMARK_TYPE, type ); } + @Override + public String[] getListObject() + { + return (String[]) getSession().get( SESSION_KEY_LIST_OBJECT ); + } + + @SuppressWarnings("unchecked") + public void setListObject( String[] objects ) + { + getSession().put( SESSION_KEY_LIST_OBJECT, objects ); + } + } === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/state/SelectionManager.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/state/SelectionManager.java 2010-07-13 15:50:08 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/state/SelectionManager.java 2011-06-07 05:41:55 +0000 @@ -51,5 +51,9 @@ public void setBookmarkType( String type ); public String getBookmarkType(); + + public String[] getListObject(); + + public void setListObject( String[] objects ); } === modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/FileUtils.java' --- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/FileUtils.java 2011-03-25 09:11:30 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/FileUtils.java 2011-06-07 05:41:55 +0000 @@ -49,9 +49,7 @@ { for ( File f : directory.listFiles() ) { - result.add( f.getName() ); - } } === 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-05-26 05:23:56 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-06-07 05:41:55 +0000 @@ -858,6 +858,15 @@ ref="org.hisp.dhis.reportexcel.importitem.ImportItemService" /> + + + + + - + @@ -1028,7 +1038,17 @@ - + + + + + + + + + + + + + + + + + + + + - + @@ -1120,24 +1166,56 @@ ref="org.hisp.dhis.reportexcel.importitem.ImportItemService" /> - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + - - + - - - - - - - - - - + - @@ -1233,7 +1293,8 @@ id="org.hisp.dhis.reportexcel.filemanager.action.ExcelTemplateListAction" class="org.hisp.dhis.reportexcel.filemanager.action.ExcelTemplateListAction" scope="prototype"> - + + + + + + + - updateExportReportFormChain - - F_EXCEL_REPORT_ADMINISTRATION - - - /main.vm + listAllExportReport.action /dhis-web-excel-reporting/report/updateExportReportForm.vm javascript/exportReports.js F_EXCEL_REPORT_ADMINISTRATION @@ -445,18 +439,14 @@ - - generateReportCategory - - - generateReportNormal - - - generateReportOrgGroupListing - - - generateReportPeriodColumnListing - + + generateReportCategory.action + + generateReportNormal.action + + generateReportOrgGroupListing.action + + generateReportPeriodColumnListing.action - - generatePreviewCategory - - - generatePreviewNormal - - - generatePreviewOrgGroupListing - - - generatePreviewPeriodColumnListing - + + generatePreviewCategory.action + + generatePreviewNormal.action + + generatePreviewOrgGroupListing.action + + generatePreviewPeriodColumnListing.action - exportXMLChain + exportXML.action - exportXMLChain + exportXML.action - exportXMLChain + exportXML.action - exportXMLChain + exportXML.action - /dhis-web-excel-reporting/responseExportReportPreview.vm @@ -662,15 +648,14 @@ - - generateAdvancedReportCategory - - generateAdvancedReportNormal - - - generateAdvancedReportOrganizationGroupListing - - generateAdvancedReportPeriodColumnListingAction + + generateAdvancedReportCategory.action + + generateAdvancedReportNormal.action + + generateAdvancedReportOrganizationGroupListing.action + + generateAdvancedReportPeriodColumnListing.action - /dhis-web-commons/ajax/xmlResponseSuccess.vm @@ -701,41 +686,37 @@ - - generatePreviewAdvancedCategory - - - generatePreviewAdvancedNormal - - - generatePreviewAdvancedOrgGroupListing - - - generatePreviewAdvancedPeriodColumnListing - + + generatePreviewAdvancedCategory.action + + generatePreviewAdvancedNormal.action + + generatePreviewAdvancedOrgGroupListing.action + + generatePreviewAdvancedPeriodColumnListing.action - exportXMLChain + exportXML.action - exportXMLChain + exportXML.action - exportXMLChain + exportXML.action - exportXMLChain + exportXML.action @@ -787,14 +768,7 @@ - updateImportReportFormChain - - F_EXCEL_REPORT_ADMINISTRATION - - - + class="org.hisp.dhis.reportexcel.importreport.action.ShowUpdateImportReportFormAction"> /main.vm /dhis-web-excel-reporting/import/updateImportReport.vm javascript/importReports.js @@ -803,9 +777,7 @@ - - listAllImportReport.action - + listAllImportReport.action - updateImportItemChainForm - - - - + class="org.hisp.dhis.reportexcel.importitem.action.ShowUpdateImportItemFormAction"> /main.vm /dhis-web-excel-reporting/import/updateImportItem.vm javascript/importItems.js @@ -1063,18 +1029,14 @@ - - previewDataCategory - - - previewDataNormal - - - previewDataOrganizationGroup - - - previewDataNormal - + + previewDataCategory.action + + previewDataNormal.action + + previewDataOrganizationGroup.action + + previewDataNormal.action @@ -1086,6 +1048,16 @@ /dhis-web-commons/ajax/xmlResponseError.vm + + + + /dhis-web-excel-reporting/responseImportItemValuesByCategory.vm + + + /dhis-web-commons/ajax/xmlResponseError.vm + + @@ -1096,58 +1068,43 @@ /dhis-web-commons/ajax/xmlResponseError.vm - - - - - /dhis-web-excel-reporting/responseImportItemValuesByCategory.vm - - - /dhis-web-commons/ajax/xmlResponseError.vm - - - + - - importDataCategoryExcelGroup - - - importDataNormalExcelGroup - - - importDataExcelOrganizationGroup - - - generateExportReportPeriodColumnListingAjax - - - - - - /dhis-web-commons/ajax/xmlResponseSuccess.vm - - /dhis-web-commons/ajax/xmlResponseError.vm - - - - - /dhis-web-commons/ajax/xmlResponseSuccess.vm - - /dhis-web-commons/ajax/xmlResponseError.vm - - - - - /dhis-web-commons/ajax/xmlResponseSuccess.vm - - /dhis-web-commons/ajax/xmlResponseError.vm - - + + importDataNormal?importReportId=${importReportId} + + importDataCategory + + importDataOrganizationGroup + + generateExportReportPeriodColumnListingAjax + + + + + /dhis-web-commons/ajax/xmlResponseSuccess.vm + + /dhis-web-commons/ajax/xmlResponseError.vm + + + + + /dhis-web-commons/ajax/xmlResponseSuccess.vm + + /dhis-web-commons/ajax/xmlResponseError.vm + + + + + /dhis-web-commons/ajax/xmlResponseSuccess.vm + + /dhis-web-commons/ajax/xmlResponseError.vm + + - periodColumns.action?id=${exportReportId} - + + periodColumns.action?id=${exportReportId} - addJChartFormChain1 - - - - addJChartFormChain2 - - - + class="org.hisp.dhis.reportexcel.jchart.action.PrepareDataForAddOrUpdateJChartAction"> /main.vm /dhis-web-excel-reporting/chart/addJChart.vm /dhis-web-excel-reporting/menu.vm @@ -1281,17 +1228,7 @@ - updateJChartFormChain1 - - - - updateJChartFormChain2 - - - + class="org.hisp.dhis.reportexcel.jchart.action.PrepareDataForAddOrUpdateJChartAction"> /main.vm /dhis-web-excel-reporting/chart/updateJChart.vm /dhis-web-excel-reporting/menu.vm === 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-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm 2011-06-07 05:41:55 +0000 @@ -46,8 +46,8 @@ - - + + === 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-05-24 07:48:23 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js 2011-06-07 05:41:55 +0000 @@ -28,15 +28,15 @@ params +='&importItemIds=' + importItems[i].value; } } - } + } params += '&periodId='+ periodId; request.sendAsPost(params); request.send('importData.action'); } -function importDataCompleted( xmlObject ){ - - setMessage(xmlObject.firstChild.nodeValue); +function importDataCompleted( xmlObject ) +{ + setMessage(xmlObject.firstChild.nodeValue); } // ----------------------------------------------------------------------------- === modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/responseExportReportPreview.vm' --- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/responseExportReportPreview.vm 2011-05-18 09:23:52 +0000 +++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/responseExportReportPreview.vm 2011-06-07 05:41:55 +0000 @@ -1,6 +1,4 @@ - $!xmlStructureResponse - \ No newline at end of file