=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2014-07-01 13:50:42 +0000 @@ -100,6 +100,8 @@ int getCount( Class clazz ); + int getCountByName( Class clazz, String name ); + // ------------------------------------------------------------------------- // NO ACL // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2014-05-05 12:22:43 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2014-07-01 13:50:42 +0000 @@ -284,6 +284,19 @@ } @Override + public int getCountByName( Class clazz, String name ) + { + GenericIdentifiableObjectStore store = getIdentifiableObjectStore( clazz ); + + if ( store != null ) + { + return store.getCountLikeName( name ); + } + + return 0; + } + + @Override @SuppressWarnings("unchecked") public Collection getLikeName( Class clazz, String name ) { === 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-20 11:14:18 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-07-01 13:50:42 +0000 @@ -79,6 +79,7 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -125,7 +126,7 @@ // GET //-------------------------------------------------------------------------- - @RequestMapping( method = RequestMethod.GET ) + @RequestMapping(method = RequestMethod.GET) public @ResponseBody RootNode getObjectList( @RequestParam Map parameters, HttpServletResponse response, HttpServletRequest request ) { @@ -142,19 +143,56 @@ boolean hasPaging = options.hasPaging(); - // get full list if we are using filters - if ( filters != null && !filters.isEmpty() ) - { - options.getOptions().put( "links", "false" ); - - if ( options.hasPaging() ) - { - hasPaging = true; - options.getOptions().put( "paging", "false" ); - } - } - - List entityList = getEntityList( metaData, options ); + List entityList; + + if ( filters.isEmpty() ) + { + entityList = getEntityList( metaData, options ); + } + else + { + Iterator iterator = filters.iterator(); + String name = null; + + while ( iterator.hasNext() ) + { + String filter = iterator.next(); + + if ( filter.startsWith( "name:like:" ) ) + { + name = filter.substring( "name:like:".length() ); + iterator.remove(); + break; + } + } + + if ( name != null ) + { + int count = manager.getCountByName( getEntityClass(), name ); + + Pager pager = new Pager( options.getPage(), count, options.getPageSize() ); + metaData.setPager( pager ); + + entityList = Lists.newArrayList( manager.getBetweenByName( getEntityClass(), name, pager.getOffset(), pager.getPageSize() ) ); + } + else + { + // get full list if we are using filters + if ( !filters.isEmpty() ) + { + options.getOptions().put( "links", "false" ); + + if ( options.hasPaging() ) + { + hasPaging = true; + options.getOptions().put( "paging", "false" ); + } + } + + entityList = getEntityList( metaData, options ); + } + } + Pager pager = metaData.getPager(); // enable object filter @@ -282,7 +320,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() ) ) @@ -295,7 +333,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() ) ) @@ -312,9 +350,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 ); @@ -337,9 +375,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 ); @@ -366,9 +404,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 ) throws + @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 ); @@ -518,7 +556,7 @@ private String entitySimpleName; - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") protected Class getEntityClass() { if ( entityClass == null ) @@ -550,7 +588,7 @@ return entitySimpleName; } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") protected T getEntityInstance() { try