=== 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-09-29 04:34:06 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-09-30 04:38:03 +0000 @@ -127,7 +127,7 @@ // GET //-------------------------------------------------------------------------- - @RequestMapping(method = RequestMethod.GET) + @RequestMapping( method = RequestMethod.GET ) public @ResponseBody RootNode getObjectList( @RequestParam Map parameters, HttpServletResponse response, HttpServletRequest request ) { @@ -148,7 +148,7 @@ if ( filters.isEmpty() || DataElementOperand.class.isAssignableFrom( getEntityClass() ) ) { - entityList = getEntityList( metaData, options ); + entityList = getEntityList( metaData, options, filters ); } else { @@ -328,7 +328,7 @@ // POST //-------------------------------------------------------------------------- - @RequestMapping(method = RequestMethod.POST, consumes = { "application/xml", "text/xml" }) + @RequestMapping( method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } ) public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) ) @@ -353,7 +353,7 @@ renderService.toXml( response.getOutputStream(), summary ); } - @RequestMapping(method = RequestMethod.POST, consumes = "application/json") + @RequestMapping( method = RequestMethod.POST, consumes = "application/json" ) public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) ) @@ -382,9 +382,9 @@ // PUT //-------------------------------------------------------------------------- - @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE }) - @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception { List objects = getEntity( uid ); @@ -413,9 +413,9 @@ renderService.toXml( response.getOutputStream(), summary ); } - @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception { List objects = getEntity( uid ); @@ -448,9 +448,9 @@ // DELETE //-------------------------------------------------------------------------- - @RequestMapping(value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid ) + @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception { List objects = getEntity( uid ); @@ -525,6 +525,11 @@ protected List getEntityList( WebMetaData metaData, WebOptions options ) { + return getEntityList( metaData, options, null ); + } + + protected List getEntityList( WebMetaData metaData, WebOptions options, List filters ) + { List entityList; if ( options.getOptions().containsKey( "query" ) ) @@ -602,7 +607,7 @@ private String entitySimpleName; - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) protected Class getEntityClass() { if ( entityClass == null ) @@ -634,7 +639,7 @@ return entitySimpleName; } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) protected T getEntityInstance() { try === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2014-08-08 08:54:26 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2014-09-30 04:38:03 +0000 @@ -33,6 +33,7 @@ import org.hisp.dhis.common.PagerUtils; 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.DataElementOperandSchemaDescriptor; import org.hisp.dhis.webapi.controller.AbstractCrudController; @@ -43,6 +44,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; /** @@ -55,7 +57,8 @@ @Autowired private DataElementCategoryService categoryService; - protected List getEntityList( WebMetaData metaData, WebOptions options ) + @Override + protected List getEntityList( WebMetaData metaData, WebOptions options, List filters ) { List dataElementOperands; @@ -65,8 +68,31 @@ } else { - List dataElements = new ArrayList<>( manager.getAllSorted( DataElement.class ) ); - dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElements ) ); + Iterator iterator = filters.iterator(); + String deGroup = null; + + while ( iterator.hasNext() ) + { + String filter = iterator.next(); + + if ( filter.startsWith( "dataElement.dataElementGroup.id:eq:" ) ) + { + deGroup = filter.substring( "dataElement.dataElementGroup.id:eq:".length() ); + iterator.remove(); + break; + } + } + + if ( deGroup != null ) + { + DataElementGroup dataElementGroup = manager.get( DataElementGroup.class, deGroup ); + dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElementGroup.getMembers() ) ); + } + else + { + List dataElements = new ArrayList<>( manager.getAllSorted( DataElement.class ) ); + dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElements ) ); + } } if ( options.hasPaging() )