← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11725: added two new options to ou-controller, includeChildren, includeDescendants

 

------------------------------------------------------------
revno: 11725
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-08-21 10:44:19 +0200
message:
  added two new options to ou-controller, includeChildren, includeDescendants
modified:
  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-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	2013-08-20 11:01:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.java	2013-08-21 08:44:19 +0000
@@ -31,7 +31,6 @@
 import org.hisp.dhis.api.controller.WebMetaData;
 import org.hisp.dhis.api.controller.WebOptions;
 import org.hisp.dhis.api.controller.exception.NotFoundException;
-import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.WebUtils;
 import org.hisp.dhis.common.Pager;
 import org.hisp.dhis.dxf2.metadata.MetaData;
@@ -120,8 +119,8 @@
     }
 
     @Override
-    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
-    public String getObject( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
+    @RequestMapping(value = "/{uid}", method = RequestMethod.GET)
+    public String getObject( @PathVariable("uid") String uid, @RequestParam Map<String, String> parameters,
         Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
@@ -174,6 +173,27 @@
                 model.addAttribute( "model", metaData );
             }
         }
+        if ( options.getOptions().containsKey( "includeDescendants" ) && Boolean.parseBoolean( options.getOptions().get( "includeDescendants" ) ) )
+        {
+            List<OrganisationUnit> entities = new ArrayList<OrganisationUnit>(
+                organisationUnitService.getOrganisationUnitsWithChildren( uid ) );
+
+            MetaData metaData = new MetaData();
+            metaData.setOrganisationUnits( entities );
+
+            model.addAttribute( "model", metaData );
+        }
+        if ( options.getOptions().containsKey( "includeChildren" ) && Boolean.parseBoolean( options.getOptions().get( "includeChildren" ) ) )
+        {
+            List<OrganisationUnit> entities = new ArrayList<OrganisationUnit>();
+            entities.add( entity );
+            entities.addAll( entity.getChildren() );
+
+            MetaData metaData = new MetaData();
+            metaData.setOrganisationUnits( entities );
+
+            model.addAttribute( "model", metaData );
+        }
         else
         {
             model.addAttribute( "model", entity );