← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17408: Charts, moved key creation to a separate method

 

------------------------------------------------------------
revno: 17408
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-11-10 20:46:15 +0100
message:
  Charts, moved key creation to a separate method
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.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/chart/BaseChart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java	2014-09-22 18:31:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java	2014-11-10 19:46:15 +0000
@@ -202,7 +202,7 @@
     {
         return title != null && !title.isEmpty();
     }
-
+    
     // -------------------------------------------------------------------------
     // Getters and setters for transient properties
     // -------------------------------------------------------------------------

=== 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-11-03 00:24:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2014-11-10 19:46:15 +0000
@@ -193,6 +193,11 @@
     {
         return itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty();
     }
+    
+    public boolean hasSortOrder()
+    {
+        return sortOrder != 0;
+    }
 
     protected void addTransientOrganisationUnits( Collection<OrganisationUnit> organisationUnits )
     {

=== 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-11-03 00:24:32 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2014-11-10 19:46:15 +0000
@@ -816,8 +816,8 @@
 
         BaseAnalyticalObject.sortKeys( valueMap );
         
-        List<NameableObject> seriez = chart.series();
-        List<NameableObject> categories = chart.category();
+        List<NameableObject> seriez = new ArrayList<>( chart.series() );
+        List<NameableObject> categories = new ArrayList<>( chart.category() );
         
         for ( NameableObject series : seriez )
         {
@@ -827,18 +827,8 @@
             {
                 categoryIndex++;
 
-                String key = series.getUid() + DIMENSION_SEP + category.getUid();
-
-                // Replace potential operand separator with dimension separator
-
-                key = chart.isAnalyticsType( AnalyticsType.AGGREGATE ) ? key.replace( DataElementOperand.SEPARATOR, DIMENSION_SEP ) : key; 
-                
-                // TODO fix issue with keys including -
-                
-                // Sort key on components to remove significance of column order
-                
-                key = BaseAnalyticalObject.sortKey( key );
-
+                String key = getKey( series, category, chart.getAnalyticsType() );
+                
                 Object object = valueMap.get( key );
                 
                 Number value = object != null && object instanceof Number ? (Number) object : null;
@@ -871,6 +861,23 @@
 
         return new CategoryDataset[]{ regularDataSet, regressionDataSet };
     }
+    
+    /**
+     * Creates a key based on the given input. Sorts the key on its components
+     * to remove significance of column order.
+     */
+    private String getKey( NameableObject series, NameableObject category, AnalyticsType analyticsType )
+    {
+        String key = series.getUid() + DIMENSION_SEP + category.getUid();
+
+        // Replace potential operand separator with dimension separator
+
+        key = AnalyticsType.AGGREGATE.equals( analyticsType ) ? key.replace( DataElementOperand.SEPARATOR, DIMENSION_SEP ) : key; 
+        
+        // TODO fix issue with keys including -.
+        
+        return BaseAnalyticalObject.sortKey( key );
+    }
 
     // -------------------------------------------------------------------------
     // CRUD operations