← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13946: support pager in filtered objects

 

------------------------------------------------------------
revno: 13946
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-02-06 12:59:21 +0700
message:
  support pager in filtered objects
modified:
  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/utils/WebUtils.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-02-06 05:54:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-02-06 05:59:21 +0000
@@ -102,7 +102,12 @@
         postProcessEntities( entityList );
         postProcessEntities( entityList, options, parameters );
 
-        List<Map<String, Object>> output = WebUtils.filterFields( entityList, fields );
+        Map<String, Object> output = WebUtils.filterFields( entityList, fields );
+
+        if ( options.hasPaging() )
+        {
+            output.put( "pager", metaData.getPager() );
+        }
 
         JacksonUtils.toJson( response.getOutputStream(), output );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java	2014-02-06 05:54:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java	2014-02-06 05:59:21 +0000
@@ -185,14 +185,17 @@
         }
     }
 
-    public static <T extends IdentifiableObject> List<Map<String, Object>> filterFields( List<T> entityList, String fields )
+    public static <T extends IdentifiableObject> Map<String, Object> filterFields( List<T> entityList, String fields )
     {
         if ( entityList.isEmpty() || fields == null )
         {
-            return Lists.newArrayList();
+            return Maps.newHashMap();
         }
 
-        List<Map<String, Object>> output = Lists.newArrayList();
+        Map<String, Object> output = Maps.newHashMap();
+        ArrayList<Object> objects = Lists.newArrayList();
+        output.put( "objects", objects );
+
         Map<String, Method> classMap = ReflectionUtils.getJacksonClassMap( entityList.get( 0 ).getClass() );
         String[] split = fields.split( "," );
 
@@ -214,7 +217,7 @@
                 }
             }
 
-            output.add( objMap );
+            objects.add( objMap );
         }
 
         return output;