← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16106: Impl method EventAnalyticsService.getFromAnalyticalObject

 

------------------------------------------------------------
revno: 16106
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-07-12 19:11:38 +0200
message:
  Impl method EventAnalyticsService.getFromAnalyticalObject
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.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-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.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/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-07-12 14:18:34 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-07-12 17:11:38 +0000
@@ -136,7 +136,6 @@
 import org.hisp.dhis.system.util.SystemUtils;
 import org.hisp.dhis.system.util.Timer;
 import org.hisp.dhis.system.util.UniqueArrayList;
-import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
@@ -1043,29 +1042,7 @@
             
             return ListUtils.getList( object );
         }
-        
-        TrackedEntityAttribute tea = attributeService.getTrackedEntityAttribute( dimension );
-        
-        if ( tea != null )
-        {
-            List<NameableObject> options = new ArrayList<NameableObject>(); //TODO
-
-            DimensionalObject object = new BaseDimensionalObject( dimension, DimensionType.TRACKED_ENTITY_ATTRIBUTE, null, tea.getDisplayName(), options );
-            
-            return ListUtils.getList( object );
-        }
-        
-        DataElement ted = dataElementService.getDataElement( dimension );
-        
-        if ( ted != null )
-        {
-            List<NameableObject> options = new ArrayList<NameableObject>(); //TODO
-
-            DimensionalObject object = new BaseDimensionalObject( dimension, DimensionType.TRACKED_ENTITY_DATAELEMENT, null, ted.getDisplayName(), options );
-            
-            return ListUtils.getList( object );            
-        }
-        
+                
         if ( allowNull )
         {
             return null;

=== 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	2014-07-02 11:08:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2014-07-12 17:11:38 +0000
@@ -32,6 +32,9 @@
 import static org.hisp.dhis.analytics.AnalyticsService.OU_HIERARCHY_KEY;
 import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
+import static org.hisp.dhis.common.DimensionalObjectUtils.getDimensionFromParam;
+import static org.hisp.dhis.common.DimensionalObjectUtils.getDimensionItemsFromParam;
+import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.common.NameableObjectUtils.asTypedList;
 import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap;
@@ -50,6 +53,7 @@
 import org.hisp.dhis.analytics.event.EventAnalyticsService;
 import org.hisp.dhis.analytics.event.EventQueryParams;
 import org.hisp.dhis.analytics.event.EventQueryPlanner;
+import org.hisp.dhis.common.BaseAnalyticalObject;
 import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.DimensionalObjectUtils;
@@ -74,6 +78,7 @@
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.system.grid.ListGrid;
 import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.system.util.ListUtils;
 import org.hisp.dhis.system.util.Timer;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
@@ -309,6 +314,50 @@
         return params;
     }
 
+    public EventQueryParams getFromAnalyticalObject( BaseAnalyticalObject object, Program program, I18nFormat format )
+    {
+        EventQueryParams params = new EventQueryParams();
+
+        if ( object != null )
+        {
+            Date date = object.getRelativePeriodDate();
+            
+            object.populateAnalyticalProperties();
+
+            for ( DimensionalObject dimension : ListUtils.union( object.getColumns(), object.getRows() ) )
+            {
+                List<DimensionalObject> dimObj = analyticsService.
+                    getDimension( toDimension( dimension.getDimension() ), getUids( dimension.getItems() ), date, format, true );
+                
+                if ( dimObj != null )
+                {
+                    params.getDimensions().addAll( dimObj );
+                }
+                else
+                {
+                    params.getItems().add( getQueryItem( dimension.getDimension(), program ) );
+                }
+            }
+            
+            for ( DimensionalObject filter : object.getFilters() )
+            {
+                List<DimensionalObject> dimObj = analyticsService.
+                    getDimension( toDimension( filter.getDimension() ), getUids( filter.getItems() ), date, format, true );
+                
+                if ( dimObj != null )
+                {
+                    params.getFilters().addAll( dimObj );
+                }
+                else
+                {
+                    params.getItemFilters().add( getQueryItem( filter.getDimension(), program ) );
+                }
+            }
+        }
+        
+        return params;
+    }
+    
     public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
         Set<String> dimension, Set<String> filter, String ouMode, Set<String> asc, Set<String> desc,
         boolean skipMeta, boolean hierarchyMeta, boolean coordinatesOnly, Integer page, Integer pageSize, I18nFormat format )
@@ -351,8 +400,8 @@
         {
             for ( String dim : dimension )
             {
-                String dimensionId = DimensionalObjectUtils.getDimensionFromParam( dim );
-                List<String> items = DimensionalObjectUtils.getDimensionItemsFromParam( dim );                
+                String dimensionId = getDimensionFromParam( dim );
+                List<String> items = getDimensionItemsFromParam( dim );                
                 List<DimensionalObject> dimObj = analyticsService.getDimension( dimensionId, items, date, format, true );
                 
                 if ( dimObj != null )
@@ -370,8 +419,8 @@
         {
             for ( String dim : filter )
             {
-                String dimensionId = DimensionalObjectUtils.getDimensionFromParam( dim );
-                List<String> items = DimensionalObjectUtils.getDimensionItemsFromParam( dim );                
+                String dimensionId = getDimensionFromParam( dim );
+                List<String> items = getDimensionItemsFromParam( dim );                
                 List<DimensionalObject> dimObj = analyticsService.getDimension( dimensionId, items, date, format, true );
                 
                 if ( dimObj != null )
@@ -424,7 +473,7 @@
         
         return params;
     }
-
+    
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------

=== 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-12 14:18:34 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2014-07-12 17:11:38 +0000
@@ -55,7 +55,6 @@
 import org.apache.commons.math.analysis.UnivariateRealInterpolator;
 import org.apache.commons.math.stat.regression.SimpleRegression;
 import org.hisp.dhis.analytics.AnalyticsService;
-import org.hisp.dhis.analytics.event.EventAnalyticsService;
 import org.hisp.dhis.chart.BaseChart;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.chart.ChartService;

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java	2014-07-12 17:11:38 +0000
@@ -229,4 +229,23 @@
         
         return list.subList( Math.max( 0, start ), Math.min( list.size(), end ) );
     }
+    
+    /**
+     * Unions the given array of lists into a single list.
+     * 
+     * @param lists the array of lists.
+     * @return a union of the given lists.
+     */
+    @SafeVarargs
+    public static <T> List<T> union( final List<T>... lists )
+    {
+        final List<T> union = new ArrayList<>();
+        
+        for ( List<T> list : lists )
+        {
+            union.addAll( list );
+        }
+        
+        return union;
+    }
 }