← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1248: generate excel report organisation group listing with organisation unit at selected level

 

------------------------------------------------------------
revno: 1248
committer: Tran Thanh Tri <Tran Thanh Tri@compaq>
branch nick: trunk
timestamp: Fri 2009-12-18 16:27:51 +0700
message:
  generate excel report organisation group listing with organisation unit at selected level
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java
  dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/hibernate/ReportExcel.hbm.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportOrganizationGroupListingAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reports.vm


--
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.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java	2009-11-19 18:58:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java	2009-12-18 09:27:51 +0000
@@ -28,11 +28,13 @@
 package org.hisp.dhis.reportexcel;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -48,6 +50,8 @@
     public static final String ID = "id";
 
     private List<OrganisationUnitGroup> organisationUnitGroups;
+    
+    private Map<OrganisationUnitGroup, OrganisationUnitLevel> organisationUnitLevels;
 
     // -------------------------------------------------------------------------
     // Constructors
@@ -61,13 +65,24 @@
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
+    
+    
 
     public List<OrganisationUnitGroup> getOrganisationUnitGroups()
     {
         return organisationUnitGroups;
     }
 
-    public void setOrganisationUnitGroups( List<OrganisationUnitGroup> organisationUnitGroups )
+    public Map<OrganisationUnitGroup, OrganisationUnitLevel> getOrganisationUnitLevels() {
+		return organisationUnitLevels;
+	}
+
+	public void setOrganisationUnitLevels(
+			Map<OrganisationUnitGroup, OrganisationUnitLevel> organisationUnitLevels) {
+		this.organisationUnitLevels = organisationUnitLevels;
+	}
+
+	public void setOrganisationUnitGroups( List<OrganisationUnitGroup> organisationUnitGroups )
     {
         this.organisationUnitGroups = organisationUnitGroups;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/hibernate/ReportExcel.hbm.xml'
--- dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/hibernate/ReportExcel.hbm.xml	2009-12-14 08:26:13 +0000
+++ dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/hibernate/ReportExcel.hbm.xml	2009-12-18 09:27:51 +0000
@@ -53,8 +53,13 @@
 				<key column="reportexcelid" />
 				<list-index column="grouporder" base="0"/>				
 				<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup" column="oganisationunitgroupid"
-				foreign-key="fk_reportexcel_organisationgroup"/>
+				foreign-key="fk_reportexcel_organisationgroup"/>				
 			</list>		
+			<map name="organisationUnitLevels" table="reportexcel_organisationunit_levels">
+				<key column="reportexcelid"/>
+				<index-many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup" column="organisationunitgroupid" foreign-key="fk_organisationunitgroup_level"/>
+				<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitLevel" column="organisationunitlevelid" foreign-key="pk_organisationunitgroup_level"/>
+			</map>
 		</joined-subclass>
 		
 	</class>

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportOrganizationGroupListingAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportOrganizationGroupListingAction.java	2009-12-09 05:55:32 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportOrganizationGroupListingAction.java	2009-12-18 09:27:51 +0000
@@ -29,11 +29,15 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.reportexcel.ReportExcelItem;
@@ -50,6 +54,17 @@
     extends GenerateReportSupport
 {
 
+    // -------------------------------------------
+    // Dependency
+    // -------------------------------------------
+    
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
     @Override
     public String execute()
         throws Exception
@@ -63,6 +78,9 @@
         ReportExcelOganiztionGroupListing reportExcel = (ReportExcelOganiztionGroupListing) reportService
             .getReportExcel( selectionManager.getSelectedReportId() );
 
+        Map<OrganisationUnitGroup, OrganisationUnitLevel> orgUniGroupAtLevels = new HashMap<OrganisationUnitGroup, OrganisationUnitLevel>(
+            reportExcel.getOrganisationUnitLevels() );
+
         this.installReadTemplateFile( reportExcel, period, organisationUnit );
 
         for ( Integer sheetNo : reportService.getSheets( selectionManager.getSelectedReportId() ) )
@@ -71,10 +89,12 @@
 
             Collection<ReportExcelItem> reportExcelItems = reportExcel.getReportItemBySheet( sheetNo );
 
-            this.generateOutPutFile( reportExcel, reportExcelItems, organisationUnit, sheet );
+            this.generateOutPutFile( reportExcel, orgUniGroupAtLevels, reportExcelItems, organisationUnit, sheet );
 
         }
 
+        
+        
         this.complete();
 
         statementManager.destroy();
@@ -83,8 +103,10 @@
     }
 
     private void generateOutPutFile( ReportExcelOganiztionGroupListing reportExcel,
+        Map<OrganisationUnitGroup, OrganisationUnitLevel> orgUniGroupAtLevels,
         Collection<ReportExcelItem> reportExcelItems, OrganisationUnit organisationUnit, HSSFSheet sheet )
     {
+
         for ( ReportExcelItem reportItem : reportExcelItems )
         {
             int rowBegin = reportItem.getRow();
@@ -92,13 +114,31 @@
 
             for ( OrganisationUnitGroup organisationUnitGroup : reportExcel.getOrganisationUnitGroups() )
             {
+
+                OrganisationUnitLevel organisationUnitLevel = orgUniGroupAtLevels.get( organisationUnitGroup );
+                
+                List<OrganisationUnit> organisationUnitsAtLevel = new ArrayList<OrganisationUnit>();
+              
+
                 List<OrganisationUnit> childrenOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnit
                     .getChildren() );
 
                 List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitGroup
                     .getMembers() );
 
-                organisationUnits.retainAll( childrenOrganisationUnits );
+                
+                
+                if ( organisationUnitLevel != null )
+                {
+                    organisationUnitsAtLevel = new ArrayList<OrganisationUnit>(organisationUnitService.getOrganisationUnitsAtLevel( organisationUnitLevel.getLevel(), organisationUnit ));
+                    
+                    organisationUnits.retainAll( organisationUnitsAtLevel );
+                    
+                }else{
+                    
+                    organisationUnits.retainAll( childrenOrganisationUnits );
+                }                
+                
 
                 Collections.sort( organisationUnits, new OrganisationUnitNameComparator() );
 
@@ -108,13 +148,13 @@
                     && (!organisationUnits.isEmpty()) )
                 {
                     ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), String.valueOf( organisationUnitGroup
-                        .getName() ), ExcelUtils.TEXT, sheet, this.csText12BoldCenter);
+                        .getName() ), ExcelUtils.TEXT, sheet, this.csText12BoldCenter );
                 }
                 else if ( reportItem.getItemType().equalsIgnoreCase( ReportExcelItem.TYPE.SERIAL )
                     && (!organisationUnits.isEmpty()) )
                 {
                     ExcelUtils.writeValueByPOI( rowBegin, reportItem.getColumn(), chappter[chapperNo], ExcelUtils.TEXT,
-                        sheet, this.csText12BoldCenter);
+                        sheet, this.csText12BoldCenter );
                 }
                 chapperNo++;
                 rowBegin++;

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-12-11 04:27:39 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-12-18 09:27:51 +0000
@@ -124,7 +124,8 @@
 	<bean id="org.hisp.dhis.reportexcel.action.GetReportExcelAction"
 		class="org.hisp.dhis.reportexcel.action.GetReportExcelAction" scope="prototype">
 		<property name="reportService" ref="org.hisp.dhis.reportexcel.ReportExcelService" />
-		<property name="selectionManager" ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
+		<property name="selectionManager"
+			ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
 	</bean>
 
 	<bean id="org.hisp.dhis.reportexcel.action.GetReportExcelGroupsAction"
@@ -269,7 +270,8 @@
 		scope="prototype">
 		<property name="reportService" ref="org.hisp.dhis.reportexcel.ReportExcelService" />
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
-		<property name="selectionManager" ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
+		<property name="selectionManager"
+			ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
 	</bean>
 
 	<bean
@@ -291,6 +293,26 @@
 	</bean>
 
 	<bean
+		id="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.ListOrganisationUnitGroupAtLevelAction"
+		class="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.ListOrganisationUnitGroupAtLevelAction"
+		scope="prototype">
+		<property name="reportService" ref="org.hisp.dhis.reportexcel.ReportExcelService" />
+		<property name="organisationUnitService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+	</bean>
+
+	<bean
+		id="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.UpdateOrganisationUnitGroupAtLevelAction"
+		class="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.UpdateOrganisationUnitGroupAtLevelAction"
+		scope="prototype">
+		<property name="reportService" ref="org.hisp.dhis.reportexcel.ReportExcelService" />
+		<property name="organisationUnitService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+		<property name="organisationUnitGroupService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+	</bean>
+
+	<bean
 		id="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.UpdateOrganisationUnitGroupAction"
 		class="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.UpdateOrganisationUnitGroupAction"
 		scope="prototype">
@@ -377,7 +399,7 @@
 		<property name="organisationUnitSelectionManager"
 			ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
 		<property name="periodDatabaseService"
-			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />		
+			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 	</bean>
 
 	<bean
@@ -423,9 +445,11 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />	
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
+		<property name="organisationUnitService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />	
 	</bean>
-	
+
 	<bean
 		id="org.hisp.dhis.reportexcel.export.action.GenerateReportNormalAction"
 		class="org.hisp.dhis.reportexcel.export.action.GenerateReportNormalAction"
@@ -448,9 +472,9 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />	
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
-	
+
 	<bean
 		id="org.hisp.dhis.reportexcel.export.action.GenerateReportCategoryAction"
 		class="org.hisp.dhis.reportexcel.export.action.GenerateReportCategoryAction"
@@ -473,10 +497,10 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />	
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
-	
-	
+
+
 	<bean
 		id="org.hisp.dhis.reportexcel.export.action.GenerateReportPeriodColumnListingAction"
 		class="org.hisp.dhis.reportexcel.export.action.GenerateReportPeriodColumnListingAction"
@@ -499,7 +523,7 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />	
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
 
 	<!-- DATA ENTRY STATUS BEAN -->
@@ -631,8 +655,7 @@
 	<bean id="org.hisp.dhis.reportexcel.preview.action.ExportXMLAction"
 		class="org.hisp.dhis.reportexcel.preview.action.ExportXMLAction"
 		scope="prototype">
-		<property name="reportService"
-			ref="org.hisp.dhis.reportexcel.ReportExcelService" />
+		<property name="reportService" ref="org.hisp.dhis.reportexcel.ReportExcelService" />
 		<property name="selectionManager"
 			ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
 	</bean>
@@ -683,7 +706,7 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />		
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
 
 	<bean
@@ -710,7 +733,7 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />		
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
 
 	<bean
@@ -737,7 +760,7 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />		
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
 
 	<bean
@@ -764,7 +787,7 @@
 		<property name="periodDatabaseService"
 			ref="org.hisp.dhis.reportexcel.period.db.PeriodDatabaseService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />		
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
 
 	<!-- INDIVIDUAL REPORT EXCEL -->
@@ -806,7 +829,7 @@
 		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 		<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
 		<property name="initPOIStylesManager"
-			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />	
+			ref="org.hisp.dhis.reportexcel.preview.manager.InitializePOIStylesManager" />
 	</bean>
 
 	<!-- Clean up Report Excel module -->

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2009-12-17 02:15:50 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2009-12-18 09:27:51 +0000
@@ -177,4 +177,6 @@
 list_of_excel_items         = List of excel items
 selected_dataelements		= Selected Data Elements
 available_dataelements		= Available Data Elements
-value_rounded               = This value maybe have been rounded
\ No newline at end of file
+value_rounded               = This value maybe have been rounded
+level_and_orgunit_group 	= Level and Organisation Unit Group
+levels						= Level
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2009-12-16 03:37:57 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2009-12-18 09:27:51 +0000
@@ -265,6 +265,18 @@
 			<result name="success" type="redirect">listReportExcel.action
 			</result>
 		</action>
+		
+		<action name="organisationUnitAtLevels"
+			class="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.ListOrganisationUnitGroupAtLevelAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-excel-reporting/organisationUnitAtLevels.vm</param>
+			<param name="menu">/dhis-web-excel-reporting/menu.vm</param>		
+		</action>
+		
+		<action name="updateOrganisationUnitGroupAtLevel"
+			class="org.hisp.dhis.reportexcel.organisationunitgrouplisting.action.UpdateOrganisationUnitGroupAtLevelAction">
+			<result name="success" type="velocity-xml">/dhis-web-excel-reporting/responseSuccess.vm</result>
+		</action>
 
 		<!-- REPORT EXCEL ASSOCIATION ACTION -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reports.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reports.vm	2009-11-13 10:28:52 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reports.vm	2009-12-18 09:27:51 +0000
@@ -22,7 +22,7 @@
 		<th>$i18n.getString('name')</th>
 		<th>$i18n.getString('report_type')</th>
 		<th>$i18n.getString('excel_template')</th>		
-		<th width="150px">$i18n.getString('operations')</th>		
+		<th width="170px">$i18n.getString('operations')</th>		
 	</tr>
 	<tbody id="list">
 	#set( $mark = false )
@@ -41,10 +41,10 @@
 				-->
 				#if($report.isOrganisationUnitGroupListing())
 				<a href="openUpdateOrgnisationUnitGroupListingReport.action?id=$report.id" title="$i18n.getString( 'organisation_unit_group' )"><img src="images/group_1.jpg"/></a>
+				<a href="organisationUnitAtLevels.action?id=$report.id" title="$i18n.getString( 'set_organisationunit_group_level' )"><img src="images/organisationunitlevel.png" alt="$i18n.getString( 'set_organisationunit_group_level' )"/></a>				
 				#end
 				#if($report.isCategory())				
-				<a href="listDataElementGroupOrder.action?id=$report.id" title="$i18n.getString( 'dataelement_groups' )"><img src="images/group.jpg"/></a>
-				
+				<a href="listDataElementGroupOrder.action?id=$report.id" title="$i18n.getString( 'dataelement_groups' )"><img src="images/group.jpg"/></a>				
 				#end
 				
 				#if($report.isPeriodColumnListing())