← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15619: support includeChildren/includeDescendants in /api/organisationUnits/uid API

 

------------------------------------------------------------
revno: 15619
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-11 13:03:34 +0200
message:
  support includeChildren/includeDescendants in /api/organisationUnits/uid API
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IdentifiableObjectController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/indicator/IndicatorGroupController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitGroupController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.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/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-11 08:13:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-11 11:03:34 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import org.hisp.dhis.acl.Access;
 import org.hisp.dhis.acl.AclService;
@@ -73,6 +74,7 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -189,7 +191,6 @@
         return rootNode;
     }
 
-
     @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
     public @ResponseBody RootNode getObject( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
         Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
@@ -202,32 +203,33 @@
         }
 
         WebOptions options = new WebOptions( parameters );
-        T entity = getEntity( uid );
+        List<T> entities = getEntity( uid, options );
 
-        if ( entity == null )
+        if ( entities.isEmpty() )
         {
             throw new NotFoundException( uid );
         }
 
         if ( options.hasLinks() )
         {
-            linkService.generateLinks( entity );
+            linkService.generateLinks( entities );
         }
 
         if ( aclService.isSupported( getEntityClass() ) )
         {
-            addAccessProperties( entity );
-        }
-
-        postProcessEntity( entity );
-        postProcessEntity( entity, options, parameters );
-
-        List<IdentifiableObject> objects = new ArrayList<>();
-        objects.add( entity );
-
-        CollectionNode collectionNode = filterService.fieldFilter( getEntityClass(), objects, fields );
-
-        if ( options.booleanTrue( "useWrapper" ) )
+            addAccessProperties( entities );
+        }
+
+        for ( T entity : entities )
+        {
+            postProcessEntity( entity );
+            postProcessEntity( entity, options, parameters );
+        }
+
+        CollectionNode collectionNode = filterService.fieldFilter( getEntityClass(), entities, fields );
+
+        if ( options.booleanTrue( "useWrapper" ) || entities.size() > 1
+            || options.getOptions().containsKey( "includeChildren" ) || options.getOptions().containsKey( "includeDescendants" ) )
         {
             RootNode rootNode = new RootNode( "metadata" );
             rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );
@@ -284,15 +286,15 @@
     public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
         input ) throws Exception
     {
-        T object = getEntity( uid );
+        List<T> objects = getEntity( uid );
 
-        if ( object == null )
+        if ( objects.isEmpty() )
         {
             ContextUtils.conflictResponse( response, getEntityName() + " does not exist: " + uid );
             return;
         }
 
-        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), object ) )
+        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), objects.get( 0 ) ) )
         {
             throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
         }
@@ -309,15 +311,15 @@
     public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
         input ) throws Exception
     {
-        T object = getEntity( uid );
+        List<T> objects = getEntity( uid );
 
-        if ( object == null )
+        if ( objects.isEmpty() )
         {
             ContextUtils.conflictResponse( response, getEntityName() + " does not exist: " + uid );
             return;
         }
 
-        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), object ) )
+        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), objects.get( 0 ) ) )
         {
             throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
         }
@@ -338,14 +340,20 @@
     public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws
         Exception
     {
-        T object = getEntity( uid );
-
-        if ( !aclService.canDelete( currentUserService.getCurrentUser(), object ) )
+        List<T> objects = getEntity( uid );
+
+        if ( objects.isEmpty() )
+        {
+            ContextUtils.conflictResponse( response, getEntityName() + " does not exist: " + uid );
+            return;
+        }
+
+        if ( !aclService.canDelete( currentUserService.getCurrentUser(), objects.get( 0 ) ) )
         {
             throw new DeleteAccessDeniedException( "You don't have the proper permissions to delete this object." );
         }
 
-        manager.delete( object );
+        manager.delete( objects.get( 0 ) );
     }
 
     //--------------------------------------------------------------------------
@@ -417,9 +425,22 @@
         return entityList;
     }
 
-    protected T getEntity( String uid )
-    {
-        return manager.getNoAcl( getEntityClass(), uid ); //TODO consider ACL
+    protected List<T> getEntity( String uid )
+    {
+        return getEntity( uid, new WebOptions( new HashMap<String, String>() ) );
+    }
+
+    protected List<T> getEntity( String uid, WebOptions options )
+    {
+        ArrayList<T> list = new ArrayList<>();
+        Optional<T> identifiableObject = Optional.of( manager.getNoAcl( getEntityClass(), uid ) );
+
+        if ( identifiableObject.isPresent() )
+        {
+            list.add( identifiableObject.get() );
+        }
+
+        return list; //TODO consider ACL
     }
 
     protected Schema getSchema()
@@ -427,17 +448,20 @@
         return schemaService.getDynamicSchema( getEntityClass() );
     }
 
-    protected void addAccessProperties( T object )
+    protected void addAccessProperties( List<T> objects )
     {
-        Access access = new Access();
-        access.setManage( aclService.canManage( currentUserService.getCurrentUser(), object ) );
-        access.setExternalize( aclService.canExternalize( currentUserService.getCurrentUser(), object.getClass() ) );
-        access.setWrite( aclService.canWrite( currentUserService.getCurrentUser(), object ) );
-        access.setRead( aclService.canRead( currentUserService.getCurrentUser(), object ) );
-        access.setUpdate( aclService.canUpdate( currentUserService.getCurrentUser(), object ) );
-        access.setDelete( aclService.canDelete( currentUserService.getCurrentUser(), object ) );
+        for ( T object : objects )
+        {
+            Access access = new Access();
+            access.setManage( aclService.canManage( currentUserService.getCurrentUser(), object ) );
+            access.setExternalize( aclService.canExternalize( currentUserService.getCurrentUser(), object.getClass() ) );
+            access.setWrite( aclService.canWrite( currentUserService.getCurrentUser(), object ) );
+            access.setRead( aclService.canRead( currentUserService.getCurrentUser(), object ) );
+            access.setUpdate( aclService.canUpdate( currentUserService.getCurrentUser(), object ) );
+            access.setDelete( aclService.canDelete( currentUserService.getCurrentUser(), object ) );
 
-        ((BaseIdentifiableObject) object).setAccess( access );
+            ((BaseIdentifiableObject) object).setAccess( access );
+        }
     }
 
     protected void handleLinksAndAccess( WebOptions options, List<T> entityList )
@@ -449,10 +473,7 @@
 
         if ( entityList != null && aclService.isSupported( getEntityClass() ) )
         {
-            for ( T object : entityList )
-            {
-                addAccessProperties( object );
-            }
+            addAccessProperties( entityList );
         }
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java	2014-06-03 09:14:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java	2014-06-11 11:03:34 +0000
@@ -148,26 +148,26 @@
     public void getFormJson( @PathVariable( "uid" ) String uid, @RequestParam( value = "ou", required = false ) String orgUnit,
         @RequestParam( value = "pe", required = false ) String period, HttpServletResponse response ) throws IOException
     {
-        DataSet dataSet = getEntity( uid );
+        List<DataSet> dataSets = getEntity( uid );
 
-        if ( dataSet == null )
+        if ( dataSets.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "Object not found for uid: " + uid );
             return;
         }
 
-        i18nService.internationalise( dataSet );
-        i18nService.internationalise( dataSet.getDataElements() );
-        i18nService.internationalise( dataSet.getSections() );
+        i18nService.internationalise( dataSets.get( 0 ) );
+        i18nService.internationalise( dataSets.get( 0 ).getDataElements() );
+        i18nService.internationalise( dataSets.get( 0 ).getSections() );
 
-        Form form = FormUtils.fromDataSet( dataSet );
+        Form form = FormUtils.fromDataSet( dataSets.get( 0 ) );
 
         if ( orgUnit != null && !orgUnit.isEmpty() && period != null && !period.isEmpty() )
         {
             OrganisationUnit ou = manager.get( OrganisationUnit.class, orgUnit );
             Period p = PeriodType.getPeriodFromIsoString( period );
 
-            Collection<DataValue> dataValues = dataValueService.getDataValues( ou, p, dataSet.getDataElements() );
+            Collection<DataValue> dataValues = dataValueService.getDataValues( ou, p, dataSets.get( 0 ).getDataElements() );
 
             FormUtils.fillWithDataValues( form, dataValues );
         }
@@ -184,35 +184,35 @@
         @RequestParam( value = "comment", defaultValue = "true", required = false ) boolean comment,
         HttpServletResponse response ) throws IOException
     {
-        DataSet dataSet = getEntity( uid );
+        List<DataSet> dataSets = getEntity( uid );
 
-        if ( dataSet == null )
+        if ( dataSets.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "Object not found for uid: " + uid );
             return null;
         }
 
         Period pe = periodService.getPeriod( period );
-        return dataValueSetService.getDataValueSetTemplate( dataSet, pe, orgUnits, comment, orgUnitIdScheme, dataElementIdScheme );
+        return dataValueSetService.getDataValueSetTemplate( dataSets.get( 0 ), pe, orgUnits, comment, orgUnitIdScheme, dataElementIdScheme );
     }
 
     @RequestMapping( value = "/{uid}/form", method = RequestMethod.GET, produces = { "application/xml", "text/xml" } )
     public void getFormXml( @PathVariable( "uid" ) String uid, @RequestParam( value = "ou", required = false ) String orgUnit,
         @RequestParam( value = "pe", required = false ) String period, HttpServletResponse response ) throws IOException
     {
-        DataSet dataSet = getEntity( uid );
+        List<DataSet> dataSets = getEntity( uid );
 
-        if ( dataSet == null )
+        if ( dataSets.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "Object not found for uid: " + uid );
             return;
         }
 
-        i18nService.internationalise( dataSet );
-        i18nService.internationalise( dataSet.getDataElements() );
-        i18nService.internationalise( dataSet.getSections() );
+        i18nService.internationalise( dataSets.get( 0 ) );
+        i18nService.internationalise( dataSets.get( 0 ).getDataElements() );
+        i18nService.internationalise( dataSets.get( 0 ).getSections() );
 
-        Form form = FormUtils.fromDataSet( dataSet );
+        Form form = FormUtils.fromDataSet( dataSets.get( 0 ) );
 
         if ( orgUnit != null && !orgUnit.isEmpty() && period != null && !period.isEmpty() )
         {
@@ -221,7 +221,7 @@
 
             Period p = PeriodType.getPeriodFromIsoString( period );
 
-            Collection<DataValue> dataValues = dataValueService.getDataValues( ou, p, dataSet.getDataElements() );
+            Collection<DataValue> dataValues = dataValueService.getDataValues( ou, p, dataSets.get( 0 ).getDataElements() );
 
             FormUtils.fillWithDataValues( form, dataValues );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IdentifiableObjectController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IdentifiableObjectController.java	2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IdentifiableObjectController.java	2014-06-11 11:03:34 +0000
@@ -28,23 +28,35 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.common.BaseIdentifiableObject;
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import org.hisp.dhis.common.IdentifiableObject;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import java.util.List;
+
 /**
  * @author Lars Helge Overland
  */
 @Controller
-@RequestMapping( value = IdentifiableObjectController.RESOURCE_PATH )
+@RequestMapping(value = IdentifiableObjectController.RESOURCE_PATH)
 public class IdentifiableObjectController
-    extends AbstractCrudController<BaseIdentifiableObject>
+    extends AbstractCrudController<IdentifiableObject>
 {
     public static final String RESOURCE_PATH = "/identifiableObjects";
-    
+
     @Override
-    public BaseIdentifiableObject getEntity( String uid )
+    public List<IdentifiableObject> getEntity( String uid )
     {
-        return manager.get( uid );
+        List<IdentifiableObject> identifiableObjects = Lists.newArrayList();
+        Optional<IdentifiableObject> optional = Optional.of( manager.get( uid ) );
+
+        if ( optional.isPresent() )
+        {
+            identifiableObjects.add( optional.get() );
+        }
+
+        return identifiableObjects;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java	2014-06-09 10:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java	2014-06-11 11:03:34 +0000
@@ -73,16 +73,16 @@
         Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        DataElementGroup dataElementGroup = getEntity( uid );
+        List<DataElementGroup> dataElementGroups = getEntity( uid );
 
-        if ( dataElementGroup == null )
+        if ( dataElementGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid );
             return null;
         }
 
         WebMetaData metaData = new WebMetaData();
-        List<DataElement> dataElements = new ArrayList<DataElement>( dataElementGroup.getMembers() );
+        List<DataElement> dataElements = new ArrayList<DataElement>( dataElementGroups.get( 0 ).getMembers() );
         Collections.sort( dataElements, IdentifiableObjectNameComparator.INSTANCE );
 
         if ( options.hasPaging() )
@@ -111,9 +111,9 @@
         HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        DataElementGroup dataElementGroup = getEntity( uid );
+        List<DataElementGroup> dataElementGroups = getEntity( uid );
 
-        if ( dataElementGroup == null )
+        if ( dataElementGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid );
             return null;
@@ -121,7 +121,7 @@
 
         WebMetaData metaData = new WebMetaData();
         List<DataElement> dataElements = new ArrayList<DataElement>();
-        List<DataElement> members = new ArrayList<DataElement>( dataElementGroup.getMembers() );
+        List<DataElement> members = new ArrayList<DataElement>( dataElementGroups.get( 0 ).getMembers() );
         Collections.sort( members, IdentifiableObjectNameComparator.INSTANCE );
 
         for ( DataElement dataElement : members )
@@ -157,16 +157,16 @@
         Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        DataElementGroup dataElementGroup = getEntity( uid );
+        List<DataElementGroup> dataElementGroups = getEntity( uid );
 
-        if ( dataElementGroup == null )
+        if ( dataElementGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid );
             return null;
         }
 
         WebMetaData metaData = new WebMetaData();
-        List<DataElementOperand> dataElementOperands = Lists.newArrayList( dataElementCategoryService.getOperands( dataElementGroup.getMembers() ) );
+        List<DataElementOperand> dataElementOperands = Lists.newArrayList( dataElementCategoryService.getOperands( dataElementGroups.get( 0 ).getMembers() ) );
 
         Collections.sort( dataElementOperands, IdentifiableObjectNameComparator.INSTANCE );
 
@@ -200,9 +200,9 @@
         HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        DataElementGroup dataElementGroup = getEntity( uid );
+        List<DataElementGroup> dataElementGroups = getEntity( uid );
 
-        if ( dataElementGroup == null )
+        if ( dataElementGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid );
             return null;
@@ -211,7 +211,7 @@
         WebMetaData metaData = new WebMetaData();
         List<DataElementOperand> dataElementOperands = Lists.newArrayList();
 
-        for ( DataElementOperand dataElementOperand : dataElementCategoryService.getOperands( dataElementGroup.getMembers() ) )
+        for ( DataElementOperand dataElementOperand : dataElementCategoryService.getOperands( dataElementGroups.get( 0 ).getMembers() ) )
         {
             if ( dataElementOperand.getDisplayName().toLowerCase().contains( q.toLowerCase() ) )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/indicator/IndicatorGroupController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/indicator/IndicatorGroupController.java	2014-06-09 10:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/indicator/IndicatorGroupController.java	2014-06-11 11:03:34 +0000
@@ -28,24 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.common.PagerUtils;
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorGroup;
 import org.hisp.dhis.schema.descriptors.IndicatorGroupSchemaDescriptor;
 import org.hisp.dhis.webapi.controller.AbstractCrudController;
 import org.hisp.dhis.webapi.controller.WebMetaData;
 import org.hisp.dhis.webapi.controller.WebOptions;
 import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.common.Pager;
-import org.hisp.dhis.common.PagerUtils;
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.indicator.Indicator;
-import org.hisp.dhis.indicator.IndicatorGroup;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.util.StringUtils;
@@ -54,6 +46,13 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -67,16 +66,16 @@
         Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        IndicatorGroup indicatorGroup = getEntity( uid );
+        List<IndicatorGroup> indicatorGroups = getEntity( uid );
 
-        if ( indicatorGroup == null )
+        if ( indicatorGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "IndicatorGroup not found for uid: " + uid );
             return null;
         }
 
         WebMetaData metaData = new WebMetaData();
-        List<Indicator> indicators = new ArrayList<Indicator>( indicatorGroup.getMembers() );
+        List<Indicator> indicators = new ArrayList<Indicator>( indicatorGroups.get( 0 ).getMembers() );
         Collections.sort( indicators, IdentifiableObjectNameComparator.INSTANCE );
 
         if ( options.hasPaging() )
@@ -105,9 +104,9 @@
         HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        IndicatorGroup indicatorGroup = getEntity( uid );
+        List<IndicatorGroup> indicatorGroups = getEntity( uid );
 
-        if ( indicatorGroup == null )
+        if ( indicatorGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "IndicatorGroup not found for uid: " + uid );
             return null;
@@ -115,7 +114,7 @@
 
         WebMetaData metaData = new WebMetaData();
         List<Indicator> indicators = new ArrayList<Indicator>();
-        List<Indicator> members = new ArrayList<Indicator>( indicatorGroup.getMembers() );
+        List<Indicator> members = new ArrayList<Indicator>( indicatorGroups.get( 0 ).getMembers() );
         Collections.sort( members, IdentifiableObjectNameComparator.INSTANCE );
 
         for ( Indicator indicator : members )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java	2014-06-09 10:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java	2014-06-11 11:03:34 +0000
@@ -28,9 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Lists;
 import org.hisp.dhis.common.Pager;
-import org.hisp.dhis.dxf2.metadata.MetaData;
-import org.hisp.dhis.node.types.RootNode;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitByLevelComparator;
@@ -40,28 +39,19 @@
 import org.hisp.dhis.webapi.controller.AbstractCrudController;
 import org.hisp.dhis.webapi.controller.WebMetaData;
 import org.hisp.dhis.webapi.controller.WebOptions;
-import org.hisp.dhis.webapi.controller.exception.NotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping( value = OrganisationUnitSchemaDescriptor.API_ENDPOINT )
+@RequestMapping(value = OrganisationUnitSchemaDescriptor.API_ENDPOINT)
 public class OrganisationUnitController
     extends AbstractCrudController<OrganisationUnit>
 {
@@ -172,21 +162,36 @@
         return entityList;
     }
 
+    @Override
+    protected List<OrganisationUnit> getEntity( String uid, WebOptions options )
+    {
+        OrganisationUnit organisationUnit = manager.get( getEntityClass(), uid );
+
+        if ( organisationUnit == null )
+        {
+            return Lists.newArrayList();
+        }
+
+        List<OrganisationUnit> organisationUnits = Lists.newArrayList();
+
+        if ( options.getOptions().containsKey( "includeChildren" ) )
+        {
+            organisationUnits.add( organisationUnit );
+            organisationUnits.addAll( organisationUnit.getChildren() );
+        }
+        else if ( options.getOptions().containsKey( "includeDescendants" ) )
+        {
+            organisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( uid ) );
+        }
+        else
+        {
+            organisationUnits.add( organisationUnit );
+        }
+
+        return organisationUnits;
+    }
 
     /* TODO can this be replaced by inclusion/filter?
-    @Override
-    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
-    public RootNode getObject( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
-        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
-    {
-        WebOptions options = new WebOptions( parameters );
-        OrganisationUnit entity = getEntity( uid );
-
-        if ( entity == null )
-        {
-            throw new NotFoundException( uid );
-        }
-
         Integer maxLevel = null;
 
         if ( options.getOptions().containsKey( "maxLevel" ) )
@@ -225,43 +230,5 @@
 
             return StringUtils.uncapitalize( getEntitySimpleName() );
         }
-        else 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 );
-        }
-        else 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 );
-        }
-
-        if ( options.hasLinks() )
-        {
-            WebUtils.generateLinks( entity );
-        }
-
-        postProcessEntity( entity );
-        postProcessEntity( entity, options, parameters );
-
-        model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
-
-        return StringUtils.uncapitalize( getEntitySimpleName() );
-    }
     */
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitGroupController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitGroupController.java	2014-06-09 10:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitGroupController.java	2014-06-11 11:03:34 +0000
@@ -86,16 +86,16 @@
         Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        OrganisationUnitGroup organisationUnitGroup = getEntity( uid );
+        List<OrganisationUnitGroup> organisationUnitGroups = getEntity( uid );
 
-        if ( organisationUnitGroup == null )
+        if ( organisationUnitGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "OrganisationUnitGroup not found for uid: " + uid );
             return null;
         }
 
         WebMetaData metaData = new WebMetaData();
-        List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitGroup.getMembers() );
+        List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitGroups.get( 0 ).getMembers() );
         Collections.sort( organisationUnits, IdentifiableObjectNameComparator.INSTANCE );
 
         if ( options.hasPaging() )
@@ -124,9 +124,9 @@
         HttpServletResponse response ) throws Exception
     {
         WebOptions options = new WebOptions( parameters );
-        OrganisationUnitGroup organisationUnitGroup = getEntity( uid );
+        List<OrganisationUnitGroup> organisationUnitGroups = getEntity( uid );
 
-        if ( organisationUnitGroup == null )
+        if ( organisationUnitGroups.isEmpty() )
         {
             ContextUtils.notFoundResponse( response, "OrganisationUnitGroup not found for uid: " + uid );
             return null;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2014-06-06 07:40:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2014-06-11 11:03:34 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.common.Pager;
@@ -136,9 +137,17 @@
     }
 
     @Override
-    protected User getEntity( String uid )
+    protected List<User> getEntity( String uid )
     {
-        return userService.getUser( uid );
+        List<User> users = Lists.newArrayList();
+        Optional<User> user = Optional.of( userService.getUser( uid ) );
+
+        if ( user.isPresent() )
+        {
+            users.add( user.get() );
+        }
+
+        return users;
     }
 
     //--------------------------------------------------------------------------
@@ -188,15 +197,15 @@
     public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
         input ) throws Exception
     {
-        User object = getEntity( uid );
+        List<User> users = getEntity( uid );
 
-        if ( object == null )
+        if ( users.isEmpty() )
         {
             ContextUtils.conflictResponse( response, getEntityName() + " does not exist: " + uid );
             return;
         }
 
-        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), object ) )
+        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), users.get( 0 ) ) )
         {
             throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
         }
@@ -219,15 +228,15 @@
     public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
         input ) throws Exception
     {
-        User object = getEntity( uid );
+        List<User> users = getEntity( uid );
 
-        if ( object == null )
+        if ( users.isEmpty() )
         {
             ContextUtils.conflictResponse( response, getEntityName() + " does not exist: " + uid );
             return;
         }
 
-        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), object ) )
+        if ( !aclService.canUpdate( currentUserService.getCurrentUser(), users.get( 0 ) ) )
         {
             throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
         }