← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7773: Implemented support for fixed periods in png charts

 

------------------------------------------------------------
revno: 7773
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-07-30 23:04:50 +0200
message:
  Implemented support for fixed periods in png charts
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.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/chart/Chart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2012-07-23 10:50:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2012-07-30 21:04:50 +0000
@@ -53,9 +53,12 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.RelativePeriods;
+import org.hisp.dhis.period.comparator.AscendingPeriodEndDateComparator;
 import org.hisp.dhis.user.User;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -66,6 +69,8 @@
     extends BaseIdentifiableObject
 {
     private static final long serialVersionUID = 2570074075484545534L;
+    
+    private static final Comparator<Period> PERIOD_COMPARATOR = new AscendingPeriodEndDateComparator();
 
     public static final String DIMENSION_PERIOD_INDICATOR = "period";
     public static final String DIMENSION_ORGANISATIONUNIT_INDICATOR = "organisationUnit";
@@ -216,6 +221,23 @@
         List<OrganisationUnit> units = getAllOrganisationUnits();
         return units != null && !units.isEmpty() ? units.iterator().next() : null;
     }
+    
+    public List<Period> getAllPeriods()
+    {
+        List<Period> list = new ArrayList<Period>();
+        
+        list.addAll( relativePeriods );
+        
+        for ( Period period : periods )
+        {
+            if ( !list.contains( period ) )
+            {
+                list.add( period );
+            }
+        }
+        
+        return list;
+    }
 
     private List<NameableObject> dimensionToList( String dimension )
     {
@@ -229,9 +251,10 @@
         }
         else if ( DIMENSION_PERIOD.equals( dimension ) )
         {
-            namePeriods( getRelativePeriods(), format );
-
-            list.addAll( relativePeriods );
+            List<Period> periods = getAllPeriods();
+            namePeriods( periods, format );
+            Collections.sort( periods, PERIOD_COMPARATOR );
+            list.addAll( periods );
         }
         else if ( DIMENSION_ORGANISATIONUNIT.equals( dimension ) )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java	2012-05-28 20:41:19 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java	2012-07-30 21:04:50 +0000
@@ -92,12 +92,12 @@
         if ( chart.isOrganisationUnitGroupBased() )
         {
             return getAggregatedValueMapOrgUnitGroups( chart.getDataElements(), chart.getIndicators(),
-                chart.getRelativePeriods(), chart.getOrganisationUnitGroupSet().getOrganisationUnitGroups(), chart.getFirstOrganisationUnit() );
+                chart.getAllPeriods(), chart.getOrganisationUnitGroupSet().getOrganisationUnitGroups(), chart.getFirstOrganisationUnit() );
         }
         else
         {
             return getAggregatedValueMapOrgUnitHierarchy( chart.getDataElements(), chart.getIndicators(), chart.getDataSets(),
-                chart.getRelativePeriods(), chart.getAllOrganisationUnits(), null, false, false );
+                chart.getAllPeriods(), chart.getAllOrganisationUnits(), null, false, false );
         }
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java	2012-07-30 16:01:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java	2012-07-30 21:04:50 +0000
@@ -135,21 +135,9 @@
         // Periods
         // ---------------------------------------------------------------------
         
-        List<Period> allRelativePeriods = rewind ? relativePeriods.getRewindedRelativePeriods() :
+        List<Period> periods = rewind ? relativePeriods.getRewindedRelativePeriods() :
             relativePeriods.getRelativePeriods();
         
-        List<Period> periods = new ArrayList<Period>();
-        
-        for ( Period period : allRelativePeriods )
-        {
-            if ( periods.contains( period ) )
-            {
-                periods.remove( period );
-            }
-            
-            periods.add( period );
-        }
-
         if ( p != null && p.size() > 0 )
         {
             for ( String iso : p )