=== 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 @@ -69,8 +67,8 @@ @Autowired private DataElementOperandService dataElementOperandService; - @RequestMapping(value = "/{uid}/members", method = RequestMethod.GET) - public String getMembers( @PathVariable("uid") String uid, @RequestParam Map parameters, + @RequestMapping( value = "/{uid}/members", method = RequestMethod.GET ) + public String getMembers( @PathVariable( "uid" ) String uid, @RequestParam Map 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 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 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 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 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 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 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 */ @Controller -@RequestMapping( value = IndicatorGroupController.RESOURCE_PATH ) +@RequestMapping(value = IndicatorGroupController.RESOURCE_PATH) public class IndicatorGroupController extends AbstractCrudController { @@ -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 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 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 */ @Controller -@RequestMapping( value = OrganisationUnitGroupController.RESOURCE_PATH ) +@RequestMapping(value = OrganisationUnitGroupController.RESOURCE_PATH) public class OrganisationUnitGroupController extends AbstractCrudController { @@ -82,10 +82,8 @@ // -------------------------------------------------------------------------- @RequestMapping( value = "/{uid}/members", method = RequestMethod.GET ) - public String getMembers( @PathVariable( "uid" ) - String uid, @RequestParam - Map parameters, Model model, HttpServletRequest request, HttpServletResponse response ) - throws Exception + public String getMembers( @PathVariable( "uid" ) String uid, @RequestParam Map 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 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 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 )