=== 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 parameters, Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception @@ -202,32 +203,33 @@ } WebOptions options = new WebOptions( parameters ); - T entity = getEntity( uid ); + List 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 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 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 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 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 getEntity( String uid ) + { + return getEntity( uid, new WebOptions( new HashMap() ) ); + } + + protected List getEntity( String uid, WebOptions options ) + { + ArrayList list = new ArrayList<>(); + Optional 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 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 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 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 dataValues = dataValueService.getDataValues( ou, p, dataSet.getDataElements() ); + Collection 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 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 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 dataValues = dataValueService.getDataValues( ou, p, dataSet.getDataElements() ); + Collection 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 + extends AbstractCrudController { public static final String RESOURCE_PATH = "/identifiableObjects"; - + @Override - public BaseIdentifiableObject getEntity( String uid ) + public List getEntity( String uid ) { - return manager.get( uid ); + List identifiableObjects = Lists.newArrayList(); + Optional 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 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 dataElements = new ArrayList( dataElementGroup.getMembers() ); + List dataElements = new ArrayList( 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 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 dataElements = new ArrayList(); - List members = new ArrayList( dataElementGroup.getMembers() ); + List members = new ArrayList( 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 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 dataElementOperands = Lists.newArrayList( dataElementCategoryService.getOperands( dataElementGroup.getMembers() ) ); + List 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 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 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 */ @@ -67,16 +66,16 @@ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception { WebOptions options = new WebOptions( parameters ); - IndicatorGroup indicatorGroup = getEntity( uid ); + List 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 indicators = new ArrayList( indicatorGroup.getMembers() ); + List indicators = new ArrayList( 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 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 indicators = new ArrayList(); - List members = new ArrayList( indicatorGroup.getMembers() ); + List members = new ArrayList( 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 */ @Controller -@RequestMapping( value = OrganisationUnitSchemaDescriptor.API_ENDPOINT ) +@RequestMapping(value = OrganisationUnitSchemaDescriptor.API_ENDPOINT) public class OrganisationUnitController extends AbstractCrudController { @@ -172,21 +162,36 @@ return entityList; } + @Override + protected List getEntity( String uid, WebOptions options ) + { + OrganisationUnit organisationUnit = manager.get( getEntityClass(), uid ); + + if ( organisationUnit == null ) + { + return Lists.newArrayList(); + } + + List 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 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 entities = new ArrayList( - 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 entities = new ArrayList(); - 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 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 organisationUnits = new ArrayList( organisationUnitGroup.getMembers() ); + List organisationUnits = new ArrayList( 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 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 getEntity( String uid ) { - return userService.getUser( uid ); + List users = Lists.newArrayList(); + Optional 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 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 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." ); }