← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16343: convert partition periods to local date, needed to match analytics_* tables, fixes issues with ag...

 

------------------------------------------------------------
revno: 16343
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-08-07 23:50:09 +0700
message:
  convert partition periods to local date, needed to match analytics_* tables, fixes issues with aggregation in other calendars
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.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-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java	2014-06-27 08:38:40 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java	2014-08-07 16:50:09 +0000
@@ -28,88 +28,90 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.analytics.Partitions;
+import org.hisp.dhis.calendar.DateUnit;
 import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.period.YearlyPeriodType;
 import org.hisp.dhis.system.util.UniqueArrayList;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
 /**
  * @author Lars Helge Overland
  */
 public class PartitionUtils
 {
     private static final YearlyPeriodType PERIODTYPE = new YearlyPeriodType();
-    
+
     private static final String SEP = "_";
 
     public static List<Period> getPeriods( Date earliest, Date latest )
     {
         List<Period> periods = new ArrayList<Period>();
-        
+
         Period period = PERIODTYPE.createPeriod( earliest );
-        
+
         while ( period != null && period.getStartDate().before( latest ) )
         {
-            periods.add( period );            
+            periods.add( period );
             period = PERIODTYPE.getNextPeriod( period );
         }
-        
+
         return periods;
     }
 
     //TODO optimize by including required filter periods only
-    
+
     public static Partitions getPartitions( Period period, String tablePrefix, String tableSuffix, Set<String> validPartitions )
     {
         tablePrefix = StringUtils.trimToEmpty( tablePrefix );
         tableSuffix = StringUtils.trimToEmpty( tableSuffix );
 
         Partitions partitions = new Partitions();
-        
-        int startYear = year( period.getStartDate() );
-        int endYear = year( period.getEndDate() );
-        
+
+        int startYear = PeriodType.getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) ).getYear();
+        int endYear = PeriodType.getCalendar().fromIso( DateUnit.fromJdkDate( period.getEndDate() ) ).getYear();
+
         while ( startYear <= endYear )
         {
-            String name = tablePrefix + SEP + startYear + tableSuffix;            
+            String name = tablePrefix + SEP + startYear + tableSuffix;
             partitions.add( name.toLowerCase() );
             startYear++;
         }
 
         return partitions.prunePartitions( validPartitions );
     }
-    
+
     public static Partitions getPartitions( List<NameableObject> periods, String tablePrefix, String tableSuffix, Set<String> validPartitions )
     {
         UniqueArrayList<String> partitions = new UniqueArrayList<String>();
-        
+
         for ( NameableObject period : periods )
         {
             partitions.addAll( getPartitions( (Period) period, tablePrefix, tableSuffix, null ).getPartitions() );
         }
-        
+
         return new Partitions( new ArrayList<String>( partitions ) ).prunePartitions( validPartitions );
     }
-    
+
     public static ListMap<Partitions, NameableObject> getPartitionPeriodMap( List<NameableObject> periods, String tablePrefix, String tableSuffix, Set<String> validPartitions )
     {
         ListMap<Partitions, NameableObject> map = new ListMap<Partitions, NameableObject>();
-        
+
         for ( NameableObject period : periods )
         {
             map.putValue( getPartitions( (Period) period, tablePrefix, tableSuffix, null ).prunePartitions( validPartitions ), period );
         }
-        
+
         return map;
     }
 
@@ -119,17 +121,17 @@
     public static ListMap<String, NameableObject> getPeriodTypePeriodMap( Collection<NameableObject> periods )
     {
         ListMap<String, NameableObject> map = new ListMap<String, NameableObject>();
-        
+
         for ( NameableObject period : periods )
         {
             String periodTypeName = ((Period) period).getPeriodType().getName();
-            
+
             map.putValue( periodTypeName, period );
         }
-        
+
         return map;
     }
-    
+
     /**
      * Returns the year of the given date.
      */
@@ -137,7 +139,7 @@
     {
         return new Cal( date ).getYear();
     }
-    
+
     /**
      * Returns the max date within the year of the given date.
      */