------------------------------------------------------------ revno: 15654 committer: Morten Olav Hansen <morte...@gmail.com> branch nick: dhis2 timestamp: Thu 2014-06-12 17:36:36 +0200 message: removed /api/type/id/members (/q/) from API, have already been replaced by fields= in appropriate places modified: 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/OrganisationUnitGroupController.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/dataelement/DataElementGroupController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java 2014-06-11 20:27:54 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementGroupController.java 2014-06-12 15:36:36 +0000 @@ -32,15 +32,14 @@ import org.hisp.dhis.common.Pager; import org.hisp.dhis.common.PagerUtils; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; -import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementGroup; import org.hisp.dhis.dataelement.DataElementOperand; import org.hisp.dhis.schema.descriptors.DataElementGroupSchemaDescriptor; import org.hisp.dhis.webapi.controller.AbstractCrudController; +import org.hisp.dhis.webapi.utils.ContextUtils; import org.hisp.dhis.webapi.webdomain.WebMetaData; import org.hisp.dhis.webapi.webdomain.WebOptions; -import org.hisp.dhis.webapi.utils.ContextUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -52,7 +51,6 @@ 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; @@ -68,90 +66,6 @@ @Autowired private DataElementCategoryService dataElementCategoryService; - @RequestMapping( value = "/{uid}/members", method = RequestMethod.GET ) - public String getMembers( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters, - Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception - { - WebOptions options = new WebOptions( parameters ); - List<DataElementGroup> dataElementGroups = getEntity( uid ); - - if ( dataElementGroups.isEmpty() ) - { - ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid ); - return null; - } - - WebMetaData metaData = new WebMetaData(); - List<DataElement> dataElements = new ArrayList<DataElement>( dataElementGroups.get( 0 ).getMembers() ); - Collections.sort( dataElements, IdentifiableObjectNameComparator.INSTANCE ); - - if ( options.hasPaging() ) - { - Pager pager = new Pager( options.getPage(), dataElements.size(), options.getPageSize() ); - metaData.setPager( pager ); - dataElements = PagerUtils.pageCollection( dataElements, pager ); - } - - metaData.setDataElements( dataElements ); - - if ( options.hasLinks() ) - { - linkService.generateLinks( metaData ); - } - - model.addAttribute( "model", metaData ); - model.addAttribute( "viewClass", options.getViewClass( "basic" ) ); - - return StringUtils.uncapitalize( getEntitySimpleName() ); - } - - @RequestMapping( value = "/{uid}/members/query/{q}", method = RequestMethod.GET ) - public String getMembersByQuery( @PathVariable( "uid" ) String uid, @PathVariable( "q" ) String q, - @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request, - HttpServletResponse response ) throws Exception - { - WebOptions options = new WebOptions( parameters ); - List<DataElementGroup> dataElementGroups = getEntity( uid ); - - if ( dataElementGroups.isEmpty() ) - { - ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid ); - return null; - } - - WebMetaData metaData = new WebMetaData(); - List<DataElement> dataElements = new ArrayList<DataElement>(); - List<DataElement> members = new ArrayList<DataElement>( dataElementGroups.get( 0 ).getMembers() ); - Collections.sort( members, IdentifiableObjectNameComparator.INSTANCE ); - - for ( DataElement dataElement : members ) - { - if ( dataElement.getDisplayName().toLowerCase().contains( q.toLowerCase() ) ) - { - dataElements.add( dataElement ); - } - } - - if ( options.hasPaging() ) - { - Pager pager = new Pager( options.getPage(), dataElements.size(), options.getPageSize() ); - metaData.setPager( pager ); - dataElements = PagerUtils.pageCollection( dataElements, pager ); - } - - metaData.setDataElements( dataElements ); - - if ( options.hasLinks() ) - { - linkService.generateLinks( metaData ); - } - - model.addAttribute( "model", metaData ); - model.addAttribute( "viewClass", options.getViewClass( "basic" ) ); - - return StringUtils.uncapitalize( getEntitySimpleName() ); - } - @RequestMapping( value = "/{uid}/operands", method = RequestMethod.GET ) public String getOperands( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception === 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-11 20:27:54 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/indicator/IndicatorGroupController.java 2014-06-12 15:36:36 +0000 @@ -28,30 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -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.webdomain.WebMetaData; -import org.hisp.dhis.webapi.webdomain.WebOptions; -import org.hisp.dhis.webapi.utils.ContextUtils; 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 <morte...@gmail.com> @@ -61,87 +42,4 @@ public class IndicatorGroupController extends AbstractCrudController<IndicatorGroup> { - @RequestMapping( value = "/{uid}/members", method = RequestMethod.GET ) - public String getMembers( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters, - Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception - { - WebOptions options = new WebOptions( parameters ); - List<IndicatorGroup> indicatorGroups = getEntity( uid ); - - if ( indicatorGroups.isEmpty() ) - { - ContextUtils.notFoundResponse( response, "IndicatorGroup not found for uid: " + uid ); - return null; - } - - WebMetaData metaData = new WebMetaData(); - List<Indicator> indicators = new ArrayList<Indicator>( indicatorGroups.get( 0 ).getMembers() ); - Collections.sort( indicators, IdentifiableObjectNameComparator.INSTANCE ); - - if ( options.hasPaging() ) - { - Pager pager = new Pager( options.getPage(), indicators.size(), options.getPageSize() ); - metaData.setPager( pager ); - indicators = PagerUtils.pageCollection( indicators, pager ); - } - - metaData.setIndicators( indicators ); - - if ( options.hasLinks() ) - { - linkService.generateLinks( metaData ); - } - - model.addAttribute( "model", metaData ); - model.addAttribute( "viewClass", options.getViewClass( "basic" ) ); - - return StringUtils.uncapitalize( getEntitySimpleName() ); - } - - @RequestMapping( value = "/{uid}/members/query/{q}", method = RequestMethod.GET ) - public String getMembersByQuery( @PathVariable( "uid" ) String uid, @PathVariable( "q" ) String q, - @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request, - HttpServletResponse response ) throws Exception - { - WebOptions options = new WebOptions( parameters ); - List<IndicatorGroup> indicatorGroups = getEntity( uid ); - - if ( indicatorGroups.isEmpty() ) - { - ContextUtils.notFoundResponse( response, "IndicatorGroup not found for uid: " + uid ); - return null; - } - - WebMetaData metaData = new WebMetaData(); - List<Indicator> indicators = new ArrayList<Indicator>(); - List<Indicator> members = new ArrayList<Indicator>( indicatorGroups.get( 0 ).getMembers() ); - Collections.sort( members, IdentifiableObjectNameComparator.INSTANCE ); - - for ( Indicator indicator : members ) - { - if ( indicator.getDisplayName().toLowerCase().contains( q.toLowerCase() ) ) - { - indicators.add( indicator ); - } - } - - if ( options.hasPaging() ) - { - Pager pager = new Pager( options.getPage(), indicators.size(), options.getPageSize() ); - metaData.setPager( pager ); - indicators = PagerUtils.pageCollection( indicators, pager ); - } - - metaData.setIndicators( indicators ); - - if ( options.hasLinks() ) - { - linkService.generateLinks( metaData ); - } - - model.addAttribute( "model", metaData ); - model.addAttribute( "viewClass", options.getViewClass( "basic" ) ); - - 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-11 20:27:54 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitGroupController.java 2014-06-12 15:36:36 +0000 @@ -28,36 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.hisp.dhis.common.Pager; -import org.hisp.dhis.common.PagerUtils; -import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitGroup; -import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; -import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.schema.descriptors.OrganisationUnitGroupSchemaDescriptor; import org.hisp.dhis.webapi.controller.AbstractCrudController; -import org.hisp.dhis.webapi.webdomain.WebMetaData; -import org.hisp.dhis.webapi.webdomain.WebOptions; -import org.hisp.dhis.webapi.utils.ContextUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.security.access.prepost.PreAuthorize; 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 org.springframework.web.bind.annotation.ResponseStatus; - -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 <morte...@gmail.com> @@ -67,131 +42,4 @@ public class OrganisationUnitGroupController extends AbstractCrudController<OrganisationUnitGroup> { - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - @Autowired - private OrganisationUnitGroupService organisationUnitGroupService; - - @Autowired - private OrganisationUnitService organisationUnitService; - - // -------------------------------------------------------------------------- - // Methods - // -------------------------------------------------------------------------- - - @RequestMapping( value = "/{uid}/members", method = RequestMethod.GET ) - public String getMembers( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters, - Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception - { - WebOptions options = new WebOptions( parameters ); - List<OrganisationUnitGroup> organisationUnitGroups = getEntity( uid ); - - if ( organisationUnitGroups.isEmpty() ) - { - ContextUtils.notFoundResponse( response, "OrganisationUnitGroup not found for uid: " + uid ); - return null; - } - - WebMetaData metaData = new WebMetaData(); - List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitGroups.get( 0 ).getMembers() ); - Collections.sort( organisationUnits, IdentifiableObjectNameComparator.INSTANCE ); - - if ( options.hasPaging() ) - { - Pager pager = new Pager( options.getPage(), organisationUnits.size(), options.getPageSize() ); - metaData.setPager( pager ); - organisationUnits = PagerUtils.pageCollection( organisationUnits, pager ); - } - - metaData.setOrganisationUnits( organisationUnits ); - - if ( options.hasLinks() ) - { - linkService.generateLinks( metaData ); - } - - model.addAttribute( "model", metaData ); - model.addAttribute( "viewClass", options.getViewClass( "basic" ) ); - - return StringUtils.uncapitalize( getEntitySimpleName() ); - } - - @RequestMapping( value = "/{uid}/members/query/{q}", method = RequestMethod.GET ) - public String getMembersByQuery( @PathVariable( "uid" ) String uid, @PathVariable( "q" ) String q, - @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request, - HttpServletResponse response ) throws Exception - { - WebOptions options = new WebOptions( parameters ); - List<OrganisationUnitGroup> organisationUnitGroups = getEntity( uid ); - - if ( organisationUnitGroups.isEmpty() ) - { - ContextUtils.notFoundResponse( response, "OrganisationUnitGroup not found for uid: " + uid ); - return null; - } - - WebMetaData metaData = new WebMetaData(); - List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>(); - List<OrganisationUnit> members = new ArrayList<OrganisationUnit>(); - Collections.sort( members, IdentifiableObjectNameComparator.INSTANCE ); - - for ( OrganisationUnit organisationUnit : members ) - { - if ( organisationUnit.getDisplayName().toLowerCase().contains( q.toLowerCase() ) ) - { - organisationUnits.add( organisationUnit ); - } - } - - if ( options.hasPaging() ) - { - Pager pager = new Pager( options.getPage(), organisationUnits.size(), options.getPageSize() ); - metaData.setPager( pager ); - organisationUnits = PagerUtils.pageCollection( organisationUnits, pager ); - } - - metaData.setOrganisationUnits( organisationUnits ); - - if ( options.hasLinks() ) - { - linkService.generateLinks( metaData ); - } - - model.addAttribute( "model", metaData ); - model.addAttribute( "viewClass", options.getViewClass( "basic" ) ); - - return StringUtils.uncapitalize( getEntitySimpleName() ); - } - - @RequestMapping( value = "/{uid}/members/{orgUnitUid}", method = RequestMethod.POST ) - @PreAuthorize( "hasRole('ALL') or hasRole('F_ORGANISATIONUNIT_ADD')" ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void addMember( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, - @PathVariable( "orgUnitUid" ) String orgUnitUid ) throws Exception - { - OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup( uid ); - OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUid ); - - if ( group.addOrganisationUnit( unit ) ) - { - organisationUnitGroupService.updateOrganisationUnitGroup( group ); - } - } - - @RequestMapping( value = "/{uid}/members/{orgUnitUid}", method = RequestMethod.DELETE ) - @PreAuthorize( "hasRole('ALL') or hasRole('F_ORGANISATIONUNIT_ADD')" ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void removeMember( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, - @PathVariable( "orgUnitUid" ) String orgUnitUid ) throws Exception - { - OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup( uid ); - OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUid ); - - if ( group.removeOrganisationUnit( unit ) ) - { - organisationUnitGroupService.updateOrganisationUnitGroup( group ); - } - } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp