← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18465: Event analytics, returning legend uid in response and including legend names in meta-data

 

------------------------------------------------------------
revno: 18465
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-03-03 11:20:32 +0100
message:
  Event analytics, returning legend uid in response and including legend names in meta-data
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.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/event/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2015-02-25 15:59:31 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2015-03-03 10:20:32 +0000
@@ -44,10 +44,12 @@
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.NameableObjectUtils;
 import org.hisp.dhis.common.QueryItem;
+import org.hisp.dhis.legend.Legend;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.system.util.ListUtils;
 
 /**
  * @author Lars Helge Overland
@@ -193,26 +195,38 @@
     }
     
     /**
-     * Get NameableObjects part of items and item filters.
-     * @return
+     * Get nameable objects part of items and item filters.
      */
     public Set<NameableObject> getNameableObjectItems()
     {
         Set<NameableObject> objects = new HashSet<NameableObject>();
         
-        for ( QueryItem item : items )
-        {
-            objects.add( item.getItem() );
-        }
-        
-        for ( QueryItem item : itemFilters )
-        {
-            objects.add( item.getItem() );
-        }
-        
+        for ( QueryItem item : ListUtils.union( items, itemFilters ) )
+        {
+            objects.add( item.getItem() );
+        }
+                
         return objects;
     }
     
+    /**
+     * Get legend sets part of items and item filters.
+     */
+    public Set<Legend> getLegends()
+    {
+        Set<Legend> legends = new HashSet<>();
+        
+        for ( QueryItem item : ListUtils.union( items, itemFilters ) )
+        {
+            if ( item.hasLegendSet() )
+            {
+                legends.addAll( item.getLegendSet().getLegends() );
+            }
+        }
+        
+        return legends;
+    }
+    
     public boolean isOrganisationUnitMode( String mode )
     {
         return organisationUnitMode != null && organisationUnitMode.equalsIgnoreCase( mode );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-02-27 18:08:30 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-03-03 10:20:32 +0000
@@ -77,7 +77,6 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.legend.Legend;
 import org.hisp.dhis.legend.LegendService;
 import org.hisp.dhis.legend.LegendSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -556,12 +555,8 @@
         {
             for ( int i = 1; i < split.length; i += 2 )
             {
-                // Legends comes as identifiers, replace with names if legend set
-                
-                String filterItem = queryItem.hasLegendSet() ? replaceLegendUidsWithNames( split[i+1] ) : split[i+1];
-                
                 QueryOperator operator = QueryOperator.fromString( split[i] );
-                QueryFilter filter = new QueryFilter( operator, filterItem );
+                QueryFilter filter = new QueryFilter( operator, split[i+1] );
                 queryItem.getFilters().add( filter );
             }
         }
@@ -594,6 +589,7 @@
         map.putAll( getUidNameMap( params.getItemFilters(), params.getDisplayProperty() ) );
         map.putAll( getUidNameMap( params.getDimensions(), params.isHierarchyMeta(), params.getDisplayProperty() ) );
         map.putAll( getUidNameMap( params.getFilters(), params.isHierarchyMeta(), params.getDisplayProperty() ) );
+        map.putAll( IdentifiableObjectUtils.getUidNameMap( params.getLegends() ) );
 
         return map;
     }
@@ -710,29 +706,4 @@
         
         throw new IllegalQueryException( "Value identifier does not reference any data element or attribute which are numeric type and part of the program: " + value );        
     }
-
-    /**
-     * Replaces legend identifiers with names.
-     */
-    private String replaceLegendUidsWithNames( String filter )
-    {
-        if ( filter != null )
-        {
-            String[] filterItems = QueryFilter.getFilterItems( filter );
-            
-            for ( String uid : filterItems )
-            {
-                Legend legend = legendService.getLegend( uid );
-
-                if ( legend == null )
-                {
-                    throw new IllegalQueryException( "Legend does not exist: " + uid );
-                }
-                
-                filter = filter.replace( uid, legend.getName() );
-            }
-        }
-        
-        return filter;
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2015-03-02 10:56:38 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2015-03-03 10:20:32 +0000
@@ -276,12 +276,12 @@
         {
             String column = quote( dataElement.getUid() + PartitionUtils.SEP + dataElement.getLegendSet().getUid() );
             
-            String sql = "(select l.name from maplegend l inner join maplegendsetmaplegend lsl on l.maplegendid=lsl.maplegendid " +
+            String sql = "(select l.uid from maplegend l inner join maplegendsetmaplegend lsl on l.maplegendid=lsl.maplegendid " +
                 "inner join trackedentitydatavalue dv on l.startvalue <= " + doubleSelect + " and l.endvalue > " + doubleSelect + " " +
                 "and lsl.legendsetid=" + dataElement.getLegendSet().getId() + " and dv.programstageinstanceid=psi.programstageinstanceid " + 
                 "and dv.dataelementid=" + dataElement.getId() + numericClause + ") as " + column;
                 
-            String[] col = { column, "character varying(230)", sql };
+            String[] col = { column, "character(11)", sql };
             columns.add( col );
         }
 
@@ -302,12 +302,12 @@
         {
             String column = quote( attribute.getUid() + PartitionUtils.SEP + attribute.getLegendSet().getUid() );
             
-            String sql = "(select l.name from maplegend l inner join maplegendsetmaplegend lsl on l.maplegendid=lsl.maplegendid " +
+            String sql = "(select l.uid from maplegend l inner join maplegendsetmaplegend lsl on l.maplegendid=lsl.maplegendid " +
                 "inner join trackedentityattributevalue av on l.startvalue <= " + doubleSelect + " and l.endvalue > " + doubleSelect + " " +
                 "and lsl.legendsetid=" + attribute.getLegendSet().getId() + " and av.trackedentityinstanceid=pi.trackedentityinstanceid " +
                 "and av.trackedentityattributeid=" + attribute.getId() + numericClause + ") as " + column;
             
-            String[] col = { column, "character varying(230)", sql };
+            String[] col = { column, "character(11)", sql };
             columns.add( col );
         }