------------------------------------------------------------
revno: 9296
committer: Morten Olav Hansen <[email protected]>
branch nick: dhis2
timestamp: Thu 2012-12-13 13:55:39 +0300
message:
  FRED-API: simple paging with limit/offset, defaults to paging off
modified:
  
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.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-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-13 10:24:38 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-13 10:55:39 +0000
@@ -233,26 +233,63 @@
     public String readFacilities( Model model, @RequestParam( required = false ) Boolean active,
         @RequestParam( value = "updatedSince", required = false ) Date lastUpdated,
         @RequestParam( value = "allProperties", required = false, defaultValue = "true" ) Boolean allProperties,
-        @RequestParam( value = "fields", required = false ) String fields )
+        @RequestParam( value = "fields", required = false ) String fields,
+        @RequestParam( value = "limit", required = false ) Integer limit,
+        @RequestParam( value = "offset", required = false ) Integer offset )
     {
         Facilities facilities = new Facilities();
         List<OrganisationUnit> allOrganisationUnits;
 
+        if ( offset == null )
+        {
+            offset = 0;
+        }
+
         if ( active == null && lastUpdated == null )
         {
-            allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() );
+            if ( limit != null )
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetween( offset, limit ) );
+            }
+            else
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() );
+            }
         }
         else if ( active == null )
         {
-            allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByLastUpdated( lastUpdated ) );
+            if ( limit != null )
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.
+                    getOrganisationUnitsBetweenByLastUpdated( lastUpdated, offset, limit ) );
+            }
+            else
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByLastUpdated( lastUpdated ) );
+            }
         }
         else if ( lastUpdated == null )
         {
-            allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByStatus( active ) );
+            if ( limit != null )
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetweenByStatus( active, offset, limit ) );
+            }
+            else
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByStatus( active ) );
+            }
         }
         else
         {
-            allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByStatusLastUpdated( active, lastUpdated ) );
+            if ( limit != null )
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.
+                    getOrganisationUnitsBetweenByStatusLastUpdated( active, lastUpdated, offset, limit ) );
+            }
+            else
+            {
+                allOrganisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnitsByStatusLastUpdated( active, lastUpdated ) );
+            }
         }
 
         Collections.sort( allOrganisationUnits, IdentifiableObjectNameComparator.INSTANCE );

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to