← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20420: Org unit service, improved performance of get by parents and groups method

 

------------------------------------------------------------
revno: 20420
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-30 20:21:31 +0200
message:
  Org unit service, improved performance of get by parents and groups method
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitQueryParams.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.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/OrganisationUnitQueryParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitQueryParams.java	2015-09-23 18:53:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitQueryParams.java	2015-09-30 18:21:31 +0000
@@ -44,12 +44,12 @@
     private String query;
     
     /**
-     * The parent organisation units for which to include all children.
+     * The parent organisation units for which to include all children, inclusive.
      */
     private Set<OrganisationUnit> parents = new HashSet<>();
     
     /**
-     * The groups for which members to include.
+     * The groups for which members to include, inclusive.
      */
     private Set<OrganisationUnitGroup> groups = new HashSet<>();
     

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2015-09-17 14:51:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2015-09-30 18:21:31 +0000
@@ -274,21 +274,11 @@
     @Override
     public List<OrganisationUnit> getOrganisationUnits( Collection<OrganisationUnitGroup> groups, Collection<OrganisationUnit> parents )
     {
-        List<OrganisationUnit> members = new ArrayList<>();
-
-        for ( OrganisationUnitGroup group : groups )
-        {
-            members.addAll( group.getMembers() );
-        }
-
-        if ( parents != null && !parents.isEmpty() )
-        {
-            List<OrganisationUnit> children = getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( parents ) );
-
-            members.retainAll( children );
-        }
-
-        return members;
+        OrganisationUnitQueryParams params = new OrganisationUnitQueryParams();
+        params.setParents( Sets.newHashSet( parents ) );
+        params.setGroups( Sets.newHashSet( groups ) );
+
+        return organisationUnitStore.getOrganisationUnits( params );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2015-09-23 18:53:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2015-09-30 18:21:31 +0000
@@ -177,10 +177,14 @@
         
         if ( params.hasGroups() )
         {
+            hql += hlp.whereAnd() + " (";
+            
             for ( OrganisationUnitGroup group : params.getGroups() )
             {
-                hql += hlp.whereAnd() + " :" + group.getUid() + " in elements(o.groups) ";
+                hql += " :" + group.getUid() + " in elements(o.groups) or ";
             }
+            
+            hql = TextUtils.removeLastOr( hql ) + ") ";
         }
         
         if ( params.hasLevels() )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java	2015-09-17 13:42:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java	2015-09-30 18:21:31 +0000
@@ -128,6 +128,16 @@
         assertEquals( 2, ous.size() );
         assertTrue( ous.containsAll( Sets.newHashSet( ouD, ouF ) ) );
 
+        // Groups
+        
+        params = new OrganisationUnitQueryParams();
+        params.setGroups( Sets.newHashSet( ogA, ogB ) );
+
+        ous = orgUnitStore.getOrganisationUnits( params );
+
+        assertEquals( 4, ous.size() );
+        assertTrue( ous.containsAll( Sets.newHashSet( ouD, ouF, ouE, ouG ) ) );
+
         // Levels
         
         params = new OrganisationUnitQueryParams();