You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/09/08 14:46:19 UTC

[2/2] olingo-odata4 git commit: [OLINGO-713] Tutorial: $skip and $top do not throw an exception any more if the given value by the client is greather than the amount of items

[OLINGO-713] Tutorial: $skip and $top do not throw an exception any more if the given
value by the client is greather than the amount of items


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/1d667218
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/1d667218
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/1d667218

Branch: refs/heads/TutorialRelease
Commit: 1d667218ac5997b0f5848097f8edd94f9ece4643
Parents: 1558273
Author: Christia Holzer <c....@sap.com>
Authored: Tue Sep 8 14:20:55 2015 +0200
Committer: Christia Holzer <c....@sap.com>
Committed: Tue Sep 8 14:25:01 2015 +0200

----------------------------------------------------------------------
 .../service/DemoEntityCollectionProcessor.java   | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1d667218/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index 737c6b0..ee3558e 100755
--- a/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -89,25 +89,32 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
         returnEntityCollection.setCount(entityList.size());
       }
     }
-
+    
     // handle $skip
     SkipOption skipOption = uriInfo.getSkipOption();
     if (skipOption != null) {
       int skipNumber = skipOption.getValue();
-      if (skipNumber >= 0 && skipNumber <= entityList.size()) {
-        entityList = entityList.subList(skipNumber, entityList.size());
+      if (skipNumber >= 0) {
+        if(skipNumber <= entityList.size()) {
+          entityList = entityList.subList(skipNumber, entityList.size());
+        } else {
+          // The client skipped all entities
+          entityList.clear();
+        }
       } else {
         throw new ODataApplicationException("Invalid value for $skip", HttpStatusCode.BAD_REQUEST.getStatusCode(),
             Locale.ROOT);
       }
     }
-
+    
     // handle $top
     TopOption topOption = uriInfo.getTopOption();
     if (topOption != null) {
       int topNumber = topOption.getValue();
-      if (topNumber >= 0 && topNumber <= entityList.size()) {
-        entityList = entityList.subList(0, topNumber);
+      if (topNumber >= 0) {
+        if(topNumber <= entityList.size()) {
+          entityList = entityList.subList(0, topNumber);
+        }  // else the client has requested more entities than available => return what we have
       } else {
         throw new ODataApplicationException("Invalid value for $top", HttpStatusCode.BAD_REQUEST.getStatusCode(),
             Locale.ROOT);