← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4562: Made one parameter for each compolsory organisation unit group set avialable for jasper report du...

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4562 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-09-11 20:54:20 +0200
message:
  Made one parameter for each compolsory organisation unit group set avialable for jasper report during report generation. This parameter is a mapping between the identifiers of the organisation units in the current report table and the name of the group in each of the group sets. This is useful for filtering organisation units in reports.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-support/dhis-support-system/src/main/resources/grid.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/SessionUtils.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.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
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-09-06 11:52:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-09-11 14:24:44 +0000
@@ -380,7 +380,7 @@
 
         return group != null ? group.getName() : null;
     }
-
+    
     public String getAncestorNames()
     {
         StringBuilder builder = new StringBuilder( name );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2011-07-22 04:09:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2011-09-11 18:19:48 +0000
@@ -29,6 +29,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -48,6 +49,7 @@
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
@@ -69,53 +71,34 @@
     private static final long serialVersionUID = 5618655666320890565L;
 
     public static final String DATAELEMENT_ID = "dataelementid";
-
     public static final String DATAELEMENT_NAME = "dataelementname";
-
     public static final String CATEGORYCOMBO_ID = "categoryoptioncomboid";
-
     public static final String CATEGORYCOMBO_NAME = "categoryoptioncomboname";
-
     public static final String CATEGORYOPTION_ID = "categoryoptionid";
-
     public static final String CATEGORYOPTION_NAME = "categoryoptionname";
-
     public static final String INDICATOR_ID = "indicatorid";
-
     public static final String INDICATOR_NAME = "indicatorname";
-
     public static final String DATASET_ID = "datasetid";
-
     public static final String DATASET_NAME = "datasetname";
-
     public static final String PERIOD_ID = "periodid";
-
     public static final String PERIOD_NAME = "periodname";
-
     public static final String ORGANISATIONUNIT_ID = "organisationunitid";
-
     public static final String ORGANISATIONUNIT_NAME = "organisationunitname";
-
     public static final String REPORTING_MONTH_COLUMN_NAME = "reporting_month_name";
-
     public static final String PARAM_ORGANISATIONUNIT_COLUMN_NAME = "param_organisationunit_name";
-
     public static final String ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME = "organisation_unit_is_parent";
 
     public static final String SEPARATOR = "_";
-
     public static final String SPACE = " ";
+    public static final String KEY_ORGUNIT_GROUPSET = "orgunit_groupset_";
 
     public static final String TOTAL_COLUMN_NAME = "total";
-
     public static final String TOTAL_COLUMN_PRETTY_NAME = "Total";
 
     public static final int ASC = -1;
-
     public static final int DESC = 1;
-
     public static final int NONE = 0;
-
+    
     public static final Map<String, String> PRETTY_COLUMNS = new HashMap<String, String>()
     {
         private static final long serialVersionUID = 4194194769957136714L;
@@ -410,9 +393,7 @@
         allPeriods.addAll( relativePeriods );
         allPeriods = removeDuplicates( allPeriods );
 
-        Collections.sort( allPeriods, new AscendingPeriodComparator() ); // Sort
-        // periods
-        // ascending
+        Collections.sort( allPeriods, new AscendingPeriodComparator() );
         setNames( allPeriods ); // Set names on periods
 
         allUnits.addAll( units );
@@ -464,7 +445,35 @@
             addReportTableGroup( group );
         }
     }
-
+    
+    /**
+     * Creates a map which contains mappings between the organisation unit
+     * identifier and the name of the group this organisation unit is a member
+     * of in all of the given group sets for all organisation units in this
+     * report table.
+     * 
+     * @param groupSets the collection of organisation unit group sets.
+     * @return a map.
+     */
+    public Map<String, Object> getOrganisationUnitGroupMap( Collection<OrganisationUnitGroupSet> groupSets )
+    {
+        Map<String, Object> organisationUnitGroupMap = new HashMap<String, Object>();
+        
+        for ( OrganisationUnitGroupSet groupSet: groupSets )
+        {
+            Map<Integer, String> map = new HashMap<Integer, String>();
+            
+            for ( OrganisationUnit unit : allUnits )
+            {
+                map.put( unit.getId(), unit.getGroupNameInGroupSet( groupSet ) );
+            }
+            
+            organisationUnitGroupMap.put( columnEncode( KEY_ORGUNIT_GROUPSET + groupSet.getName() ), map );
+        }
+        
+        return organisationUnitGroupMap;
+    }
+        
     /**
      * Indicates whether this ReportTable is multi-dimensional.
      */
@@ -519,14 +528,11 @@
         {
             if ( object != null && object instanceof Period )
             {
-                buffer.append( object.getName() + SEPARATOR ); // Relative
-                // periods must
-                // have static
-                // names when
-                // crosstabbed -
-                // which are set
-                // on name
-                // property
+                // -------------------------------------------------------------
+                // Periods need static names when crosstab - set on name prop
+                // -------------------------------------------------------------
+
+                buffer.append( object.getName() + SEPARATOR );
             }
             else
             {
@@ -593,8 +599,7 @@
     {
         List<String> ids = Arrays.asList( identifiers );
 
-        Collections.sort( ids ); // Sort to remove the significance of the
-        // order
+        Collections.sort( ids ); // Sort to remove the significance of order
 
         return StringUtils.join( ids, SEPARATOR );
     }
@@ -734,12 +739,11 @@
         {
             if ( period.getName() == null ) // Crosstabulated relative periods
             {
-                period.setName( i18nFormat.formatPeriod( period ) ); // Static
-                // periods
-                // +
-                // indexed
-                // relative
-                // periods
+                // -------------------------------------------------------------
+                // Static periods + index relative periods
+                // -------------------------------------------------------------
+
+                period.setName( i18nFormat.formatPeriod( period ) );
                 period.setShortName( i18nFormat.formatPeriod( period ) );
             }
         }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/resources/grid.vm'
--- dhis-2/dhis-support/dhis-support-system/src/main/resources/grid.vm	2011-07-12 12:15:23 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/resources/grid.vm	2011-09-11 18:19:48 +0000
@@ -2,7 +2,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"; name="dpt" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
 	#foreach ( $key in $params.keySet() )
-	<parameter name="${encoder.xmlEncode( ${key} )}" class="java.lang.Double"/>
+	<parameter name="${encoder.xmlEncode( ${key} )}" #if ( ${params.get($key)} )class="${params.get($key).getClass().getName()}"#end/>
 	#end
 	#foreach( $header in $grid.getHeaders() )
 	<field name="${encoder.xmlEncode( ${header.column} )}" class="${header.type}"/>

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java	2011-07-12 12:15:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java	2011-09-11 18:19:48 +0000
@@ -65,9 +65,9 @@
         this.grid = grid;
     }
     
-    private Map<?, ?> params;
+    private Map<Object, Object> params;
 
-    public void setParams( Map<?, ?> params )
+    public void setParams( Map<Object, Object> params )
     {
         this.params = params;
     }
@@ -77,6 +77,7 @@
     // -------------------------------------------------------------------------
 
     @Override
+    @SuppressWarnings("unchecked")
     public void execute( ActionInvocation invocation )
         throws Exception
     {
@@ -88,7 +89,7 @@
         
         grid = _grid != null ? _grid : grid;
         
-        Map<?, ?> _params = (Map<?, ?>) invocation.getStack().findValue( "params" );
+        Map<Object, Object> _params = (Map<Object, Object>) invocation.getStack().findValue( "params" );
 
         params = _params != null ? _params : params;
         

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java	2011-07-12 12:15:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java	2011-09-11 18:19:48 +0000
@@ -66,9 +66,9 @@
         this.grid = grid;
     }
 
-    private Map<?, ?> params;
+    private Map<Object, Object> params;
 
-    public void setParams( Map<?, ?> params )
+    public void setParams( Map<Object, Object> params )
     {
         this.params = params;
     }
@@ -78,6 +78,7 @@
     // -------------------------------------------------------------------------
 
     @Override
+    @SuppressWarnings("unchecked")
     public void execute( ActionInvocation invocation )
         throws Exception
     {
@@ -89,7 +90,7 @@
         
         grid = _grid != null ? _grid : grid; 
 
-        Map<?, ?> _params = (Map<?, ?>) invocation.getStack().findValue( "params" );
+        Map<Object, Object> _params = (Map<Object, Object>) invocation.getStack().findValue( "params" );
 
         params = _params != null ? _params : params;
         

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/SessionUtils.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/SessionUtils.java	2011-05-31 11:18:52 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/SessionUtils.java	2011-09-11 18:19:48 +0000
@@ -39,6 +39,7 @@
     public static final String KEY_PREVIEW_STATUS = "previewStatus";    
     public static final String KEY_CURRENT_YEAR = "currentYear";
     public static final String KEY_REPORT_TABLE_GRID = "lastReportTableGrid";
+    public static final String KEY_REPORT_TABLE_PARAMS = "lastReportTableParams";
     public static final String KEY_DATASET_REPORT_GRID = "lastDataSetReportGrid";
     
     public static Object getSessionVar( String name )

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java	2011-07-12 12:15:23 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java	2011-09-11 18:19:48 +0000
@@ -31,6 +31,7 @@
 
 import java.io.OutputStream;
 import java.sql.Connection;
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
@@ -44,6 +45,7 @@
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.report.ReportService;
 import org.hisp.dhis.reporttable.ReportTable;
@@ -87,14 +89,21 @@
     {
         this.constantService = constantService;
     }
-
+    
     private StatementManager statementManager;
 
     public void setStatementManager( StatementManager statementManager )
     {
         this.statementManager = statementManager;
     }
-    
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
     private I18nFormat format;
 
     public void setFormat( I18nFormat format )
@@ -146,8 +155,10 @@
         
         Report report = reportService.getReport( id );
         
-        Map<String, Double> constantMap = constantService.getConstantParameterMap();
+        Map<Object, Object> params = new HashMap<Object, Object>();
         
+        params.putAll( constantService.getConstantParameterMap() );
+                
         JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report.getDesignContent() ) );
         
         JasperPrint print = null;
@@ -156,9 +167,11 @@
         {
             ReportTable reportTable = report.getReportTable();
             
+            params.putAll( reportTable.getOrganisationUnitGroupMap( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() ) );
+            
             Grid grid = reportTableService.getReportTableGrid( reportTable.getId(), format, reportingPeriod, organisationUnitId );
             
-            print = JasperFillManager.fillReport( jasperReport, constantMap, grid );
+            print = JasperFillManager.fillReport( jasperReport, params, grid );
         }
         else // Assume SQL report and provide JDBC connection
         {
@@ -166,7 +179,7 @@
             
             try
             {
-                print = JasperFillManager.fillReport( jasperReport, constantMap, connection );
+                print = JasperFillManager.fillReport( jasperReport, params, connection );
             }
             finally
             {        

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java	2011-07-12 12:15:23 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java	2011-09-11 18:19:48 +0000
@@ -27,11 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
 import org.hisp.dhis.util.SessionUtils;
 
@@ -63,6 +66,13 @@
         this.constantService = constantService;
     }
 
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
     private I18nFormat format;
 
     public void setFormat( I18nFormat format )
@@ -120,9 +130,9 @@
         return grid;
     }
 
-    private Map<?, ?> params;
+    private Map<Object, Object> params = new HashMap<Object, Object>();
 
-    public Map<?, ?> getParams()
+    public Map<Object, Object> getParams()
     {
         return params;
     }
@@ -132,21 +142,27 @@
     // -------------------------------------------------------------------------
 
     @Override
+    @SuppressWarnings("unchecked")
     public String execute()
         throws Exception
     {
         if ( useLast )
         {
             grid = (Grid) SessionUtils.getSessionVar( SessionUtils.KEY_REPORT_TABLE_GRID );
+            params = (Map<Object, Object>) SessionUtils.getSessionVar( SessionUtils.KEY_REPORT_TABLE_PARAMS );
         }
         else
         {
-            grid = reportTableService.getReportTableGrid( id, format, reportingPeriod, organisationUnitId );            
+            ReportTable reportTable = reportTableService.getReportTable( id );
+            
+            grid = reportTableService.getReportTableGrid( id, format, reportingPeriod, organisationUnitId );
+            
+            params.putAll( constantService.getConstantParameterMap() );
+            params.putAll( reportTable.getOrganisationUnitGroupMap( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() ) );
         }
 
-        params = constantService.getConstantParameterMap();
-        
         SessionUtils.setSessionVar( SessionUtils.KEY_REPORT_TABLE_GRID, grid );
+        SessionUtils.setSessionVar( SessionUtils.KEY_REPORT_TABLE_PARAMS, params );
         
         return type != null ? type : DEFAULT_TYPE;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-07-21 09:09:42 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-09-11 18:19:48 +0000
@@ -203,6 +203,7 @@
     scope="prototype">
     <property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService" />
 	<property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
+	<property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService"/>
   </bean>
 
   <bean id="org.hisp.dhis.reporting.tablecreator.action.GetCategoryComboDataElementsAction" class="org.hisp.dhis.reporting.tablecreator.action.GetCategoryComboDataElementsAction"
@@ -290,6 +291,7 @@
     <property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService" />
 	<property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
     <property name="statementManager" ref="statementManager" />
+	<property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
   </bean>
 
   <bean id="org.hisp.dhis.reporting.reportviewer.action.GetReportDesignAction" class="org.hisp.dhis.reporting.reportviewer.action.GetReportDesignAction"