← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10939: Impl report parameters for report table properly

 

------------------------------------------------------------
revno: 10939
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-05-22 18:37:59 +0200
message:
  Impl report parameters for report table properly
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java


--
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/common/BaseAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2013-05-22 11:27:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2013-05-22 16:37:59 +0000
@@ -39,6 +39,7 @@
 import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_CHILDREN;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -67,6 +68,7 @@
 import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
 import org.hisp.dhis.user.User;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonView;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -137,6 +139,8 @@
     // -------------------------------------------------------------------------
 
     protected transient List<OrganisationUnit> transientOrganisationUnits = new ArrayList<OrganisationUnit>();
+        
+    protected transient Date relativePeriodDate;
     
     // -------------------------------------------------------------------------
     // Logic
@@ -154,7 +158,7 @@
         return relatives != null && !relatives.isEmpty();
     }
     
-    protected void addTransientOrganisationUnits( List<OrganisationUnit> organisationUnits )
+    protected void addTransientOrganisationUnits( Collection<OrganisationUnit> organisationUnits )
     {
         if ( organisationUnits != null )
         {
@@ -162,6 +166,14 @@
         }
     }
     
+    protected void addTransientOrganisationUnit( OrganisationUnit organisationUnit )
+    {
+        if ( organisationUnit != null )
+        {
+            this.transientOrganisationUnits.add( organisationUnit );
+        }
+    }
+    
     /**
      * Assembles a DimensionalObject. Collapses indicators, data elements, data
      * element operands and data sets into the dx dimension.
@@ -607,6 +619,16 @@
     }
 
     // -------------------------------------------------------------------------
+    // Transient properties
+    // -------------------------------------------------------------------------
+
+    @JsonIgnore
+    public Date getRelativePeriodDate()
+    {
+        return relativePeriodDate;
+    }
+
+    // -------------------------------------------------------------------------
     // Web domain properties
     // -------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2013-05-22 15:57:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2013-05-22 16:37:59 +0000
@@ -756,7 +756,7 @@
      * @param relativePeriods a list of RelativePeriodsEnum.
      * @return a RelativePeriods instance.
      */
-    public static List<Period> getRelativePeriodsFromEnum( RelativePeriodEnum relativePeriod, I18nFormat format, boolean dynamicNames )
+    public static List<Period> getRelativePeriodsFromEnum( RelativePeriodEnum relativePeriod, Date date, I18nFormat format, boolean dynamicNames )
     {
         Map<RelativePeriodEnum, RelativePeriods> map = new HashMap<RelativePeriodEnum, RelativePeriods>();
         
@@ -784,7 +784,7 @@
         map.put( RelativePeriodEnum.LAST_12_WEEKS, new RelativePeriods().setLast12Weeks( true ) );
         map.put( RelativePeriodEnum.LAST_52_WEEKS, new RelativePeriods().setLast52Weeks( true ) );
         
-        return map.containsKey( relativePeriod ) ? map.get( relativePeriod ).getRelativePeriods( format, dynamicNames ) : null;
+        return map.containsKey( relativePeriod ) ? map.get( relativePeriod ).getRelativePeriods( date, format, dynamicNames ) : null;
     }
     
     /**

=== 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	2013-05-22 13:14:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2013-05-22 16:37:59 +0000
@@ -353,11 +353,34 @@
     // Init
     // -------------------------------------------------------------------------
 
-    public void init( User user, Date date, List<OrganisationUnit> relativeOrganisationUnits, I18nFormat format )
+    public void init( User user, Date date, OrganisationUnit organisationUnit, I18nFormat format )
     {
         verify( ( periods != null && !periods.isEmpty() ) || hasRelativePeriods(), "Must contain periods or relative periods" );
 
-        addTransientOrganisationUnits( relativeOrganisationUnits );
+        this.relativePeriodDate = date;
+        
+        // Handle report parameters
+        
+        if ( hasRelativePeriods() )
+        {
+            this.reportingPeriodName = relatives.getReportingPeriodName( date, format );
+        }
+
+        if ( organisationUnit != null && hasReportParams() && reportParams.isParamParentOrganisationUnit() )
+        {
+            organisationUnit.setCurrentParent( true );
+            this.parentOrganisationUnit = organisationUnit;
+            addTransientOrganisationUnits( organisationUnit.getChildren() );
+            addTransientOrganisationUnit( organisationUnit );
+        }
+
+        if ( organisationUnit != null && hasReportParams() && reportParams.isParamOrganisationUnit() )
+        {
+            this.parentOrganisationUnit = organisationUnit;
+            addTransientOrganisationUnit( organisationUnit );
+        }
+
+        // Populate grid
         
         this.populateGridColumnsAndRows( date, user, format );
         
@@ -367,7 +390,9 @@
             verify( nonEmptyLists( categoryOptionCombos ) == 1, "Category option combos size must be larger than 0" );
         }
 
-        addIfEmpty( gridColumns ); // Allow for all or none crosstab dimensions
+        // Allow for no columns or rows
+        
+        addIfEmpty( gridColumns ); 
         addIfEmpty( gridRows );
     }
     

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-05-19 18:49:47 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-05-22 16:37:59 +0000
@@ -56,6 +56,7 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -494,7 +495,7 @@
                 
                 if ( dimension != null && options != null )
                 {
-                    params.getDimensions().addAll( getDimension( dimension, options, format ) );
+                    params.getDimensions().addAll( getDimension( dimension, options, null, format ) );
                 }
             }
         }
@@ -508,7 +509,7 @@
                 
                 if ( dimension != null && options != null )
                 {
-                    params.getFilters().addAll( getDimension( dimension, options, format ) );
+                    params.getFilters().addAll( getDimension( dimension, options, null, format ) );
                 }
             }
         }
@@ -528,21 +529,23 @@
         
         if ( object != null )
         {
+            Date date = object.getRelativePeriodDate();
+            
             object.populateAnalyticalProperties();
             
             for ( DimensionalObject column : object.getColumns() )
             {
-                params.getDimensions().addAll( getDimension( toDimension( column.getDimension() ), getUids( column.getItems() ), format ) );
+                params.getDimensions().addAll( getDimension( toDimension( column.getDimension() ), getUids( column.getItems() ), date, format ) );
             }
             
             for ( DimensionalObject row : object.getRows() )
             {
-                params.getDimensions().addAll( getDimension( toDimension( row.getDimension() ), getUids( row.getItems() ), format ) );
+                params.getDimensions().addAll( getDimension( toDimension( row.getDimension() ), getUids( row.getItems() ), date, format ) );
             }
             
             for ( DimensionalObject filter : object.getFilters() )
             {
-                params.getFilters().addAll( getDimension( toDimension( filter.getDimension() ), getUids( filter.getItems() ), format ) );
+                params.getFilters().addAll( getDimension( toDimension( filter.getDimension() ), getUids( filter.getItems() ), date, format ) );
             }
         }
         
@@ -563,9 +566,15 @@
      * replaced by real ISO periods relative to the current date. For the ou 
      * dimension items, the user  organisation unit enums 
      * USER_ORG_UNIT|USER_ORG_UNIT_CHILDREN will be replaced by the persisted 
-     * organisation units for the current user. 
+     * organisation units for the current user.
+     * 
+     * @param dimension the dimension identifier.
+     * @param items the dimension items.
+     * @param relativePeriodDate the date to use for generating relative periods, can be null.
+     * @parma format the I18nFormat, can be null.
+     * @return list of DimensionalObjects.
      */
-    private List<DimensionalObject> getDimension( String dimension, List<String> items, I18nFormat format )
+    private List<DimensionalObject> getDimension( String dimension, List<String> items, Date relativePeriodDate, I18nFormat format )
     {        
         if ( DATA_X_DIM_ID.equals( dimension ) )
         {
@@ -643,7 +652,7 @@
                 if ( RelativePeriodEnum.contains( isoPeriod ) )
                 {
                     RelativePeriodEnum relativePeriod = RelativePeriodEnum.valueOf( isoPeriod );
-                    periods.addAll( RelativePeriods.getRelativePeriodsFromEnum( relativePeriod, format, true ) );
+                    periods.addAll( RelativePeriods.getRelativePeriodsFromEnum( relativePeriod, relativePeriodDate, format, true ) );
                 }
                 else
                 {

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2013-05-22 13:14:47 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2013-05-22 16:37:59 +0000
@@ -34,7 +34,6 @@
 import static org.hisp.dhis.reporttable.ReportTable.getColumnName;
 import static org.hisp.dhis.reporttable.ReportTable.getPrettyColumnName;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -122,9 +121,13 @@
     @Override
     public Grid getReportTableGrid( String uid, I18nFormat format, Date reportingPeriod, String organisationUnitUid )
     {
+        log.info( "Generating report table grid: " + uid + ", date: " + reportingPeriod + ", ou: " + organisationUnitUid );
+        
         ReportTable reportTable = getReportTable( uid );
-
-        reportTable = initDynamicMetaObjects( reportTable, reportingPeriod, organisationUnitUid, format );
+                
+        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
+                
+        reportTable.init( currentUserService.getCurrentUser(), reportingPeriod, organisationUnit, format );
 
         return getGrid( reportTable, format );
     }
@@ -226,80 +229,6 @@
     // -------------------------------------------------------------------------
 
     /**
-     * Populates the report table with dynamic meta objects originating from
-     * report table parameters.
-     *
-     * @param reportTable        the report table.
-     * @param reportingPeriod    the reporting period start date.
-     * @param organisationUnitId the organisation unit identifier.
-     * @param format             the I18n format.
-     * @return a report table.
-     */
-    private ReportTable initDynamicMetaObjects( ReportTable reportTable, Date reportingPeriod,
-        String organisationUnitUid, I18nFormat format )
-    {
-        // ---------------------------------------------------------------------
-        // Reporting period report parameter / current reporting period
-        // ---------------------------------------------------------------------
-
-        log.info( "Running report table: " + reportTable.getName() );
-
-        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
-        
-        List<OrganisationUnit> relativeOrganisationUnits = new ArrayList<OrganisationUnit>();
-        
-        if ( reportTable.hasRelativePeriods() && reportTable.getReportParams() != null && reportTable.getReportParams().isParamReportingMonth() )
-        {
-            reportTable.setReportingPeriodName( reportTable.getRelatives().getReportingPeriodName( reportingPeriod,
-                format ) );
-
-            log.info( "Reporting period date from report param: " + reportTable.getReportingPeriodName() );
-        }
-        else if ( reportTable.hasRelativePeriods() )
-        {
-            reportTable.setReportingPeriodName( reportTable.getRelatives().getReportingPeriodName( format ) );
-
-            log.info( "Reporting period date default: " + reportTable.getReportingPeriodName() );
-        }
-
-        // ---------------------------------------------------------------------
-        // Parent organisation unit report parameter
-        // ---------------------------------------------------------------------
-
-        if ( reportTable.getReportParams() != null &&
-            reportTable.getReportParams().isParamParentOrganisationUnit() )
-        {
-            organisationUnit.setCurrentParent( true );
-            reportTable.setParentOrganisationUnit( organisationUnit );
-            relativeOrganisationUnits.addAll( organisationUnit.getChildren() );
-            relativeOrganisationUnits.add( organisationUnit );
-
-            log.info( "Parent organisation unit: " + organisationUnit.getName() );
-        }
-
-        // ---------------------------------------------------------------------
-        // Organisation unit report parameter
-        // ---------------------------------------------------------------------
-
-        if ( reportTable.getReportParams() != null &&
-            reportTable.getReportParams().isParamOrganisationUnit() )
-        {
-            reportTable.setParentOrganisationUnit( organisationUnit );
-            relativeOrganisationUnits.add( organisationUnit );
-
-            log.info( "Organisation unit: " + organisationUnit.getName() );
-        }
-
-        // ---------------------------------------------------------------------
-        // Set properties and initalize
-        // ---------------------------------------------------------------------
-
-        reportTable.init( currentUserService.getCurrentUser(), reportingPeriod, relativeOrganisationUnits, format );
-
-        return reportTable;
-    }
-
-    /**
      * Generates a grid based on the given report table.
      *
      * @param reportTable the report table.