← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16118: Impl support for PNG versions of event charts in web api on api/eventCharts/<uid>/data

 

------------------------------------------------------------
revno: 16118
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-07-13 16:34:10 +0200
message:
  Impl support for PNG versions of event charts in web api on api/eventCharts/<uid>/data
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.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	2014-07-13 13:53:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2014-07-13 14:34:10 +0000
@@ -670,9 +670,8 @@
     }
     
     /**
-     * Splits the keys of the given map on the dimension identifier separator,
-     * sorts the identifiers, writes them out as a key and puts the key back into
-     * the map.
+     * Sorts the keys in the given map by splitting on the '-' character and 
+     * sorting the components alphabetically.
      * 
      * @param valueMap the mapping of keys and values.
      */
@@ -682,15 +681,11 @@
 
         for ( String key : valueMap.keySet() )
         {
-            if ( key != null )
+            String sortKey = sortKey( key );
+            
+            if ( sortKey != null )
             {
-                String[] ids = key.split( DIMENSION_SEP );
-
-                Collections.sort( Arrays.asList( ids ) );
-
-                String sortedKey = StringUtils.join( ids, DIMENSION_SEP );
-
-                map.put( sortedKey, valueMap.get( key ) );
+                map.put( sortKey, valueMap.get( key ) );
             }
         }
 
@@ -699,6 +694,26 @@
     }
 
     /**
+     * Sorts the given key by splitting on the '-' character and sorting the 
+     * components alphabetically.
+     * 
+     * @param valueMap the mapping of keys and values.
+     */
+    public static String sortKey( String key )
+    {
+        if ( key != null )
+        {
+            String[] ids = key.split( DIMENSION_SEP );
+
+            Collections.sort( Arrays.asList( ids ) );
+
+            key = StringUtils.join( ids, DIMENSION_SEP );
+        }
+        
+        return key;
+    }
+
+    /**
      * Generates an identifier based on the given lists of NameableObjects. Uses
      * the UIDs for each NameableObject, sorts them and writes them out as a key.
      */

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java	2014-07-13 13:53:40 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java	2014-07-13 14:34:10 +0000
@@ -95,6 +95,13 @@
     }
     
     @Test
+    public void testSortKey()
+    {
+        String expected = "a-b-c";
+        assertEquals( expected, BaseAnalyticalObject.sortKey( "b-c-a" ) );
+    }
+    
+    @Test
     public void testPopulateAnalyticalProperties()
     {
         TrackedEntityAttribute tea = new TrackedEntityAttribute();

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2014-07-13 13:53:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2014-07-13 14:34:10 +0000
@@ -62,6 +62,7 @@
 import org.hisp.dhis.chart.ChartService;
 import org.hisp.dhis.common.AnalyticalObjectStore;
 import org.hisp.dhis.common.AnalyticsType;
+import org.hisp.dhis.common.BaseAnalyticalObject;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.NameableObject;
@@ -746,6 +747,8 @@
 
         SimpleRegression regression = new SimpleRegression();
 
+        BaseAnalyticalObject.sortKeys( valueMap );
+
         for ( NameableObject series : chart.series() )
         {
             double categoryIndex = 0;
@@ -759,6 +762,10 @@
                 // Replace potential operand separator with dimension separator
 
                 key = key.replace( DataElementOperand.SEPARATOR, DIMENSION_SEP );
+                
+                // Sort key on components to remove significance of column order
+                
+                key = BaseAnalyticalObject.sortKey( key );
 
                 Double value = valueMap.get( key );