← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9189: added support for getting children of an ou based on level (country_uid?level=4 will get all faci...

 

------------------------------------------------------------
revno: 9189
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-06 15:22:40 +0300
message:
  added support for getting children of an ou based on level (country_uid?level=4 will get all facilities where level = facilities)
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.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	2012-12-06 09:06:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2012-12-06 12:22:40 +0000
@@ -514,7 +514,7 @@
     }
 
     @JsonProperty( "level" )
-    @JacksonXmlProperty( isAttribute = true )
+    @JacksonXmlProperty( localName = "level", isAttribute = true )
     public int getOrganisationUnitLevel()
     {
         int currentLevel = 1;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.java	2012-12-06 12:06:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.java	2012-12-06 12:22:40 +0000
@@ -31,7 +31,10 @@
 import org.hisp.dhis.api.controller.WebOptions;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.WebUtils;
+import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.util.StringUtils;
@@ -42,6 +45,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -54,6 +59,9 @@
 {
     public static final String RESOURCE_PATH = "/organisationUnits";
 
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
     @Override
     @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
     public String getObject( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
@@ -96,9 +104,13 @@
             }
             else
             {
-                // TODO
-                // System.err.println( "GET CHILDREN" );
-                model.addAttribute( "model", entity );
+                List<OrganisationUnit> entities = new ArrayList<OrganisationUnit>(
+                    organisationUnitService.getOrganisationUnitsAtLevel( level, entity ) );
+
+                MetaData metaData = new MetaData();
+                metaData.setOrganisationUnits( entities );
+
+                model.addAttribute( "model", metaData );
             }
         }
         else