From 1d667218ac5997b0f5848097f8edd94f9ece4643 Mon Sep 17 00:00:00 2001 From: Christia Holzer Date: Tue, 8 Sep 2015 14:20:55 +0200 Subject: [PATCH] [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 --- .../DemoEntityCollectionProcessor.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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 737c6b08e..ee3558ec9 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);