=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java' --- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-16 20:17:59 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-17 10:36:42 +0000 @@ -44,7 +44,6 @@ import static org.hisp.dhis.reportsheet.utils.ExcelUtils.readValueByPOI; import java.io.FileInputStream; -import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -138,9 +137,7 @@ private String commonName = ""; - private int exportReportId; - - private int dataSetId; + private Set vrList = new HashSet(); private Map deMap1 = new HashMap(); @@ -148,8 +145,6 @@ private Map idMap = new HashMap(); - private Set vrList = new HashSet(); - private static final Map operatorMap = new HashMap() { /** @@ -224,6 +219,35 @@ return xmlStructureResponse; } + private int exportReportId; + + public int getExportReportId() + { + return exportReportId; + } + + private int dataSetId; + + public int getDataSetId() + { + return dataSetId; + } + + public Collection getDataElementIds() + { + return deMap1.values(); + } + + public Collection getIndicatorIds() + { + return idMap.values(); + } + + public Set getValidationRuleIds() + { + return new HashSet( vrList ); + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -283,13 +307,14 @@ e.printStackTrace(); cleanUp(); + + return ERROR; } return SUCCESS; } private void printXML( Collection collectSheets, List importItems ) - throws Exception { printMergedInfo( collectSheets ); @@ -305,267 +330,215 @@ private void printData( int sheetNo, List importItems ) { - try + + // Create new DataSet + DataSet dataSet = new DataSet( commonName, commonName, periodType ); + + // Create new ExportReport + ExportReport exportReport = new ExportReportNormal( commonName, REPORT_EXCEL_GROUP, excelFileName, null ); + exportReportId = exportReportService.addExportReport( exportReport ); + + Sheet s = WORKBOOK.getSheetAt( sheetNo - 1 ); + + xml.append( "" ); + xml.append( "" ); + + for ( Row row : s ) { - // Create new DataSet - DataSet dataSet = new DataSet( commonName, commonName, periodType ); - - // Create new ExportReport - ExportReport exportReport = new ExportReportNormal( commonName, REPORT_EXCEL_GROUP, excelFileName, null ); - exportReportId = exportReportService.addExportReport( exportReport ); - - Sheet s = WORKBOOK.getSheetAt( sheetNo - 1 ); - - xml.append( "" ); - xml.append( "" ); - - for ( Row row : s ) + xml.append( "" ); + + for ( Cell cell : row ) { - xml.append( "" ); + Comment cmt = cell.getCellComment(); + int rowIndex = cell.getRowIndex(); + int colIndex = cell.getColumnIndex(); - for ( Cell cell : row ) + if ( cmt != null ) { - Comment cmt = cell.getCellComment(); - int rowIndex = cell.getRowIndex(); - int colIndex = cell.getColumnIndex(); + String values[] = cmt.getString().toString().split( ":" ); - if ( cmt != null ) + if ( values[0].equalsIgnoreCase( DATAELEMENT_KEY ) ) { - String values[] = cmt.getString().toString().split( ":" ); - - if ( values[0].equalsIgnoreCase( DATAELEMENT_KEY ) ) - { - String deName = cell.getStringCellValue(); - String[] colNames = values[1].split( "," ); - - for ( String colName : colNames ) - { - int colIdx = convertColumnNameToNumber( colName ); - String name = deName + " (" + colIdx + ")"; - - // Generate DataElement - DataElement dataElement = new DataElement( name ); - /** TAKE CARE OF SHORT_NAME IS TOO LONG */ - dataElement.setShortName( name ); - dataElement.setActive( true ); - dataElement.setZeroIsSignificant( false ); - dataElement.setDomainType( DOMAIN_TYPE_AGGREGATE ); - dataElement.setType( VALUE_TYPE_INT ); - dataElement.setNumberType( VALUE_TYPE_INT ); - dataElement.setAggregationOperator( AGGREGATION_OPERATOR_SUM ); - dataElement.setCategoryCombo( optionCombo.getCategoryCombo() ); - - int deId = dataElementService.addDataElement( dataElement ); - - deMap1.put( (colIdx - 1) + "#" + rowIndex, deId ); - deMap2.put( colName + (rowIndex + 1), "[" + deId + "." + optionCombo.getId() + "]"); - - // Add the dataElement into the dataSet - dataSet.addDataElement( dataElement ); - - // Generate Report Item - ExportItem exportItem = new ExportItem(); - exportItem.setName( name ); - exportItem.setItemType( DATAELEMENT ); - exportItem.setRow( rowIndex + 1 ); - exportItem.setColumn( colIdx ); - exportItem.setExpression( "[" + deId + "." + optionCombo.getId() + "]" ); - exportItem.setPeriodType( SELECTED_MONTH ); - exportItem.setSheetNo( sheetNo ); - exportItem.setExportReport( exportReport ); - - exportReportService.addExportItem( exportItem ); - } - } - else if ( values[0].equalsIgnoreCase( INDICATOR_KEY ) ) - { - String idName = INDICATOR_NAME + values[1]; - Integer colIdx = colIndex + 1; - - if ( values.length == 4 ) - { - colIdx = convertColumnNameToNumber( values[3] ); - } - else if ( values.length == 5 ) - { - colIdx = convertColumnNameToNumber( values[3] ); - rowIndex = Integer.parseInt( values[4] ) - 1; - } - - // Create Indicator - Indicator indicator = new Indicator(); - indicator.setName( idName ); - indicator.setShortName( idName ); - indicator.setAnnualized( false ); - indicator.setIndicatorType( indicatorType ); - indicator.setNumerator( prepareExcelFormulaForAutoForm( values[2] ) ); - indicator.setNumeratorDescription( DESCRIPTION ); - indicator.setDenominator( 1 + "" ); - indicator.setDenominatorDescription( DESCRIPTION ); - - int indicatorId = indicatorService.addIndicator( indicator ); - - idMap.put( (colIdx - 1) + "#" + rowIndex, indicatorId ); + String deName = cell.getStringCellValue(); + String[] colNames = values[1].split( "," ); + + for ( String colName : colNames ) + { + int colIdx = convertColumnNameToNumber( colName ); + String name = deName + " (" + colIdx + ")"; + + // Generate DataElement + DataElement dataElement = new DataElement( name ); + /** TAKE CARE OF SHORT_NAME IS TOO LONG */ + dataElement.setShortName( name ); + dataElement.setActive( true ); + dataElement.setZeroIsSignificant( false ); + dataElement.setDomainType( DOMAIN_TYPE_AGGREGATE ); + dataElement.setType( VALUE_TYPE_INT ); + dataElement.setNumberType( VALUE_TYPE_INT ); + dataElement.setAggregationOperator( AGGREGATION_OPERATOR_SUM ); + dataElement.setCategoryCombo( optionCombo.getCategoryCombo() ); + + int deId = dataElementService.addDataElement( dataElement ); + + deMap1.put( (colIdx - 1) + "#" + rowIndex, deId ); + deMap2.put( colName + (rowIndex + 1), "[" + deId + "." + optionCombo.getId() + "]" ); // Add the dataElement into the dataSet - dataSet.addIndicator( indicator ); + dataSet.addDataElement( dataElement ); // Generate Report Item ExportItem exportItem = new ExportItem(); - exportItem.setName( idName ); - exportItem.setItemType( INDICATOR ); + exportItem.setName( name ); + exportItem.setItemType( DATAELEMENT ); exportItem.setRow( rowIndex + 1 ); exportItem.setColumn( colIdx ); - exportItem.setExpression( "[" + indicatorId + "]" ); + exportItem.setExpression( "[" + deId + "." + optionCombo.getId() + "]" ); exportItem.setPeriodType( SELECTED_MONTH ); exportItem.setSheetNo( sheetNo ); exportItem.setExportReport( exportReport ); exportReportService.addExportItem( exportItem ); } - else - { - // Validation rules - Expression leftSide = new Expression(); - - leftSide.setExpression( prepareExcelFormulaForAutoForm( values[2] ) ); - leftSide.setDescription( DESCRIPTION ); - leftSide.setNullIfBlank( true ); - - Expression rightSide = new Expression(); - - rightSide.setExpression( prepareExcelFormulaForAutoForm( values[4] ) ); - rightSide.setDescription( DESCRIPTION ); - rightSide.setNullIfBlank( true ); - - ValidationRule validationRule = new ValidationRule(); - - validationRule.setName( values[1] ); - validationRule.setDescription( DESCRIPTION ); - validationRule.setType( ValidationRule.TYPE_ABSOLUTE ); - validationRule.setOperator( Operator.valueOf( operatorMap.get( values[3] ) ) ); - validationRule.setLeftSide( leftSide ); - validationRule.setRightSide( rightSide ); - - validationRule.setPeriodType( periodType ); - - vrList.add( validationRuleService.saveValidationRule( validationRule ) ); - } - } - - String key = colIndex + "#" + rowIndex; - - if ( deMap1.containsKey( key ) ) - { - xml.append( "" ); - - xml.append( "]]>" ); - - xml.append( printFormatInfo( s, cell ) ); - - xml.append( "" ); - } - else if ( idMap.containsKey( key ) ) - { - int indicatorId = idMap.get( key ); - - xml.append( "" ); - - xml.append( "]]>" ); - - xml.append( printFormatInfo( s, cell ) ); - - xml.append( "" ); - } - else if ( (cell.getCellStyle() != null || cell.getCellType() != Cell.CELL_TYPE_BLANK) - && !s.isColumnHidden( colIndex ) ) - { - xml.append( "" ); - - xml.append( "" ); - - xml.append( printFormatInfo( s, cell ) ); - - xml.append( "" ); - } - } - xml.append( "" ); - } - xml.append( "" ); - - // Update DataSet - DataEntryForm dataEntryForm = new DataEntryForm( commonName, "

" ); - dataEntryFormService.addDataEntryForm( dataEntryForm ); - - dataSet.setDataEntryForm( dataEntryForm ); - dataSetId = dataSetService.addDataSet( dataSet ); - - // Update ExportReport - Set dataSets = new HashSet(); - dataSets.add( dataSet ); - - exportReport.setDataSets( dataSets ); - exportReportService.updateExportReport( exportReport ); - - xml.append( "" ); - - for ( String key1 : idMap.keySet() ) - { - Indicator indicator = indicatorService.getIndicator( idMap.get( key1 ) ); - String expression = indicator.getNumerator(); - - for ( String key2 : deMap2.keySet() ) - { - expression = expression.replaceAll( "\\[" + key2 + "\\]", deMap2.get( key2 ) ); - } - - indicator.setNumerator( expression ); - indicatorService.updateIndicator( indicator ); - } - - for ( Integer id : vrList ) - { - ValidationRule vr = validationRuleService.getValidationRule( id ); - - Expression leftSide = vr.getLeftSide(); - Expression rightSide = vr.getRightSide(); - - String leftExpression = leftSide.getExpression(); - String rightExpression = rightSide.getExpression(); - - for ( String key2 : deMap2.keySet() ) - { - String operandId = deMap2.get( key2 ); - - leftExpression = leftExpression.replaceAll( "\\[" + key2 + "\\]", operandId ); - rightExpression = rightExpression.replaceAll( "\\[" + key2 + "\\]", operandId ); - } - - leftSide.setDataElementsInExpression( expressionService.getDataElementsInExpression( leftExpression ) ); - leftSide.setOptionCombosInExpression( expressionService.getOptionCombosInExpression( leftExpression ) ); - - rightSide - .setDataElementsInExpression( expressionService.getDataElementsInExpression( rightExpression ) ); - rightSide - .setOptionCombosInExpression( expressionService.getOptionCombosInExpression( rightExpression ) ); - - vr.setLeftSide( leftSide ); - vr.setRightSide( rightSide ); - - validationRuleService.updateValidationRule( vr ); - } - } - catch ( Exception e ) - { - e.printStackTrace(); - - autoRollBack(); - cleanUp(); - } + } + else if ( values[0].equalsIgnoreCase( INDICATOR_KEY ) ) + { + String idName = INDICATOR_NAME + values[1]; + Integer colIdx = colIndex + 1; + + if ( values.length == 4 ) + { + colIdx = convertColumnNameToNumber( values[3] ); + } + else if ( values.length == 5 ) + { + colIdx = convertColumnNameToNumber( values[3] ); + rowIndex = Integer.parseInt( values[4] ) - 1; + } + + // Create Indicator + Indicator indicator = new Indicator(); + indicator.setName( idName ); + indicator.setShortName( idName ); + indicator.setAnnualized( false ); + indicator.setIndicatorType( indicatorType ); + indicator.setNumerator( prepareExcelFormulaForAutoForm( values[2] ) ); + indicator.setNumeratorDescription( DESCRIPTION ); + indicator.setDenominator( 1 + "" ); + indicator.setDenominatorDescription( DESCRIPTION ); + + int indicatorId = indicatorService.addIndicator( indicator ); + + idMap.put( (colIdx - 1) + "#" + rowIndex, indicatorId ); + + // Add the dataElement into the dataSet + dataSet.addIndicator( indicator ); + + // Generate Report Item + ExportItem exportItem = new ExportItem(); + exportItem.setName( idName ); + exportItem.setItemType( INDICATOR ); + exportItem.setRow( rowIndex + 1 ); + exportItem.setColumn( colIdx ); + exportItem.setExpression( "[" + indicatorId + "]" ); + exportItem.setPeriodType( SELECTED_MONTH ); + exportItem.setSheetNo( sheetNo ); + exportItem.setExportReport( exportReport ); + + exportReportService.addExportItem( exportItem ); + } + else + { + // Validation rules + Expression leftSide = new Expression(); + + leftSide.setExpression( prepareExcelFormulaForAutoForm( values[2] ) ); + leftSide.setDescription( DESCRIPTION ); + leftSide.setNullIfBlank( true ); + + Expression rightSide = new Expression(); + + rightSide.setExpression( prepareExcelFormulaForAutoForm( values[4] ) ); + rightSide.setDescription( DESCRIPTION ); + rightSide.setNullIfBlank( true ); + + ValidationRule validationRule = new ValidationRule(); + + validationRule.setName( values[1] ); + validationRule.setDescription( DESCRIPTION ); + validationRule.setType( ValidationRule.TYPE_ABSOLUTE ); + validationRule.setOperator( Operator.valueOf( operatorMap.get( values[3] ) ) ); + validationRule.setLeftSide( leftSide ); + validationRule.setRightSide( rightSide ); + + validationRule.setPeriodType( periodType ); + + vrList.add( validationRuleService.saveValidationRule( validationRule ) ); + } + } + + String key = colIndex + "#" + rowIndex; + + if ( deMap1.containsKey( key ) ) + { + xml.append( "" ); + + xml.append( "]]>" ); + + xml.append( printFormatInfo( s, cell ) ); + + xml.append( "" ); + } + else if ( idMap.containsKey( key ) ) + { + int indicatorId = idMap.get( key ); + + xml.append( "" ); + + xml.append( "]]>" ); + + xml.append( printFormatInfo( s, cell ) ); + + xml.append( "" ); + } + else if ( (cell.getCellStyle() != null || cell.getCellType() != Cell.CELL_TYPE_BLANK) + && !s.isColumnHidden( colIndex ) ) + { + xml.append( "" ); + + xml.append( "" ); + + xml.append( printFormatInfo( s, cell ) ); + + xml.append( "" ); + } + } + xml.append( "" ); + } + xml.append( "
" ); + + // Update DataSet + DataEntryForm dataEntryForm = new DataEntryForm( commonName, "

" ); + dataEntryFormService.addDataEntryForm( dataEntryForm ); + + dataSet.setDataEntryForm( dataEntryForm ); + dataSetId = dataSetService.addDataSet( dataSet ); + + // Update ExportReport + Set dataSets = new HashSet(); + dataSets.add( dataSet ); + + exportReport.setDataSets( dataSets ); + exportReportService.updateExportReport( exportReport ); + + updateIndicator(); + updateValidationRule(); + + xml.append( "" ); } /** @@ -624,7 +597,6 @@ // ------------------------------------------------------------------------- private void printMergedInfo( Collection collectSheets ) - throws IOException { // Open the main Tag // xml.append( MERGEDCELL_OPENTAG ); @@ -679,57 +651,53 @@ return buffer.toString(); } - private void autoRollBack() - { - try - { - if ( exportReportId > 0 ) - { - exportReportService.deleteExportReport( exportReportId ); - - exportReportId = 0; - } - if ( dataSetId > 0 ) - { - dataSetService.deleteDataSet( dataSetService.getDataSet( dataSetId ) ); - - dataSetId = 0; - } - - for ( String key : deMap1.keySet() ) - { - dataElementService.deleteDataElement( dataElementService.getDataElement( deMap1.get( key ) ) ); - } - for ( String key : idMap.keySet() ) - { - indicatorService.deleteIndicator( indicatorService.getIndicator( idMap.get( key ) ) ); - } - for ( Integer vrId : vrList ) - { - validationRuleService.deleteValidationRule( validationRuleService.getValidationRule( vrId ) ); - } - - deMap1.clear(); - deMap2.clear(); - idMap.clear(); - vrList.clear(); - } - catch ( Exception e ) - { - resetParams(); - - e.printStackTrace(); - } - } - - private void resetParams() - { - exportReportId = 0; - dataSetId = 0; - deMap1.clear(); - deMap2.clear(); - idMap.clear(); - vrList.clear(); - } - + private void updateIndicator() + { + for ( String key1 : idMap.keySet() ) + { + Indicator indicator = indicatorService.getIndicator( idMap.get( key1 ) ); + String expression = indicator.getNumerator(); + + for ( String key2 : deMap2.keySet() ) + { + expression = expression.replaceAll( "\\[" + key2 + "\\]", deMap2.get( key2 ) ); + } + + indicator.setNumerator( expression ); + indicatorService.updateIndicator( indicator ); + } + } + + private void updateValidationRule() + { + for ( Integer id : vrList ) + { + ValidationRule vr = validationRuleService.getValidationRule( id ); + + Expression leftSide = vr.getLeftSide(); + Expression rightSide = vr.getRightSide(); + + String leftExpression = leftSide.getExpression(); + String rightExpression = rightSide.getExpression(); + + for ( String key2 : deMap2.keySet() ) + { + String operandId = deMap2.get( key2 ); + + leftExpression = leftExpression.replaceAll( "\\[" + key2 + "\\]", operandId ); + rightExpression = rightExpression.replaceAll( "\\[" + key2 + "\\]", operandId ); + } + + leftSide.setDataElementsInExpression( expressionService.getDataElementsInExpression( leftExpression ) ); + leftSide.setOptionCombosInExpression( expressionService.getOptionCombosInExpression( leftExpression ) ); + + rightSide.setDataElementsInExpression( expressionService.getDataElementsInExpression( rightExpression ) ); + rightSide.setOptionCombosInExpression( expressionService.getOptionCombosInExpression( rightExpression ) ); + + vr.setLeftSide( leftSide ); + vr.setRightSide( rightSide ); + + validationRuleService.updateValidationRule( vr ); + } + } } \ No newline at end of file === added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormRollBack.java' --- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormRollBack.java 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormRollBack.java 2012-12-17 10:36:42 +0000 @@ -0,0 +1,211 @@ +package org.hisp.dhis.reportsheet.preview.action; + +/* + * Copyright (c) 2004-2012, 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.HashSet; +import java.util.Set; + +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; +import org.hisp.dhis.indicator.IndicatorService; +import org.hisp.dhis.reportsheet.ExportReport; +import org.hisp.dhis.reportsheet.ExportReportService; +import org.hisp.dhis.reportsheet.action.ActionSupport; +import org.hisp.dhis.validation.ValidationRuleService; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public class AutoGenerateFormRollBack + extends ActionSupport +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private DataElementService dataElementService; + + @Autowired + private DataSetService dataSetService; + + @Autowired + private IndicatorService indicatorService; + + @Autowired + private ValidationRuleService validationRuleService; + + @Autowired + private ExportReportService exportReportService; + + // ------------------------------------------------------------------------- + // Input && Output + // ------------------------------------------------------------------------- + + private int exportReportId; + + public void setExportReportId( int exportReportId ) + { + this.exportReportId = exportReportId; + } + + private int dataSetId; + + public void setDataSetId( int dataSetId ) + { + this.dataSetId = dataSetId; + } + + private Set dataElementIds = new HashSet(); + + public void setDataElementIds( Set dataElementIds ) + { + this.dataElementIds = dataElementIds; + } + + private Set indicatorIds = new HashSet(); + + public void setIndicatorIds( Set indicatorIds ) + { + this.indicatorIds = indicatorIds; + } + + private Set validationRuleIds = new HashSet(); + + public void setValidationRuleIds( Set validationRuleIds ) + { + this.validationRuleIds = validationRuleIds; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + cleanUp(); + + autoRollBack(); + + return SUCCESS; + } + + private void cleanUp() + { + System.gc(); + } + + private void autoRollBack() + { + try + { + message = ""; + + if ( exportReportId > 0 ) + { + ExportReport exportReport = exportReportService.getExportReport( exportReportId ); + + if ( exportReport != null ) + { + message += i18n.getString( "report_with_name" ) + " \"" + exportReport.getDisplayName(); + } + + exportReportService.deleteExportReport( exportReportId ); + + message += "\" " + i18n.getString( "deleted" ); + + exportReportId = 0; + } + if ( dataSetId > 0 ) + { + DataSet ds = dataSetService.getDataSet( dataSetId ); + + if ( ds != null ) + { + message += "
" + i18n.getString( "data_set_with_name" ) + " \"" + ds.getDisplayName(); + } + + dataSetService.deleteDataSet( ds ); + + message += "\" " + i18n.getString( "deleted" ); + + dataSetId = 0; + } + + int i = 0; + + if ( indicatorIds != null && !indicatorIds.isEmpty() ) + { + for ( Integer id : indicatorIds ) + { + indicatorService.deleteIndicator( indicatorService.getIndicator( id ) ); + i++; + } + + message += "
" + i18n.getString( "indicators" ) + ": " + i + "/" + indicatorIds.size() + " " + + i18n.getString( "deleted" ); + } + if ( validationRuleIds != null && !validationRuleIds.isEmpty() ) + { + i = 0; + + for ( Integer id : validationRuleIds ) + { + validationRuleService.deleteValidationRule( validationRuleService.getValidationRule( id ) ); + i++; + } + + message += "
" + i18n.getString( "validation_rules" ) + ": " + i + "/" + validationRuleIds.size() + " " + + i18n.getString( "deleted" ); + } + if ( dataElementIds != null && !dataElementIds.isEmpty() ) + { + i = 0; + + for ( Integer id : dataElementIds ) + { + dataElementService.deleteDataElement( dataElementService.getDataElement( id ) ); + i++; + } + + message += "
" + i18n.getString( "data_elements" ) + ": " + i + "/" + dataElementIds.size() + " " + + i18n.getString( "deleted" ); + } + } + catch ( Exception e ) + { + message = i18n.getString( "auto_roll_back_failed" ); + + e.printStackTrace(); + } + } +} \ No newline at end of file === removed file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/TestAction.java' --- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/TestAction.java 2012-12-11 15:34:39 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/TestAction.java 1970-01-01 00:00:00 +0000 @@ -1,64 +0,0 @@ -package org.hisp.dhis.reportsheet.preview.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.HashSet; -import java.util.Set; - -import com.opensymphony.xwork2.Action; - -/** - * @author - */ -public class TestAction - implements Action -{ - // TODO remove not required with struts2 - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - { - Set collectSheets = new HashSet(); - collectSheets.add( 1 ); - - try - { -// new AutoGenerateFormByTemplate( "d:\\template_file.xls", collectSheets ); - } - catch ( Exception e ) - { - System.out.println( e.getMessage() ); - } - - return SUCCESS; - } - -} === modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/META-INF/dhis/beans.xml' --- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/META-INF/dhis/beans.xml 2012-12-11 15:34:39 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/META-INF/dhis/beans.xml 2012-12-17 10:36:42 +0000 @@ -1527,14 +1527,15 @@ - - + + + === modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties' --- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties 2012-12-12 09:34:51 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties 2012-12-17 10:36:42 +0000 @@ -376,18 +376,21 @@ permission_notification = You don't have any permission in this Export report. Please contact with org_unit_with_name = Organisation unit data_set_with_name = Data set +report_with_name = Export report name uncompleted = uncompleted importing = Importing specified_data_set_unavailable = Selected data set is not exist specified_data_set_unassign_to_export_report = Selected data set is not assign to any Export report -roll_back_import = Rollback imported value -data_value = data value -old_value = The old value -new_value = The new value -reverted = reverted -deleted = deleted -no_value_rollbacked = There is no value rollbacked -automate = Automate -auto_generate_form = Automatic generating form -generate_form = Generate form -auto_generate_form_completed= Form generated \ No newline at end of file +roll_back_import = Rollback imported value +auto_roll_back_failed = Automatic rollback failed +data_value = data value +old_value = The old value +new_value = The new value +reverted = reverted +deleted = deleted +no_value_rollbacked = There is no value rollbacked +automate = Automate +auto_generate_form = Automatic generating form +generate_form = Generate form +generate_form_confirm = Would you like to generate form now ? +auto_generate_form_completed = Form generated \ No newline at end of file === modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties' --- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties 2012-12-12 09:34:51 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties 2012-12-17 10:36:42 +0000 @@ -407,11 +407,13 @@ via_email = th\u00f4ng qua th\u01b0 \u0111i\u1ec7n t\u1eed org_unit_with_name = \u0110\u01a1n v\u1ecb data_set_with_name = Bi\u1ec3u nh\u1eadp +report_with_name = B\u00e1o c\u00e1o Xu\u1ea5t uncompleted = ch\u01b0a ho\u00e0n t\u1ea5t importing = T\u00edch h\u1ee3p d\u1eef li\u1ec7u specified_data_set_unavailable = M\u1eabu b\u00e1o c\u00e1o n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i specified_data_set_unassign_to_export_report = M\u1eabu b\u00e1o c\u00e1o n\u00e0y ch\u01b0a \u0111\u01b0\u1ee3c g\u00e1n v\u00e0o b\u1ea5t k\u1ef3 bi\u1ec3u Xu\u1ea5t n\u00e0o roll_back_import = Ph\u1ee5c h\u1ed3i gi\u00e1 tr\u1ecb import +auto_roll_back_failed = Qu\u00e1 tr\u00ecnh ph\u1ee5c h\u1ed3i l\u1ed7i data_value = gi\u00e1 tr\u1ecb old_value = D\u1eef li\u1ec7u c\u0169 new_value = D\u1eef li\u1ec7u m\u1edbi @@ -421,4 +423,5 @@ automate = T\u1ef1 \u0111\u1ed9ng h\u00f3a auto_generate_form = T\u1ef1 \u0111\u1ed9ng t\u1ea1o bi\u1ec3u m\u1eabu generate_form = T\u1ea1o bi\u1ec3u m\u1eabu +generate_form_confirm = B\u1ea1n c\u00f3 mu\u1ed1n t\u1ea1o bi\u1ec3u m\u1eabu ngay b\u00e2y gi\u1edd ? auto_generate_form_completed = Bi\u1ec3u m\u1eabu \u0111\u01b0\u1ee3c ho\u00e0n th\u00e0nh \ No newline at end of file === modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml' --- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-12 09:34:51 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-17 10:36:42 +0000 @@ -1841,13 +1841,6 @@ administration.action F_MULTI_ORGANISATION_UNIT_ADD - - - ../dhis-web-commons/ajax/jsonResponseSuccess.vm - ../dhis-web-commons/ajax/jsonResponseError.vm - plainTextError - @@ -1868,7 +1861,14 @@ /dhis-web-spreadsheet-reporting/responseExportReportPreview.vm - /dhis-web-commons/ajax/xmlResponseError.vm + /dhis-web-spreadsheet-reporting/responseAutoGenerateFormError.vm + + + + ../dhis-web-commons/ajax/jsonResponseSuccess.vm + ../dhis-web-commons/ajax/jsonResponseError.vm + plainTextError === modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js' --- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-15 09:52:30 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-17 10:36:42 +0000 @@ -35,7 +35,9 @@ { 'draft': true, 'allowNewName': false }, function( data, e ) { try { - window.location.reload(); + if ( window.confirm( i18n_generate_form_confirm ) ) { + autoGenerateFormByTemplate(); + } else return; } catch(e) { alert(e); @@ -62,7 +64,41 @@ if ( type && type == 'error' ) { - showErrorMessage( parentElement.firstChild.nodeValue ); + var dataElementTag = parentElement.getElementsByTagName( 'dataElements' )[0]; + var indicatorTag = parentElement.getElementsByTagName( 'indicators' )[0]; + var validationRuleTag = parentElement.getElementsByTagName( 'validationRules' )[0]; + + var dataElements = dataElementTag.getElementsByTagName( 'id' ); + var indicators = dataElementTag.getElementsByTagName( 'id' ); + var validationRules = dataElementTag.getElementsByTagName( 'id' ); + + var reportId = getElementAttribute( parentElement, 'exportReport', 'id' ); + var dataSetId = getElementAttribute( parentElement, 'dataSet', 'id' ); + + var url = 'autoGenerateFormRollback.action?'; + + for ( var i = 0 ; i < dataElements.length ; i ++ ) + { + url += 'dataElementIds=' + dataElements[i].firstChild.nodeValue + '&'; + } + for ( var i = 0 ; i < indicators.length ; i ++ ) + { + url += 'indicatorIds=' + indicators[i].firstChild.nodeValue + '&'; + } + for ( var i = 0 ; i < validationRules.length ; i ++ ) + { + url += 'validationRuleIds=' + validationRules[i].firstChild.nodeValue + '&'; + } + + url += 'exportReportId=' + reportId + '&dataSetId=' + dataSetId; + + jQuery.post( url, {}, function( json ) { + if ( json.response == "success" ) { + showSuccessMessage( json.message, 7000 ); + } else { + showErrorMessage( json.message, 5000 ); + } + } ); } else { @@ -169,7 +205,7 @@ //showById( "previewDiv" ); unLockScreen(); - showSuccessMessage( i18n_auto_generate_form_completed ); + showSuccessMessage( i18n_auto_generate_form_completed, 3000 ); if ( _sHTML.length > 0 ) { === added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/responseAutoGenerateFormError.vm' --- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/responseAutoGenerateFormError.vm 1970-01-01 00:00:00 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/responseAutoGenerateFormError.vm 2012-12-17 10:36:42 +0000 @@ -0,0 +1,21 @@ + + + $encoder.xmlEncode( $message ) + + + + #foreach( $id in $dataElementIds ) + $id + #end + + + #foreach( $id in $indicatorIds ) + $id + #end + + + #foreach( $id in $validationRuleIds ) + $id + #end + + \ No newline at end of file === modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm' --- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm 2012-12-16 20:17:59 +0000 +++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/showAutoGenerateForm.vm 2012-12-17 10:36:42 +0000 @@ -26,5 +26,6 @@ \ No newline at end of file