You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/02/14 10:05:25 UTC
[05/50] [abbrv] git commit: [OLINGO-125] Fixed next link creation
[OLINGO-125] Fixed next link creation
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/8ed6306f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/8ed6306f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/8ed6306f
Branch: refs/heads/ODataServlet
Commit: 8ed6306f6cd1f88cdab8050b1ab5cce92a338ee4
Parents: 1d8cdd3
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Jan 17 14:43:38 2014 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Fri Jan 17 14:51:36 2014 +0100
----------------------------------------------------------------------
.../processor/core/ListsProcessor.java | 20 +++--
.../processor/core/ListsProcessorTest.java | 54 +++++++++++++
.../odata2/ref/processor/ListsProcessor.java | 19 +++--
.../ref/processor/ListsProcessorTest.java | 80 ++++++++++++++++++++
4 files changed, 160 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8ed6306f/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
index 85e011c..7e637f9 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
@@ -30,8 +30,8 @@ import java.util.Locale;
import java.util.Map;
import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.ValueAccess;
import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource.BinaryData;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.ValueAccess;
import org.apache.olingo.odata2.api.ODataCallback;
import org.apache.olingo.odata2.api.batch.BatchHandler;
import org.apache.olingo.odata2.api.batch.BatchRequestPart;
@@ -172,12 +172,8 @@ public class ListsProcessor extends DataSourceProcessor {
sortInDefaultOrder(entitySet, data);
}
- // TODO: Percent-encode "next" link.
- nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString()
- .replaceAll("\\$skiptoken=.+?&?", "")
- .replaceAll("\\$skip=.+?&?", "")
- .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
- // above.
+ nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString();
+ nextLink = percentEncodeNextLink(nextLink);
nextLink += (nextLink.contains("?") ? "&" : "?")
+ "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));
@@ -209,6 +205,16 @@ public class ListsProcessor extends DataSourceProcessor {
return ODataResponse.fromResponse(response).build();
}
+ String percentEncodeNextLink(String link) {
+ if(link == null) {
+ return null;
+ }
+
+ return link.replaceAll("\\$skiptoken=.+?(?:&|$)", "")
+ .replaceAll("\\$skip=.+?(?:&|$)", "")
+ .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
+ }
+
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
throws ODataException {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8ed6306f/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java
index b7642fb..82b857c 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java
@@ -23,12 +23,17 @@ import org.apache.olingo.odata2.annotation.processor.core.model.Building;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.junit.Assert;
import org.junit.Test;
+import org.mockito.Mockito;
/**
*
*/
public class ListsProcessorTest {
+ private ListsProcessor listsProcessor;
+ private DataSource mockedDataSource = Mockito.mock(DataSource.class);
+ private ValueAccess mockedValueAccess = Mockito.mock(ValueAccess.class);
+
@Test
public void init() throws ODataException {
DataSource dataSource = new AnnotationInMemoryDs(Building.class.getPackage().getName());
@@ -37,4 +42,53 @@ public class ListsProcessorTest {
Assert.assertNotNull(lp);
}
+
+ public ListsProcessorTest() {
+ listsProcessor = new ListsProcessor(mockedDataSource, mockedValueAccess);
+ }
+
+ @Test
+ public void testSkipAndSkiptoken() {
+ String url1 = "Rooms?$orderby=Seats%20desc&$skiptoken=12&$skip=000000&$top=200";
+ String result = listsProcessor.percentEncodeNextLink(url1);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc&$top=200", result);
+
+ String url2 = "Rooms?$orderby=Seats%20desc&$skiptoken=213&$skip=99";
+ String result2 = listsProcessor.percentEncodeNextLink(url2);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2);
+
+ String url3 = "Rooms?$skiptoken=213&$skip=0000";
+ String result3 = listsProcessor.percentEncodeNextLink(url3);
+ Assert.assertEquals("Rooms", result3);
+ }
+
+ @Test
+ public void testSkipOnly() {
+ String url = "Rooms?$orderby=Seats%20desc&$skip=000000&$top=200";
+ String result = listsProcessor.percentEncodeNextLink(url);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc&$top=200", result);
+
+ String url2 = "Rooms?$orderby=Seats%20desc&$skip=213";
+ String result2 = listsProcessor.percentEncodeNextLink(url2);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2);
+
+ String url3 = "Rooms?$skip=0999";
+ String result3 = listsProcessor.percentEncodeNextLink(url3);
+ Assert.assertEquals("Rooms", result3);
+ }
+
+ @Test
+ public void testSkiptokenOnly() {
+ String url = "Rooms?$orderby=Seats%20desc&$skiptoken=213&$top=200";
+ String result = listsProcessor.percentEncodeNextLink(url);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc&$top=200", result);
+
+ String url2 = "Rooms?$orderby=Seats%20desc&$skiptoken=213";
+ String result2 = listsProcessor.percentEncodeNextLink(url2);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2);
+
+ String url3 = "Rooms?$skiptoken=213";
+ String result3 = listsProcessor.percentEncodeNextLink(url3);
+ Assert.assertEquals("Rooms", result3);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8ed6306f/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
index fd335b4..32f196f 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
@@ -178,12 +178,9 @@ public class ListsProcessor extends ODataSingleProcessor {
sortInDefaultOrder(entitySet, data);
}
- // TODO: Percent-encode "next" link.
- nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString()
- .replaceAll("\\$skiptoken=.+?&?", "")
- .replaceAll("\\$skip=.+?&?", "")
- .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
- // above.
+ nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString();
+ nextLink = percentEncodeNextLink(nextLink);
+
nextLink += (nextLink.contains("?") ? "&" : "?")
+ "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));
@@ -215,6 +212,16 @@ public class ListsProcessor extends ODataSingleProcessor {
return ODataResponse.fromResponse(response).build();
}
+ String percentEncodeNextLink(String link) {
+ if(link == null) {
+ return null;
+ }
+
+ return link.replaceAll("\\$skiptoken=.+?(?:&|$)", "")
+ .replaceAll("\\$skip=.+?(?:&|$)", "")
+ .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
+ }
+
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
throws ODataException {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8ed6306f/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/processor/ListsProcessorTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/processor/ListsProcessorTest.java b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/processor/ListsProcessorTest.java
new file mode 100644
index 0000000..bfca445
--- /dev/null
+++ b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/processor/ListsProcessorTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.processor;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ *
+ */
+public class ListsProcessorTest {
+
+ private ListsProcessor listsProcessor;
+
+ public ListsProcessorTest() {
+ listsProcessor = new ListsProcessor(null);
+ }
+
+ @Test
+ public void testSkipAndSkiptoken() {
+ String url1 = "Rooms?$orderby=Seats%20desc&$skiptoken=12&$skip=000000&$top=200";
+ String result = listsProcessor.percentEncodeNextLink(url1);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc&$top=200", result);
+
+ String url2 = "Rooms?$orderby=Seats%20desc&$skiptoken=213&$skip=99";
+ String result2 = listsProcessor.percentEncodeNextLink(url2);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2);
+
+ String url3 = "Rooms?$skiptoken=213&$skip=0000";
+ String result3 = listsProcessor.percentEncodeNextLink(url3);
+ Assert.assertEquals("Rooms", result3);
+ }
+
+ @Test
+ public void testSkipOnly() {
+ String url = "Rooms?$orderby=Seats%20desc&$skip=000000&$top=200";
+ String result = listsProcessor.percentEncodeNextLink(url);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc&$top=200", result);
+
+ String url2 = "Rooms?$orderby=Seats%20desc&$skip=213";
+ String result2 = listsProcessor.percentEncodeNextLink(url2);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2);
+
+ String url3 = "Rooms?$skip=0999";
+ String result3 = listsProcessor.percentEncodeNextLink(url3);
+ Assert.assertEquals("Rooms", result3);
+ }
+
+ @Test
+ public void testSkiptokenOnly() {
+ String url = "Rooms?$orderby=Seats%20desc&$skiptoken=213&$top=200";
+ String result = listsProcessor.percentEncodeNextLink(url);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc&$top=200", result);
+
+ String url2 = "Rooms?$orderby=Seats%20desc&$skiptoken=213";
+ String result2 = listsProcessor.percentEncodeNextLink(url2);
+ Assert.assertEquals("Rooms?$orderby=Seats%20desc", result2);
+
+ String url3 = "Rooms?$skiptoken=213";
+ String result3 = listsProcessor.percentEncodeNextLink(url3);
+ Assert.assertEquals("Rooms", result3);
+ }
+}