[OLINGO-1573] Add next link support on expanded navigation
All the credit goes to c.schwyter@gmail.com for writing this patch.
This commit is contained in:
parent
0734e23aab
commit
1cb2907fcc
|
@ -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 {
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue