← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13652: implemented paging for /groups/members

 

------------------------------------------------------------
revno: 13652
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-01-08 12:19:03 +0100
message:
  implemented paging for /groups/members
modified:
  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/indicator/IndicatorGroupController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitGroupController.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/dataelement/DataElementGroupController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java	2014-01-08 11:05:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java	2014-01-08 11:19:03 +0000
@@ -30,9 +30,13 @@
 
 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;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.WebUtils;
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.common.PagerUtils;
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.springframework.stereotype.Controller;
@@ -45,6 +49,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -70,8 +76,17 @@
             return null;
         }
 
-        MetaData metaData = new MetaData();
-        metaData.setDataElements( Lists.newArrayList( dataElementGroup.getMembers() ) );
+        WebMetaData metaData = new WebMetaData();
+        List<DataElement> dataElements = Lists.newArrayList( dataElementGroup.getMembers() );
+
+        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() )
         {

=== 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-08 11:05:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/indicator/IndicatorGroupController.java	2014-01-08 11:19:03 +0000
@@ -30,10 +30,13 @@
 
 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;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.WebUtils;
-import org.hisp.dhis.dxf2.metadata.MetaData;
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.common.PagerUtils;
+import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorGroup;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -45,6 +48,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -70,8 +74,17 @@
             return null;
         }
 
-        MetaData metaData = new MetaData();
-        metaData.setIndicators( Lists.newArrayList( indicatorGroup.getMembers() ) );
+        WebMetaData metaData = new WebMetaData();
+        List<Indicator> indicators = Lists.newArrayList( indicatorGroup.getMembers() );
+
+        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() )
         {

=== 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-08 11:07:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitGroupController.java	2014-01-08 11:19:03 +0000
@@ -30,10 +30,12 @@
 
 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;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.WebUtils;
-import org.hisp.dhis.dxf2.metadata.MetaData;
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.common.PagerUtils;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
@@ -52,6 +54,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -93,8 +96,17 @@
             return null;
         }
 
-        MetaData metaData = new MetaData();
-        metaData.setOrganisationUnits( Lists.newArrayList( organisationUnitGroup.getMembers() ) );
+        WebMetaData metaData = new WebMetaData();
+        List<OrganisationUnit> organisationUnits = Lists.newArrayList( organisationUnitGroup.getMembers() );
+
+        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() )
         {