dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28753
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14398: moved api-filter from /api/type/filtered => /api/type, still wip.. only supports json for include...
------------------------------------------------------------
revno: 14398
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-03-25 11:41:38 +0100
message:
moved api-filter from /api/type/filtered => /api/type, still wip.. only supports json for include/exclude functionality
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.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/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2014-03-25 10:24:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2014-03-25 10:41:38 +0000
@@ -61,7 +61,6 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -90,22 +89,23 @@
// GET
//--------------------------------------------------------------------------
- @RequestMapping( value = "/filtered", method = RequestMethod.GET )
- public void getObjectListFiltered(
+ @RequestMapping( method = RequestMethod.GET )
+ public String getObjectList(
@RequestParam( required = false ) String include,
@RequestParam( required = false ) String exclude,
@RequestParam( value = "filter", required = false ) List<String> filters,
- @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
+ @RequestParam Map<String, String> parameters, HttpServletResponse response, Model model ) throws IOException
{
WebOptions options = new WebOptions( parameters );
WebMetaData metaData = new WebMetaData();
- options.getOptions().put( "links", "false" );
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;
@@ -115,11 +115,7 @@
List<T> entityList = getEntityList( metaData, options );
- handleLinksAndAccess( options, metaData, entityList, true );
-
- postProcessEntities( entityList );
- postProcessEntities( entityList, options, parameters );
-
+ // enable object filter
if ( filters != null && !filters.isEmpty() )
{
entityList = filterService.filterObjects( entityList, filters );
@@ -132,28 +128,6 @@
}
}
- List<Object> objects = filterService.filterProperties( entityList, include, exclude );
- Map<String, Object> output = Maps.newLinkedHashMap();
-
- if ( hasPaging )
- {
- output.put( "pager", metaData.getPager() );
- }
-
- output.put( "objects", objects );
-
- JacksonUtils.toJson( response.getOutputStream(), output );
- }
-
- @RequestMapping( method = RequestMethod.GET )
- public String getObjectList( @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request ) throws Exception
- {
- WebOptions options = new WebOptions( parameters );
- WebMetaData metaData = new WebMetaData();
- List<T> entityList = getEntityList( metaData, options );
-
- ReflectionUtils.invokeSetterMethod( ExchangeClasses.getAllExportMap().get( getEntityClass() ), metaData, entityList );
-
if ( options.getViewClass( "basic" ).equals( "basic" ) )
{
handleLinksAndAccess( options, metaData, entityList, false );
@@ -166,8 +140,27 @@
postProcessEntities( entityList );
postProcessEntities( entityList, options, parameters );
- model.addAttribute( "model", metaData );
- model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
+ // enable property filter
+ if ( include != null || exclude != null )
+ {
+ List<Object> objects = filterService.filterProperties( entityList, include, exclude );
+ Map<String, Object> output = Maps.newLinkedHashMap();
+
+ if ( hasPaging )
+ {
+ output.put( "pager", metaData.getPager() );
+ }
+
+ output.put( "objects", objects );
+ JacksonUtils.toJson( response.getOutputStream(), output );
+ }
+ else
+ {
+ ReflectionUtils.invokeSetterMethod( ExchangeClasses.getAllExportMap().get( getEntityClass() ), metaData, entityList );
+
+ model.addAttribute( "model", metaData );
+ model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
+ }
return StringUtils.uncapitalize( getEntitySimpleName() ) + "List";
}