This is an automated email from the ASF dual-hosted git repository.
ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git
The following commit(s) were added to refs/heads/master by this push:
new 26cbf2c [OLINGO-1488]-Support deep structures with identical
navigation names
26cbf2c is described below
commit 26cbf2cbe39589723aecdb2decac955a4d34505d
Author: ramya vasanth <[email protected]>
AuthorDate: Thu Oct 29 11:08:17 2020 +0530
[OLINGO-1488]-Support deep structures with identical navigation names
---
.../odata2/core/ep/producer/JsonEntryEntityProducer.java | 15 +++++++++++++--
.../core/ep/producer/JsonEntryEntityProducerTest.java | 11 ++++++++++-
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
index 887d4b9..80a4465 100644
---
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
+++
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
@@ -116,7 +116,11 @@ public class JsonEntryEntityProducer {
jsonStreamWriter.separator();
jsonStreamWriter.name(navigationPropertyName);
if
(entityInfo.getExpandedNavigationPropertyNames().contains(navigationPropertyName))
{
- if (properties.getCallbacks() != null &&
properties.getCallbacks().containsKey(navigationPropertyName)) {
+
+ String navigationPropertyNameFqn =
concat(entityInfo.getEntityType().getName(), navigationPropertyName);
+ Map<String, ODataCallback> callbacks = properties.getCallbacks();
+ if (callbacks != null &&
(callbacks.containsKey(navigationPropertyName) ||
+ callbacks.containsKey(navigationPropertyNameFqn))) {
writeExpandedNavigationProperty(writer, entityInfo, data, type,
navigationPropertyName);
} else {
writeDeferredUri(entityInfo, navigationPropertyName);
@@ -128,6 +132,10 @@ public class JsonEntryEntityProducer {
}
}
+ private String concat(String s1, String s2) {
+ return s1.concat(".").concat(s2);
+ }
+
private void writeExpandedNavigationProperty(final Writer writer, final
EntityInfoAggregator entityInfo,
final Map<String, Object> data,
final EdmEntityType type, final String navigationPropertyName) throws
EdmException, EntityProviderException,
@@ -145,7 +153,10 @@ public class JsonEntryEntityProducer {
context.setCurrentExpandSelectTreeNode(properties.getExpandSelectTree().getLinks().get(
navigationPropertyName));
- ODataCallback callback =
properties.getCallbacks().get(navigationPropertyName);
+ Map<String, ODataCallback> callbacks = properties.getCallbacks();
+ String navigationPropertyNameFqn =
concat(entityInfo.getEntityType().getName(), navigationPropertyName);
+ ODataCallback callback = callbacks.get(navigationPropertyName);
+ callback = callback == null ? callbacks.get(navigationPropertyNameFqn) :
callback;
if (callback == null) {
throw new
EntityProviderProducerException(EntityProviderException.EXPANDNOTSUPPORTED);
}
diff --git
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
index 899dd4f..f943148 100644
---
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
+++
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
@@ -880,8 +880,17 @@ public class JsonEntryEntityProducerTest extends BaseTest {
+ "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + BASE_URI +
"Rooms('1')/nr_Employees\"}},"
+ "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + BASE_URI +
"Rooms('1')/nr_Building\"}}}]}}}",
json);
+
+ callbacks.clear();
+ callbacks.put("Building.nb_Rooms", new DataFeedCallback());
+ final ODataResponse responseWithNavigation =
+ new JsonEntityProvider().writeEntry(entitySet, buildingData,
+
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1)
+ .callbacks(callbacks).build());
+ final String jsonWithNavigation = verifyResponse(responseWithNavigation);
+ assertEquals(json, jsonWithNavigation);
}
-
+
class DataFeedCallback implements OnWriteFeedContent {
@Override
public WriteFeedCallbackResult retrieveFeedResult(final
WriteFeedCallbackContext context)