Repository: olingo-odata4 Updated Branches: refs/heads/master af116170a -> 3a8cbcc33
OLINGO-1104: Write @odata.navigationLink and @odata.assosiationLink always when metadata=full, previously it is omiited when query came in with Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/3a8cbcc3 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/3a8cbcc3 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/3a8cbcc3 Branch: refs/heads/master Commit: 3a8cbcc337577a1cf56cf77383d62edcf2fea857 Parents: af11617 Author: Ramesh Reddy <[email protected]> Authored: Thu Apr 13 09:35:21 2017 -0500 Committer: Ramesh Reddy <[email protected]> Committed: Thu Apr 13 09:35:21 2017 -0500 ---------------------------------------------------------------------- .../serializer/json/ODataJsonSerializer.java | 23 ++--- .../json/ODataJsonSerializerTest.java | 94 ++++++++++++++++++++ 2 files changed, 106 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a8cbcc3/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java ---------------------------------------------------------------------- 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 0cf307f..c5ac9f3 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 @@ -485,6 +485,18 @@ public class ODataJsonSerializer extends AbstractODataSerializer { protected void writeNavigationProperties(final ServiceMetadata metadata, final EdmStructuredType type, final Linked linked, final ExpandOption expand, final Integer toDepth, final Set<String> ancestors, final JsonGenerator json) throws SerializerException, IOException { + if (isODataMetadataFull) { + for (final String propertyName : type.getNavigationPropertyNames()) { + final Link navigationLink = linked.getNavigationLink(propertyName); + if (navigationLink != null) { + json.writeStringField(propertyName + Constants.JSON_NAVIGATION_LINK, navigationLink.getHref()); + } + final Link associationLink = linked.getAssociationLink(propertyName); + if (associationLink != null) { + json.writeStringField(propertyName + Constants.JSON_ASSOCIATION_LINK, associationLink.getHref()); + } + } + } if ((toDepth != null && toDepth > 1) || (toDepth == null && ExpandSelectHelper.hasExpand(expand))) { final ExpandItem expandAll = ExpandSelectHelper.getExpandAll(expand); for (final String propertyName : type.getNavigationPropertyNames()) { @@ -543,17 +555,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer { json); } } - } else if (isODataMetadataFull) { - for (final String propertyName : type.getNavigationPropertyNames()) { - final Link navigationLink = linked.getNavigationLink(propertyName); - if (navigationLink != null) { - json.writeStringField(propertyName + Constants.JSON_NAVIGATION_LINK, navigationLink.getHref()); - } - final Link associationLink = linked.getAssociationLink(propertyName); - if (associationLink != null) { - json.writeStringField(propertyName + Constants.JSON_ASSOCIATION_LINK, associationLink.getHref()); - } - } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a8cbcc3/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java ---------------------------------------------------------------------- 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 cf29d5f..9796aef 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 @@ -255,6 +255,100 @@ public class ODataJsonSerializerTest { } @Test + public void entitySetMetadataFullWithExpand() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); + final EntityCollection entityCol = data.readAll(edmEntitySet); + final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList( + ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETTwoPrimOne"))); + InputStream result = serializerFullMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), entityCol, + EntityCollectionSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) + .expand(expand) + .build()).getContent(); + final String resultString = IOUtils.toString(result); + final String expected = "{" + + "\"@odata.context\":\"$metadata#ESAllPrim\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"#olingo.odata.test1.BAESAllPrimRTETAllPrim\":{" + + "\"title\":\"olingo.odata.test1.BAESAllPrimRTETAllPrim\"," + + "\"target\":\"ESAllPrim/olingo.odata.test1.BAESAllPrimRTETAllPrim\"" + + "}," + + "\"#olingo.odata.test1.BAESAllPrimRT\":{" + + "\"title\":\"olingo.odata.test1.BAESAllPrimRT\"," + + "\"target\":\"ESAllPrim/olingo.odata.test1.BAESAllPrimRT\"" + + "}," + + "\"#olingo.odata.test1.BFNESAllPrimRTCTAllPrim\":{" + + "\"title\":\"olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"," + + "\"target\":\"ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"" + + "}," + + "\"value\":[" + + "{" + + "\"@odata.type\":\"#olingo.odata.test1.ETAllPrim\"," + + "\"@odata.id\":\"ESAllPrim(32767)\"," + + "\"[email protected]\":\"#Int16\"," + + "\"PropertyInt16\":32767," + + "\"PropertyString\":\"First Resource - positive values\"," + + "\"PropertyBoolean\":true," + + "\"[email protected]\":\"#Byte\"," + + "\"PropertyByte\":255," + + "\"[email protected]\":\"#SByte\"," + + "\"PropertySByte\":127," + + "\"[email protected]\":\"#Int32\"," + + "\"PropertyInt32\":2147483647," + + "\"[email protected]\":\"#Int64\"," + + "\"PropertyInt64\":9223372036854775807," + + "\"[email protected]\":\"#Single\"," + + "\"PropertySingle\":1.79E20," + + "\"PropertyDouble\":-1.79E19," + + "\"[email protected]\":\"#Decimal\"," + + "\"PropertyDecimal\":34," + + "\"[email protected]\":\"#Binary\"," + + "\"PropertyBinary\":\"ASNFZ4mrze8=\"," + + "\"[email protected]\":\"#Date\"," + + "\"PropertyDate\":\"2012-12-03\"," + + "\"[email protected]\":\"#DateTimeOffset\"," + + "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," + + "\"[email protected]\":\"#Duration\"," + + "\"PropertyDuration\":\"PT6S\"," + + "\"[email protected]\":\"#Guid\"," + + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," + + "\"[email protected]\":\"#TimeOfDay\"," + + "\"PropertyTimeOfDay\":\"03:26:05\"," + + "\"[email protected]\":\"ESTwoPrim(32767)\"," + + "\"[email protected]\":\"ESAllPrim(32767)/NavPropertyETTwoPrimMany\"," + + "\"NavPropertyETTwoPrimOne\":{" + + "\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\"," + + "\"@odata.id\":\"ESTwoPrim(32767)\"," + + "\"[email protected]\":\"#Int16\"," + + "\"PropertyInt16\":32767," + + "\"PropertyString\":\"Test String4\"," + + "\"[email protected]\":\"ESAllPrim(32767)\"," + + "\"#olingo.odata.test1.BAETTwoPrimRTString\":{" + + "\"title\":\"olingo.odata.test1.BAETTwoPrimRTString\"," + + "\"target\":\"ESTwoPrim(32767)/olingo.odata.test1.BAETTwoPrimRTString\"" + + "}," + + "\"#olingo.odata.test1.BAETTwoPrimRTCollString\":{" + + "\"title\":\"olingo.odata.test1.BAETTwoPrimRTCollString\"," + + "\"target\":\"ESTwoPrim(32767)/olingo.odata.test1.BAETTwoPrimRTCollString\"" + + "}," + + "\"#olingo.odata.test1.BAETTwoPrimRTCTAllPrim\":{" + + "\"title\":\"olingo.odata.test1.BAETTwoPrimRTCTAllPrim\"," + + "\"target\":\"ESTwoPrim(32767)/olingo.odata.test1.BAETTwoPrimRTCTAllPrim\"" + + "}," + + "\"#olingo.odata.test1.BAETTwoPrimRTCollCTAllPrim\":{" + + "\"title\":\"olingo.odata.test1.BAETTwoPrimRTCollCTAllPrim\"," + + "\"target\":\"ESTwoPrim(32767)/olingo.odata.test1.BAETTwoPrimRTCollCTAllPrim\"" + + "}" + + "}," + + "\"#olingo.odata.test1.BAETAllPrimRT\":{" + + "\"title\":\"olingo.odata.test1.BAETAllPrimRT\"," + + "\"target\":\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\"" + + "}},"; + + Assert.assertTrue(resultString.startsWith(expected)); + } + + @Test public void entityAllPrimAllNull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
