← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9359: FRED-API: moved hierarchy generator out of converter service, should be listing facilities a lot ...

 

------------------------------------------------------------
revno: 9359
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-12-18 18:57:10 +0100
message:
  FRED-API: moved hierarchy generator out of converter service, should be listing facilities a lot faster (about 5x speedup)
modified:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.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-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-13 10:55:39 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-18 17:57:10 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.hierarchy.HierarchyViolationException;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.web.webapi.v1.domain.Facilities;
@@ -293,12 +294,27 @@
         }
 
         Collections.sort( allOrganisationUnits, IdentifiableObjectNameComparator.INSTANCE );
+        List<OrganisationUnitLevel> organisationUnitLevels = organisationUnitService.getOrganisationUnitLevels();
 
         for ( OrganisationUnit organisationUnit : allOrganisationUnits )
         {
             Facility facility = conversionService.convert( organisationUnit, Facility.class );
             filterFacility( facility, allProperties, fields );
 
+            // TODO this probably belongs in "meta": {}
+            List<Map<String, Object>> hierarchy = new ArrayList<Map<String, Object>>();
+            facility.getProperties().put( "hierarchy", hierarchy );
+
+            for ( OrganisationUnitLevel organisationUnitLevel : organisationUnitLevels )
+            {
+                Map<String, Object> level = new HashMap<String, Object>();
+
+                level.put( "name", organisationUnitLevel.getName() );
+                level.put( "level", organisationUnitLevel.getLevel() );
+
+                hierarchy.add( level );
+            }
+
             facilities.getFacilities().add( facility );
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java	2012-12-13 17:04:35 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java	2012-12-18 17:57:10 +0000
@@ -31,7 +31,6 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitLevelComparator;
 import org.hisp.dhis.web.webapi.v1.controller.FacilityController;
 import org.hisp.dhis.web.webapi.v1.domain.Facility;
 import org.hisp.dhis.web.webapi.v1.domain.Identifier;
@@ -40,7 +39,6 @@
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -111,23 +109,6 @@
 
         facility.getProperties().put( "level", organisationUnit.getOrganisationUnitLevel() );
 
-        List<OrganisationUnitLevel> organisationUnitLevels = organisationUnitService.getOrganisationUnitLevels();
-        Collections.sort( organisationUnitLevels, new OrganisationUnitLevelComparator() );
-
-        // TODO this probably belongs in "meta": {}
-        List<Map<String, Object>> hierarchy = new ArrayList<Map<String, Object>>();
-        facility.getProperties().put( "hierarchy", hierarchy );
-
-        for ( OrganisationUnitLevel organisationUnitLevel : organisationUnitLevels )
-        {
-            Map<String, Object> level = new HashMap<String, Object>();
-
-            level.put( "name", organisationUnitLevel.getName() );
-            level.put( "level", organisationUnitLevel.getLevel() );
-
-            hierarchy.add( level );
-        }
-
         return facility;
     }
 }