This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git


The following commit(s) were added to refs/heads/master by this push:
     new 1cb2907fc [OLINGO-1573] Add next link support on expanded navigation
1cb2907fc is described below

commit 1cb2907fccb06b66e026d3b1255e9b57449eec9b
Author: Scraylex <[email protected]>
AuthorDate: Fri Feb 3 08:43:32 2023 +0100

    [OLINGO-1573] Add next link support on expanded navigation
    
    All the credit goes to [email protected] for writing this patch.
---
 .../core/serializer/json/ODataJsonSerializer.java  | 11 ++++--
 .../serializer/json/ODataJsonSerializerTest.java   | 42 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index ec75da089..aed0bb881 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -37,6 +37,7 @@ import 
org.apache.olingo.commons.api.data.AbstractEntityCollection;
 import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntityCollection;
 import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.data.Link;
 import org.apache.olingo.commons.api.data.Linked;
@@ -654,12 +655,18 @@ public class ODataJsonSerializer extends 
AbstractODataSerializer {
           json.writeStartArray();
           json.writeEndArray();
         } else {
+          final EntityCollection inlineEntitySet = 
navigationLink.getInlineEntitySet();
           if (innerCount != null && innerCount.getValue()) {
-            writeInlineCount(property.getName(), 
navigationLink.getInlineEntitySet().getCount(), json);
+            writeInlineCount(property.getName(), inlineEntitySet.getCount(), 
json);
           }
           json.writeFieldName(property.getName());
-          writeEntitySet(metadata, property.getType(), 
navigationLink.getInlineEntitySet(), innerExpand, toDepth,
+          writeEntitySet(metadata, property.getType(), inlineEntitySet, 
innerExpand, toDepth,
               innerSelect, writeOnlyRef, ancestors, name, json);
+
+          final URI nextLink = inlineEntitySet.getNext();
+          if (nextLink != null) {
+            json.writeStringField(navigationLink.getTitle() + 
constants.getNextLink(), nextLink.toASCIIString());
+          }
         }
       }
     } else {
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 5230e6020..b156bb964 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -25,9 +25,11 @@ import java.io.InputStream;
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
 import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalTime;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
@@ -92,6 +94,7 @@ import org.apache.olingo.server.tecsvc.MetadataETagSupport;
 import org.apache.olingo.server.tecsvc.data.DataProvider;
 import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matcher;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -1700,6 +1703,45 @@ public class ODataJsonSerializerTest {
         resultString);
   }
 
+  @Test
+  public void expandWithNextLink() throws Exception {
+
+    final EdmEntitySet edmEntitySet = 
entityContainer.getEntitySet("ESTwoPrim");
+    final EdmEntityType entityType = edmEntitySet.getEntityType();
+    final EdmEntitySet innerEntitySet = 
entityContainer.getEntitySet("ESAllPrim");
+    final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
+    final EntityCollection innerEntities = data.readAll(innerEntitySet);
+    innerEntities.setNext(URI.create("/next"));
+    final ExpandItem expandItem = 
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimMany");
+    final List<ExpandItem> expandItems = new ArrayList<>();
+    expandItems.add(expandItem);
+
+    final ExpandOption expandOption = 
ExpandSelectMock.mockExpandOption(expandItems);
+    final Link link = new Link();
+    link.setTitle("NavPropertyETAllPrimMany");
+    link.setInlineEntitySet(innerEntities);
+    entity.getNavigationLinks().add(link);
+
+
+    final ContextURL build = ContextURL.with().entitySet(edmEntitySet)
+            .selectList(helper.buildContextURLSelectList(entityType, 
expandOption, null))
+            .suffix(Suffix.ENTITY).build();
+    final String resultString = IOUtils.toString(serializerV401
+            .entity(metadata, entityType, entity,
+                    EntitySerializerOptions.with()
+                            .contextURL(build)
+                            .expand(expandOption)
+                            .build()).getContent(), Charset.defaultCharset());
+
+
+    final Matcher<String> stringMatcher = CoreMatchers.endsWith("}],"
+            + "\"NavPropertyETAllPrimMany@nextLink\":\"/next\"}");
+
+    final boolean matchResult = stringMatcher.matches(resultString);
+    Assert.assertTrue(matchResult);
+
+  }
+
   @Test
   public void primitiveProperty() throws Exception {
     final EdmEntitySet edmEntitySet = 
entityContainer.getEntitySet("ESAllPrim");

Reply via email to