← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6766: local vn - Supported in generating the Vertical Category report. Done

 

------------------------------------------------------------
revno: 6766
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-04-27 02:11:23 +0700
message:
  local vn - Supported in generating the Vertical Category report. Done
added:
  local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportVerticalCategoryAction.java
modified:
  local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/ExcelTemplateListAction.java
  local/vn/dhis-web-spreadsheet-reporting/src/main/resources/META-INF/dhis/beans.xml
  local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportVerticalCategoryAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportVerticalCategoryAction.java	1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/exporting/action/GenerateReportVerticalCategoryAction.java	2012-04-26 19:11:23 +0000
@@ -0,0 +1,164 @@
+package org.hisp.dhis.reportsheet.exporting.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.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.poi.ss.usermodel.Sheet;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.reportsheet.CategoryOptionGroupOrder;
+import org.hisp.dhis.reportsheet.ExportItem;
+import org.hisp.dhis.reportsheet.ExportReport;
+import org.hisp.dhis.reportsheet.ExportReportVerticalCategory;
+import org.hisp.dhis.reportsheet.exporting.AbstractGenerateExcelReportSupport;
+import org.hisp.dhis.reportsheet.utils.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class GenerateReportVerticalCategoryAction
+    extends AbstractGenerateExcelReportSupport
+{
+    @Override
+    protected void executeGenerateOutputFile( ExportReport exportReport, Period period )
+        throws Exception
+    {
+        OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
+
+        ExportReportVerticalCategory exportReportInstance = (ExportReportVerticalCategory) exportReport;
+
+        this.installReadTemplateFile( exportReportInstance, period, organisationUnit );
+
+        for ( Integer sheetNo : exportReportService.getSheets( selectionManager.getSelectedReportId() ) )
+        {
+            Sheet sheet = this.templateWorkbook.getSheetAt( sheetNo - 1 );
+
+            Collection<ExportItem> exportReportItems = exportReportInstance.getExportItemBySheet( sheetNo );
+
+            this.generateVerticalOutPutFile( exportReportInstance, exportReportItems, organisationUnit, sheet );
+        }
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive method
+    // -------------------------------------------------------------------------
+
+    private void generateVerticalOutPutFile( ExportReportVerticalCategory exportReport,
+        Collection<ExportItem> exportReportItems, OrganisationUnit organisationUnit, Sheet sheet )
+    {
+        DataElement de = null;
+        Set<DataElementCategoryOptionCombo> optionCombos = new HashSet<DataElementCategoryOptionCombo>();
+
+        for ( ExportItem reportItem : exportReportItems )
+        {
+            int run = 0;
+            int rowBegin = reportItem.getRow();
+
+            if ( reportItem.getItemType().equalsIgnoreCase( ExportItem.TYPE.DATAELEMENT ) )
+            {
+                de = dataElementService.getDataElement( Integer.parseInt( reportItem.getExpression().split( "." )[0] ) );
+                optionCombos = de.getCategoryCombo().getOptionCombos();
+            }
+
+            for ( CategoryOptionGroupOrder group : exportReport.getCategoryOptionGroupOrders() )
+            {
+                int beginChapter = rowBegin;
+
+                if ( reportItem.getItemType().equalsIgnoreCase( ExportItem.TYPE.DATAELEMENT_NAME ) )
+                {
+                    ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), group.getName(), ExcelUtils.TEXT,
+                        sheet, this.csText12BoldCenter );
+                }
+
+                run++;
+                rowBegin++;
+                int serial = 1;
+
+                for ( DataElementCategoryOption categoryOption : group.getCategoryOptions() )
+                {
+                    if ( reportItem.getItemType().equalsIgnoreCase( ExportItem.TYPE.DATAELEMENT_NAME ) )
+                    {
+                        ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), categoryOption.getName(),
+                            ExcelUtils.TEXT, sheet, this.csText10Bold );
+                    }
+                    else if ( reportItem.getItemType().equalsIgnoreCase( ExportItem.TYPE.SERIAL ) )
+                    {
+                        ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( serial ),
+                            ExcelUtils.NUMBER, sheet, this.csTextSerial );
+                    }
+                    else if ( reportItem.getItemType().equalsIgnoreCase( ExportItem.TYPE.FORMULA_EXCEL ) )
+                    {
+                        ExcelUtils.writeFormulaByPOI( rowBegin, reportItem.getColumn(), ExcelUtils
+                            .generateExcelFormula( reportItem.getExpression(), run, run ), sheet, csFormula );
+                    }
+                    else
+                    {
+                        for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                        {
+                            if ( optionCombo.getCategoryOptions().contains( categoryOption ) )
+                            {
+                                ExportItem newReportItem = new ExportItem();
+
+                                String expression = reportItem.getExpression();
+                                expression = expression.replace( "*", String.valueOf( optionCombo.getId() ) );
+
+                                newReportItem.setExpression( expression );
+
+                                double value = this.getDataValue( newReportItem, organisationUnit );
+
+                                ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( value ),
+                                    ExcelUtils.NUMBER, sheet, this.csNumber );
+                                
+                                break;
+                            }
+                        }
+                    }
+
+                    rowBegin++;
+                    serial++;
+                    run++;
+                }
+
+                if ( reportItem.getItemType().equalsIgnoreCase( ExportItem.TYPE.DATAELEMENT ) )
+                {
+                    String columnName = ExcelUtils.convertColumnNumberToName( reportItem.getColumn() );
+                    String formula = "SUM(" + columnName + (beginChapter + 1) + ":" + columnName + (rowBegin - 1) + ")";
+
+                    ExcelUtils.writeFormulaByPOI( beginChapter, reportItem.getColumn(), formula, sheet, this.csFormula );
+                }
+            }
+        }
+    }
+}

=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/ExcelTemplateListAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/ExcelTemplateListAction.java	2012-04-25 09:59:24 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/filemanager/action/ExcelTemplateListAction.java	2012-04-26 19:11:23 +0000
@@ -150,6 +150,7 @@
         this.reportTypes.add( ExportReport.TYPE.NORMAL );
         this.reportTypes.add( ExportReport.TYPE.ATTRIBUTE );
         this.reportTypes.add( ExportReport.TYPE.CATEGORY );
+        this.reportTypes.add( ExportReport.TYPE.CATEGORY_VERTICAL );
         this.reportTypes.add( ExportReport.TYPE.PERIOD_COLUMN_LISTING );
         this.reportTypes.add( ExportReport.TYPE.ORGANIZATION_GROUP_LISTING );
 

=== 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-04-26 18:25:07 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/META-INF/dhis/beans.xml	2012-04-26 19:11:23 +0000
@@ -564,6 +564,11 @@
 		scope="prototype" />
 
 	<bean
+		id="org.hisp.dhis.reportsheet.exporting.action.GenerateReportVerticalCategoryAction"
+		class="org.hisp.dhis.reportsheet.exporting.action.GenerateReportVerticalCategoryAction"
+		scope="prototype" />
+
+	<bean
 		id="org.hisp.dhis.reportsheet.exporting.action.GenerateReportAttributeAction"
 		class="org.hisp.dhis.reportsheet.exporting.action.GenerateReportAttributeAction"
 		scope="prototype" />

=== 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-04-26 18:25:07 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml	2012-04-26 19:11:23 +0000
@@ -708,6 +708,8 @@
 				generateReportAttribute.action</result>
 			<result name="CATEGORY" type="redirect">
 				generateReportCategory.action</result>
+			<result name="CATEGORY_VERTICAL" type="redirect">
+				generateReportVerticalCategory.action</result>
 			<result name="NORMAL" type="redirect">
 				generateReportNormal.action</result>
 			<result name="ORGANIZATION_GROUP_LISTING" type="redirect">
@@ -728,6 +730,12 @@
 				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
 		</action>
 
+		<action name="generateReportVerticalCategory"
+			class="org.hisp.dhis.reportsheet.exporting.action.GenerateReportVerticalCategoryAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+		</action>
+
 		<action name="generateReportNormal"
 			class="org.hisp.dhis.reportsheet.exporting.action.GenerateReportNormalAction">
 			<result name="success" type="velocity-json">
@@ -859,6 +867,8 @@
 				generatePreviewAttribute.action</result>
 			<result name="CATEGORY" type="redirect">
 				generatePreviewCategory.action</result>
+			<result name="CATEGORY_VERTICAL" type="redirect">
+				generatePreviewVerticalCategory.action</result>
 			<result name="NORMAL" type="redirect">
 				generatePreviewNormal.action</result>
 			<result name="ORGANIZATION_GROUP_LISTING" type="redirect">
@@ -879,6 +889,12 @@
 			</result>
 		</action>
 
+		<action name="generatePreviewVerticalCategory"
+			class="org.hisp.dhis.reportsheet.exporting.action.GenerateReportVerticalCategoryAction">
+			<result name="success" type="redirect">exportXML.action
+			</result>
+		</action>
+
 		<action name="generatePreviewNormal"
 			class="org.hisp.dhis.reportsheet.exporting.action.GenerateReportNormalAction">
 			<result name="success" type="redirect">exportXML.action