← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17595: Analytics, fix for parent graph and data view org units

 

------------------------------------------------------------
revno: 17595
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-11-26 14:15:09 +0100
message:
  Analytics, fix for parent graph and data view org units
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.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/event/data/DefaultEventAnalyticsService.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/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2014-11-26 12:47:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2014-11-26 13:15:09 +0000
@@ -716,11 +716,11 @@
         return builder.toString();
     }
 
-    public String getParentNameGraph( boolean includeThis )
+    public String getParentNameGraph( Collection<OrganisationUnit> roots, boolean includeThis )
     {
         StringBuilder builder = new StringBuilder();
 
-        List<OrganisationUnit> ancestors = getAncestors();
+        List<OrganisationUnit> ancestors = getAncestors( roots );
 
         for ( OrganisationUnit unit : ancestors )
         {
@@ -739,7 +739,7 @@
      * Returns a mapping between the uid and the uid parent graph of the given
      * organisation units.
      */
-    public static Map<String, String> getParentGraphMap( List<OrganisationUnit> organisationUnits )
+    public static Map<String, String> getParentGraphMap( List<OrganisationUnit> organisationUnits, Collection<OrganisationUnit> roots )
     {
         Map<String, String> map = new HashMap<>();
         
@@ -747,7 +747,7 @@
         {
             for ( OrganisationUnit unit : organisationUnits )
             {
-                map.put( unit.getUid(), unit.getParentGraph( null ) );
+                map.put( unit.getUid(), unit.getParentGraph( roots ) );
             }
         }
         
@@ -758,7 +758,7 @@
      * Returns a mapping between the uid and the uid parent graph of the given
      * organisation units.
      */
-    public static Map<String, String> getParentNameGraphMap( List<OrganisationUnit> organisationUnits, boolean includeThis )
+    public static Map<String, String> getParentNameGraphMap( List<OrganisationUnit> organisationUnits, Collection<OrganisationUnit> roots, boolean includeThis )
     {
         Map<String, String> map = new HashMap<>();
         
@@ -766,7 +766,7 @@
         {
             for ( OrganisationUnit unit : organisationUnits )
             {
-                map.put( unit.getName(), unit.getParentNameGraph( includeThis ) );
+                map.put( unit.getName(), unit.getParentNameGraph( roots, includeThis ) );
             }
         }
         

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java	2014-11-26 12:20:00 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java	2014-11-26 13:15:09 +0000
@@ -138,6 +138,24 @@
 
         assertEquals( expected, unitD.getParentGraph( null ) );        
     }
+
+    @Test
+    public void testGetParentNameGraph()
+    {
+        unitD.setParent( unitC );
+        unitC.setParent( unitB );
+        unitB.setParent( unitA );
+        
+        List<OrganisationUnit> roots = new ArrayList<>( Arrays.asList( unitB ) );
+        
+        String expected = "/OrgUnitB/OrgUnitC";
+        
+        assertEquals( expected, unitD.getParentNameGraph( roots, false ) );
+        
+        expected = "/OrgUnitA/OrgUnitB/OrgUnitC";
+
+        assertEquals( expected, unitD.getParentNameGraph( null, false ) );        
+    }
     
     @Test
     public void testSetMultiPolygonCoordinatesFromCollection()

=== 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-11-11 10:29:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-11-26 13:15:09 +0000
@@ -463,7 +463,7 @@
         if ( !params.isSkipMeta() )
         {
             Map<Object, Object> metaData = new HashMap<>();
-
+            
             Map<String, String> uidNameMap = getUidNameMap( params );
             Map<String, String> cocNameMap = getCocNameMap( params );
             uidNameMap.putAll( cocNameMap );
@@ -487,14 +487,19 @@
             metaData.put( ORGUNIT_DIM_ID, getUids( params.getDimensionOrFilter( ORGUNIT_DIM_ID ) ) );
             metaData.put( CATEGORYOPTIONCOMBO_DIM_ID, cocNameMap.keySet() );
 
+            User user = currentUserService.getCurrentUser();
+            
+            List<OrganisationUnit> organisationUnits = asTypedList( params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class );
+            Collection<OrganisationUnit> roots = user != null ? user.getDataViewOrganisationUnitsWithFallback() : null;
+            
             if ( params.isHierarchyMeta() )
             {
-                metaData.put( OU_HIERARCHY_KEY, getParentGraphMap( asTypedList( params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ) ) );
+                metaData.put( OU_HIERARCHY_KEY, getParentGraphMap( organisationUnits, roots ) );
             }
 
             if ( params.isShowHierarchy() )
             {
-                metaData.put( OU_NAME_HIERARCHY_KEY, getParentNameGraphMap( asTypedList( params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ), true ) );
+                metaData.put( OU_NAME_HIERARCHY_KEY, getParentNameGraphMap( organisationUnits, roots, true ) );
             }
 
             grid.setMetaData( metaData );

=== 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-11-07 17:10:51 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2014-11-26 13:15:09 +0000
@@ -41,6 +41,7 @@
 import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -85,6 +86,8 @@
 import org.hisp.dhis.system.util.ListUtils;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
 import org.hisp.dhis.util.Timer;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -136,6 +139,9 @@
     @Autowired
     private SystemSettingManager systemSettingManager;
 
+    @Autowired
+    private CurrentUserService currentUserService;
+    
     // -------------------------------------------------------------------------
     // EventAnalyticsService implementation
     // -------------------------------------------------------------------------
@@ -219,11 +225,15 @@
             metaData.put( NAMES_META_KEY, uidNameMap );
             metaData.put( PERIOD_DIM_ID, getUids( params.getDimensionOrFilter( PERIOD_DIM_ID ) ) );
             metaData.put( ORGUNIT_DIM_ID, getUids( params.getDimensionOrFilter( ORGUNIT_DIM_ID ) ) );
-    
+
+            User user = currentUserService.getCurrentUser();
+            
+            Collection<OrganisationUnit> roots = user != null ? user.getDataViewOrganisationUnitsWithFallback() : null;
+            
             if ( params.isHierarchyMeta() )
             {
                 metaData.put( OU_HIERARCHY_KEY, getParentGraphMap( asTypedList( 
-                    params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ) ) );
+                    params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ), roots ) );
             }
 
             grid.setMetaData( metaData );
@@ -307,10 +317,14 @@
 
         metaData.put( NAMES_META_KEY, uidNameMap );
 
+        User user = currentUserService.getCurrentUser();
+
+        Collection<OrganisationUnit> roots = user != null ? user.getDataViewOrganisationUnitsWithFallback() : null;
+        
         if ( params.isHierarchyMeta() )
         {
             metaData.put( OU_HIERARCHY_KEY, getParentGraphMap( asTypedList( 
-                params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ) ) );
+                params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ), roots ) );
         }
 
         if ( params.isPaging() )