← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20220: Event analytics. Fixed issue with user org units

 

------------------------------------------------------------
revno: 20220
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-17 18:33:12 +0200
message:
  Event analytics. Fixed issue with user org units
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java
  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/MockAnalyticsService.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/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.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/AnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java	2015-09-08 18:09:34 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java	2015-09-17 16:33:12 +0000
@@ -222,4 +222,14 @@
      */
     DimensionalObject getDimension( String dimension, List<String> items, Date relativePeriodDate, 
         List<OrganisationUnit> userOrgUnits, I18nFormat format, boolean allowNull );
+    
+    /**
+     * Returns a list of user organisation units, looking first at the given user 
+     * org unit parameter, second at the organisation units associated with the
+     * current user. Returns an empty list if no organisation units are found.
+     * 
+     * @param userOrgUnit the user org unit parameter string.
+     * @return a list of organisation units.
+     */
+    List<OrganisationUnit> getUserOrgUnits( String userOrgUnit );
 }

=== 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	2015-09-16 18:31:45 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2015-09-17 16:33:12 +0000
@@ -1279,6 +1279,35 @@
         throw new IllegalQueryException( "Dimension identifier does not reference any dimension: " + dimension );
     }
 
+    @Override
+    public List<OrganisationUnit> getUserOrgUnits( String userOrgUnit )
+    {
+        List<OrganisationUnit> units = new ArrayList<>();
+        
+        User currentUser = currentUserService.getCurrentUser();
+        
+        if ( userOrgUnit != null )
+        {
+            List<String> ous = DimensionalObjectUtils.getItemsFromParam( userOrgUnit );
+            
+            for ( String ou : ous )
+            {
+                OrganisationUnit unit = idObjectManager.get( OrganisationUnit.class, ou );
+                
+                if ( unit != null )
+                {
+                    units.add( unit );
+                }
+            }
+        }
+        else if ( currentUser != null && currentUser.hasOrganisationUnit() )
+        {
+            units = currentUser.getSortedOrganisationUnits();
+        }
+        
+        return units;
+    }
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
@@ -1441,42 +1470,6 @@
     }
     
     /**
-     * Returns a list of user organisation units, looking first at the given user 
-     * org unit parameter, second at the organisation units associated with the
-     * current user. Returns an empty list if no organisation units are found.
-     * 
-     * @param userOrgUnit the user org unit parameter string.
-     * @return a list of organisation units.
-     */
-    private List<OrganisationUnit> getUserOrgUnits( String userOrgUnit )
-    {
-        List<OrganisationUnit> units = new ArrayList<>();
-        
-        User currentUser = currentUserService.getCurrentUser();
-        
-        if ( userOrgUnit != null )
-        {
-            List<String> ous = DimensionalObjectUtils.getItemsFromParam( userOrgUnit );
-            
-            for ( String ou : ous )
-            {
-                OrganisationUnit unit = idObjectManager.get( OrganisationUnit.class, ou );
-                
-                if ( unit != null )
-                {
-                    units.add( unit );
-                }
-            }
-        }
-        else if ( currentUser != null && currentUser.hasOrganisationUnit() )
-        {
-            units = currentUser.getSortedOrganisationUnits();
-        }
-        
-        return units;
-    }
-
-    /**
      * Gets the number of available cores. Uses explicit number from system
      * setting if available. Detects number of cores from current server runtime
      * if not.

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java	2015-09-08 18:09:34 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java	2015-09-17 16:33:12 +0000
@@ -109,4 +109,10 @@
     {
         throw new NotImplementedException( "" );
     }
+
+    @Override
+    public List<OrganisationUnit> getUserOrgUnits( String userOrgUnit )
+    {
+        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	2015-09-13 21:54:23 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-09-17 16:33:12 +0000
@@ -410,6 +410,8 @@
         DisplayProperty displayProperty, Integer page, Integer pageSize, I18nFormat format )
     {
         EventQueryParams params = new EventQueryParams();
+        
+        List<OrganisationUnit> userOrgUnits = analyticsService.getUserOrgUnits( null );
 
         Program pr = programService.getProgram( program );
 
@@ -447,7 +449,7 @@
             {
                 String dimensionId = getDimensionFromParam( dim );
                 List<String> items = getDimensionItemsFromParam( dim );                
-                DimensionalObject dimObj = analyticsService.getDimension( dimensionId, items, null, null, format, true );
+                DimensionalObject dimObj = analyticsService.getDimension( dimensionId, items, null, userOrgUnits, format, true );
                 
                 if ( dimObj != null )
                 {
@@ -466,7 +468,7 @@
             {
                 String dimensionId = getDimensionFromParam( dim );
                 List<String> items = getDimensionItemsFromParam( dim );                
-                DimensionalObject dimObj = analyticsService.getDimension( dimensionId, items, null, null, format, true );
+                DimensionalObject dimObj = analyticsService.getDimension( dimensionId, items, null, userOrgUnits, format, true );
                 
                 if ( dimObj != null )
                 {

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java	2015-09-08 18:09:34 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java	2015-09-17 16:33:12 +0000
@@ -32,6 +32,7 @@
 import static org.junit.Assert.assertNotNull;
 
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.hisp.dhis.DhisSpringTest;
@@ -57,6 +58,8 @@
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import com.google.inject.internal.Lists;
+
 /**
  * @author Lars Helge Overland
  */
@@ -464,4 +467,14 @@
         assertEquals( 1, params.getFilters().size() );
         assertEquals( 3, params.getDimensionOptions( ouGroupSetA.getUid() ).size() );
     }
+    
+    @Test
+    public void testGetUserOrgUnits()
+    {
+        String ouParam = ouA.getUid() + ";" + ouB.getUid();
+        
+        List<OrganisationUnit> expected = Lists.newArrayList( ouA, ouB );
+        
+        assertEquals( expected, analyticsService.getUserOrgUnits( ouParam ) );
+    }
 }