------------------------------------------------------------ revno: 13675 committer: Morten Olav Hansen <[email protected]> branch nick: dhis2 timestamp: Thu 2014-01-09 16:03:58 +0100 message: implement /query/q for all /members and /operands modified: dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/indicator/IndicatorGroupController.java dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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/api/controller/dataelement/DataElementGroupController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java 2014-01-09 14:43:13 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java 2014-01-09 15:03:58 +0000 @@ -28,12 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.google.common.collect.Lists; import org.hisp.dhis.api.controller.AbstractCrudController; import org.hisp.dhis.api.controller.WebMetaData; import org.hisp.dhis.api.controller.WebOptions; @@ -54,7 +49,10 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import com.google.common.collect.Lists; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; /** * @author Morten Olav Hansen <[email protected]> @@ -69,8 +67,8 @@ @Autowired private DataElementOperandService dataElementOperandService; - @RequestMapping(value = "/{uid}/members", method = RequestMethod.GET) - public String getMembers( @PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, + @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 ); @@ -105,22 +103,75 @@ 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 - { - WebOptions options = new WebOptions( parameters ); - DataElementGroup dataElementGroup = getEntity( uid ); - - if ( dataElementGroup == null ) - { - ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid ); - return null; - } - - WebMetaData metaData = new WebMetaData(); - List<DataElementOperand> dataElementOperands = Lists.newArrayList( - dataElementOperandService.getDataElementOperandByDataElementGroup( dataElementGroup ) ); + @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 ); + DataElementGroup dataElementGroup = getEntity( uid ); + + if ( dataElementGroup == null ) + { + ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid ); + return null; + } + + WebMetaData metaData = new WebMetaData(); + List<DataElement> dataElements = Lists.newArrayList(); + + for ( DataElement dataElement : dataElementGroup.getMembers() ) + { + 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() ) + { + WebUtils.generateLinks( metaData ); + } + + model.addAttribute( "model", metaData ); + model.addAttribute( "viewClass", options.getViewClass( "basic" ) ); + + return StringUtils.uncapitalize( getEntitySimpleName() ); + } + + @RequestMapping( value = "/{uid}/operands/query/{q}", method = RequestMethod.GET ) + public String getOperands( @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 ); + DataElementGroup dataElementGroup = getEntity( uid ); + + if ( dataElementGroup == null ) + { + ContextUtils.notFoundResponse( response, "DataElementGroup not found for uid: " + uid ); + return null; + } + + WebMetaData metaData = new WebMetaData(); + List<DataElementOperand> dataElementOperands = Lists.newArrayList(); + + for ( DataElementOperand dataElementOperand : dataElementOperandService.getDataElementOperandByDataElementGroup( dataElementGroup ) ) + { + if ( dataElementOperand.getDisplayName().toLowerCase().contains( q.toLowerCase() ) ) + { + dataElementOperands.add( dataElementOperand ); + } + } metaData.setDataElementOperands( dataElementOperands ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/indicator/IndicatorGroupController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/indicator/IndicatorGroupController.java 2014-01-09 14:43:13 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/indicator/IndicatorGroupController.java 2014-01-09 15:03:58 +0000 @@ -55,7 +55,7 @@ * @author Morten Olav Hansen <[email protected]> */ @Controller -@RequestMapping( value = IndicatorGroupController.RESOURCE_PATH ) +@RequestMapping(value = IndicatorGroupController.RESOURCE_PATH) public class IndicatorGroupController extends AbstractCrudController<IndicatorGroup> { @@ -96,4 +96,49 @@ 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 ); + IndicatorGroup indicatorGroup = getEntity( uid ); + + if ( indicatorGroup == null ) + { + ContextUtils.notFoundResponse( response, "IndicatorGroup not found for uid: " + uid ); + return null; + } + + WebMetaData metaData = new WebMetaData(); + List<Indicator> indicators = Lists.newArrayList(); + + for ( Indicator indicator : indicatorGroup.getMembers() ) + { + 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() ) + { + WebUtils.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/api/controller/organisationunit/OrganisationUnitGroupController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitGroupController.java 2014-01-09 14:43:13 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitGroupController.java 2014-01-09 15:03:58 +0000 @@ -61,7 +61,7 @@ * @author Morten Olav Hansen <[email protected]> */ @Controller -@RequestMapping( value = OrganisationUnitGroupController.RESOURCE_PATH ) +@RequestMapping(value = OrganisationUnitGroupController.RESOURCE_PATH) public class OrganisationUnitGroupController extends AbstractCrudController<OrganisationUnitGroup> { @@ -82,10 +82,8 @@ // -------------------------------------------------------------------------- @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 + 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 ); OrganisationUnitGroup organisationUnitGroup = getEntity( uid ); @@ -119,6 +117,51 @@ 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 ); + OrganisationUnitGroup organisationUnitGroup = getEntity( uid ); + + if ( organisationUnitGroup == null ) + { + ContextUtils.notFoundResponse( response, "OrganisationUnitGroup not found for uid: " + uid ); + return null; + } + + WebMetaData metaData = new WebMetaData(); + List<OrganisationUnit> organisationUnits = Lists.newArrayList(); + + for ( OrganisationUnit organisationUnit : organisationUnitGroup.getMembers() ) + { + 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() ) + { + WebUtils.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 )
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

