=== removed file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelCategoryAction.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelCategoryAction.java 2009-10-07 10:20:08 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelCategoryAction.java 1970-01-01 00:00:00 +0000 @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2004-2007, 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. - */ -package org.hisp.dhis.reportexcel.preview.action; - -import java.util.Collection; - -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.reportexcel.DataElementGroupOrder; -import org.hisp.dhis.reportexcel.ReportExcelCategory; -import org.hisp.dhis.reportexcel.ReportExcelItem; -import org.hisp.dhis.reportexcel.utils.ExcelUtils; - -/** - * @author Dang Duy Hieu - * @author Tran Thanh Tri - * @version $Id$ - * @since 2009-09-18 - */ -public class GeneratePreviewReportExcelCategoryAction - extends GeneratePreviewReportExcelSupport -{ - - public String execute() - throws Exception - { - statementManager.initialise(); - - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - Period period = selectionManager.getSelectedPeriod(); - this.installPeriod( period ); - - ReportExcelCategory reportExcel = (ReportExcelCategory) reportService.getReportExcel( selectionManager - .getSelectedReportExcelId() ); - - this.installReadTemplateFile( reportExcel, period, organisationUnit ); - - if ( this.sheetId > 0 ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( this.sheetId, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( organisationUnit, reportExcelItems, reportExcel, sheet ); - } - else - { - for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( sheetNo, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( organisationUnit, reportExcelItems, reportExcel, sheet ); - - } - } - - this.complete(); - - statementManager.destroy(); - - return SUCCESS; - } - - private void generateOutPutFile( OrganisationUnit organisationUnit, Collection reportExcelItems, - ReportExcelCategory reportExcel, HSSFSheet sheet ) - throws Exception - { - - for ( ReportExcelItem reportItem : reportExcelItems ) - { - int rowBegin = reportItem.getRow(); - - for ( DataElementGroupOrder dataElementGroup : reportExcel.getDataElementOrders() ) - { - - int beginChapter = rowBegin; - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_NAME ) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElementGroup.getName(), - ExcelUtils.TEXT, sheet, this.csTextChapterLeft ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_CODE ) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElementGroup.getCode(), - ExcelUtils.TEXT, sheet, this.csTextChapterLeft ); - } - - rowBegin++; - int serial = 1; - for ( DataElement dataElement : dataElementGroup.getDataElements() ) - { - - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_NAME ) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElement.getName(), - ExcelUtils.TEXT, sheet, this.csTextLeft ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT_CODE ) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), dataElement.getCode(), - ExcelUtils.TEXT, sheet, this.csTextLeft ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.SERIAL ) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( serial ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.FORMULA_EXCEL ) ) - { - ExcelUtils.writeFormulaByPOI( rowBegin, reportItem.getColumn(), reportItem.getExpression(), - sheet, this.csNumber ); - } - else - { - ReportExcelItem newReportItem = new ReportExcelItem(); - newReportItem.setColumn( reportItem.getColumn() ); - newReportItem.setRow( reportItem.getRow() ); - newReportItem.setPeriodType( reportItem.getPeriodType() ); - newReportItem.setName( reportItem.getName() ); - newReportItem.setSheetNo( reportItem.getSheetNo() ); - newReportItem.setItemType( reportItem.getItemType() ); - - String expression = reportItem.getExpression(); - expression = expression.replace( "*", String.valueOf( dataElement.getId() ) ); - newReportItem.setExpression( expression ); - - double value = this.getDataValue( newReportItem, organisationUnit ); - - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - } - rowBegin++; - serial++; - } - - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) ) - { - String columnName = ExcelUtils.convertColNumberToColName( reportItem.getColumn() ); - String formula = "SUM(" + columnName + (beginChapter + 1) + ":" + columnName + (rowBegin - 1) + ")"; - ExcelUtils.writeFormulaByPOI( beginChapter, reportItem.getColumn(), formula, sheet, this.csNumber ); - } - } - } - } -} === removed file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelNormalAction.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelNormalAction.java 2009-10-07 10:20:08 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelNormalAction.java 1970-01-01 00:00:00 +0000 @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2004-2007, 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. - */ -package org.hisp.dhis.reportexcel.preview.action; - -import java.util.Collection; - -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.reportexcel.ReportExcelItem; -import org.hisp.dhis.reportexcel.ReportExcelNormal; -import org.hisp.dhis.reportexcel.utils.ExcelUtils; - -/** - * @author Dang Duy Hieu - * @author Tran Thanh Tri - * @version $Id$ - * @since 2009-09-18 - */ -public class GeneratePreviewReportExcelNormalAction - extends GeneratePreviewReportExcelSupport -{ - - public String execute() - throws Exception - { - statementManager.initialise(); - - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - Period period = selectionManager.getSelectedPeriod(); - this.installPeriod( period ); - - ReportExcelNormal reportExcel = (ReportExcelNormal) reportService.getReportExcel( selectionManager - .getSelectedReportExcelId() ); - - this.installReadTemplateFile( reportExcel, period, organisationUnit ); - - if ( this.sheetId > 0 ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( this.sheetId, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( organisationUnit, reportExcelItems, sheet ); - } - else - { - for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( sheetNo, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( organisationUnit, reportExcelItems, sheet ); - } - } - - this.complete(); - - statementManager.destroy(); - - return SUCCESS; - } - - private void generateOutPutFile( OrganisationUnit organisationUnit, Collection reportExcelItems, - HSSFSheet sheet ) - throws Exception - { - for ( ReportExcelItem reportItem : reportExcelItems ) - { - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) ) - { - double value = getDataValue( reportItem, organisationUnit ); - - ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn(), String.valueOf( value ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - } - - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.INDICATOR ) ) - { - double value = getIndicatorValue( reportItem, organisationUnit ); - - ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn(), String.valueOf( value ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - } - } - } - -} === removed file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelOrganizationGroupListingAction.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelOrganizationGroupListingAction.java 2009-10-07 10:20:08 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelOrganizationGroupListingAction.java 1970-01-01 00:00:00 +0000 @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2004-2007, 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. - */ -package org.hisp.dhis.reportexcel.preview.action; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitGroup; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.reportexcel.ReportExcelItem; -import org.hisp.dhis.reportexcel.ReportExcelOganiztionGroupListing; -import org.hisp.dhis.reportexcel.utils.ExcelUtils; - -/** - * @author Dang Duy Hieu - * @author Chau Thu Tran - * @version $Id$ - * @since 2009-09-18 - */ - -public class GeneratePreviewReportExcelOrganizationGroupListingAction - extends GeneratePreviewReportExcelSupport -{ - - public String execute() - throws Exception - { - statementManager.initialise(); - - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - Period period = selectionManager.getSelectedPeriod(); - this.installPeriod( period ); - - ReportExcelOganiztionGroupListing reportExcel = (ReportExcelOganiztionGroupListing) reportService - .getReportExcel( selectionManager.getSelectedReportExcelId() ); - - this.installReadTemplateFile( reportExcel, period, organisationUnit ); - - if ( this.sheetId > 0 ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( this.sheetId, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( reportExcel, reportExcelItems, organisationUnit, sheet ); - } - else - { - for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( sheetNo, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( reportExcel, reportExcelItems, organisationUnit, sheet ); - } - } - - this.complete(); - - statementManager.destroy(); - - return SUCCESS; - } - - private void generateOutPutFile( ReportExcelOganiztionGroupListing reportExcel, - Collection reportExcelItems, OrganisationUnit organisationUnit, HSSFSheet sheet ) - throws Exception - { - for ( ReportExcelItem reportItem : reportExcelItems ) - { - int rowBegin = reportItem.getRow(); - int chapperNo = 0; - - for ( OrganisationUnitGroup organisationUnitGroup : reportExcel.getOrganisationUnitGroups() ) - { - - List childrenOrganisationUnits = new ArrayList( organisationUnit - .getChildren() ); - - Collection organisationUnits = organisationUnitGroup.getMembers(); - - organisationUnits.retainAll( childrenOrganisationUnits ); - - int beginChapter = rowBegin; - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.ORGANISATION ) - && (!organisationUnits.isEmpty()) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), organisationUnitGroup.getName(), - ExcelUtils.TEXT, sheet, this.csTextChapterLeft ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.SERIAL ) - && (!organisationUnits.isEmpty()) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), chappter[chapperNo], ExcelUtils.TEXT, - sheet, this.csTextChapterLeft ); - } - chapperNo++; - rowBegin++; - int serial = 1; - - for ( OrganisationUnit o : organisationUnits ) - { - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.ORGANISATION ) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), o.getName(), ExcelUtils.TEXT, - sheet, this.csTextLeft ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.SERIAL ) ) - { - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( serial ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) ) - { - double value = this.getDataValue( reportItem, o ); - - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.INDICATOR ) ) - { - double value = this.getIndicatorValue( reportItem, o ); - - ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.FORMULA_EXCEL ) ) - { - ExcelUtils.writeFormulaByPOI( rowBegin, reportItem.getColumn(), reportItem.getExpression(), - sheet, this.csNumber ); - } - - rowBegin++; - serial++; - } - - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) - && (!organisationUnits.isEmpty()) ) - { - String columnName = ExcelUtils.convertColNumberToColName( reportItem.getColumn() ); - String formula = "SUM(" + columnName + (beginChapter + 1) + ":" + columnName + (rowBegin - 1) + ")"; - ExcelUtils.writeFormulaByPOI( beginChapter, reportItem.getColumn(), formula, sheet, this.csNumber ); - } - } - } - } -} === removed file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelPeriodColumnListingAction.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelPeriodColumnListingAction.java 2009-10-07 10:20:08 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/GeneratePreviewReportExcelPeriodColumnListingAction.java 1970-01-01 00:00:00 +0000 @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2004-2007, 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. - */ - -package org.hisp.dhis.reportexcel.preview.action; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.MonthlyPeriodType; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodType; -import org.hisp.dhis.period.comparator.AscendingPeriodComparator; -import org.hisp.dhis.reportexcel.ReportExcelItem; -import org.hisp.dhis.reportexcel.ReportExcelPeriodColumnListing; -import org.hisp.dhis.reportexcel.utils.DateUtils; -import org.hisp.dhis.reportexcel.utils.ExcelUtils; -import org.hisp.dhis.system.util.MathUtils; - -/** - * @author Dang Duy Hieu - * @author Tran Thanh Tri - * @version $Id$ - * @since 2009-09-18 - */ - -public class GeneratePreviewReportExcelPeriodColumnListingAction - extends GeneratePreviewReportExcelSupport -{ - - public String execute() - throws Exception - { - statementManager.initialise(); - - OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit(); - Period period = selectionManager.getSelectedPeriod(); - this.installPeriod( period ); - Calendar calendar = Calendar.getInstance(); - PeriodType periodType = periodService.getPeriodTypeByClass( MonthlyPeriodType.class ); - Date firstDateOfThisYear = DateUtils.getFirstDayOfYear( calendar.get( Calendar.YEAR ) ); - - List periods = new ArrayList( periodService.getIntersectingPeriodsByPeriodType( periodType, - firstDateOfThisYear, endDate ) ); - Collections.sort( periods, new AscendingPeriodComparator() ); - - ReportExcelPeriodColumnListing reportExcel = (ReportExcelPeriodColumnListing) reportService - .getReportExcel( selectionManager.getSelectedReportExcelId() ); - - this.installReadTemplateFile( reportExcel, period, organisationUnit ); - - if ( this.sheetId > 0 ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( this.sheetId - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( this.sheetId, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( periods, reportExcelItems, organisationUnit, sheet ); - } - else - { - - for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportExcelId() ) ) - { - HSSFSheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 ); - - Collection reportExcelItems = reportService.getReportExcelItem( sheetNo, - selectionManager.getSelectedReportExcelId() ); - - this.generateOutPutFile( periods, reportExcelItems, organisationUnit, sheet ); - - } - } - - this.complete(); - - statementManager.destroy(); - - return SUCCESS; - } - - private void generateOutPutFile( List periods, Collection reportExcelItems, - OrganisationUnit organisationUnit, HSSFSheet sheet ) - throws Exception - { - for ( ReportExcelItem reportItem : reportExcelItems ) - { - int i = 0; - for ( Period p : periods ) - { - double value = 0.0; - - if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.DATAELEMENT ) ) - { - value = MathUtils.calculateExpression( generateExpression( reportItem, p.getStartDate(), p - .getEndDate(), organisationUnit ) ); - } - else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.INDICATOR ) ) - { - value = MathUtils.calculateExpression( generateExpression( reportItem, p.getStartDate(), p - .getEndDate(), organisationUnit ) ); - } - - ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn() + i, String.valueOf( value ), - ExcelUtils.NUMBER, sheet, this.csNumber ); - i++; - } - } - } -}