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 2ccc05b  [OLINGO-1488]Support deep structures with identical 
navigation names (Atom)
2ccc05b is described below

commit 2ccc05b8bf43ed699c870d52e10fb28aef8adbb5
Author: ramya vasanth <ramya.vasa...@sap.com>
AuthorDate: Wed Dec 9 10:21:52 2020 +0530

    [OLINGO-1488]Support deep structures with identical navigation names (Atom)
---
 .../core/ep/producer/AtomEntryEntityProducer.java    | 20 ++++++++++++++++----
 .../core/ep/producer/AtomEntryProducerTest.java      | 16 ++++++++++++++++
 .../core/ep/producer/AtomFeedProducerTest.java       | 14 ++++++++++++++
 3 files changed, 46 insertions(+), 4 deletions(-)

diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
index c347be4..e580f18 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
@@ -253,12 +253,19 @@ public class AtomEntryEntityProducer {
     }
   }
 
+  private String concat(String s1, String s2) {
+    return s1.concat(".").concat(s2);
+  }
+
   private void appendInlineFeed(final XMLStreamWriter writer, final String 
navigationPropertyName,
       final EntityInfoAggregator eia, final Map<String, Object> data, final 
String self)
       throws EntityProviderException, XMLStreamException, EdmException, 
URISyntaxException {
 
     if 
(eia.getExpandedNavigationPropertyNames().contains(navigationPropertyName)) {
-      if (properties.getCallbacks() != null && 
properties.getCallbacks().containsKey(navigationPropertyName)) {
+      String navigationPropertyNameFqn = concat(eia.getEntityType().getName(), 
navigationPropertyName);
+      Map<String, ODataCallback> callbacks = properties.getCallbacks();
+    if (callbacks != null && callbacks.containsKey(navigationPropertyName) ||
+        callbacks.containsKey(navigationPropertyNameFqn)) {
 
         EdmNavigationProperty navProp = (EdmNavigationProperty) 
eia.getEntityType().getProperty(navigationPropertyName);
         WriteFeedCallbackContext context = new WriteFeedCallbackContext();
@@ -270,7 +277,8 @@ public class AtomEntryEntityProducer {
         context.setCurrentExpandSelectTreeNode(subNode);
         context.setSelfLink(new URI(self));
 
-        ODataCallback callback = 
properties.getCallbacks().get(navigationPropertyName);
+        ODataCallback callback = callbacks.get(navigationPropertyName);
+        callback = callback == null ? callbacks.get(navigationPropertyNameFqn) 
: callback;
         if (callback == null) {
           throw new 
EntityProviderProducerException(EntityProviderException.EXPANDNOTSUPPORTED);
         }
@@ -308,7 +316,10 @@ public class AtomEntryEntityProducer {
       XMLStreamException, EdmException {
 
     if 
(eia.getExpandedNavigationPropertyNames().contains(navigationPropertyName)) {
-      if (properties.getCallbacks() != null && 
properties.getCallbacks().containsKey(navigationPropertyName)) {
+      Map<String, ODataCallback> callbacks = properties.getCallbacks();
+      String navigationPropertyNameFqn = concat(eia.getEntityType().getName(), 
navigationPropertyName);
+       if (callbacks != null && callbacks.containsKey(navigationPropertyName) 
|| 
+        callbacks.containsKey(navigationPropertyNameFqn)) {
 
         EdmNavigationProperty navProp = (EdmNavigationProperty) 
eia.getEntityType().getProperty(navigationPropertyName);
         WriteEntryCallbackContext context = new WriteEntryCallbackContext();
@@ -319,7 +330,8 @@ public class AtomEntryEntityProducer {
         ExpandSelectTreeNode subNode = 
properties.getExpandSelectTree().getLinks().get(navigationPropertyName);
         context.setCurrentExpandSelectTreeNode(subNode);
 
-        ODataCallback callback = 
properties.getCallbacks().get(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/AtomEntryProducerTest.java
 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
index f62d953..bb28afa 100644
--- 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
+++ 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
@@ -1320,6 +1320,22 @@ public class AtomEntryProducerTest extends 
AbstractProviderTest {
     assertXpathNotExists("/a:entry/m:properties", xmlString);
     assertXpathExists("/a:entry/a:link", xmlString);
     verifyBuilding(buildingXPathString, xmlString);
+
+    callbacks.clear();
+    callbacks.put("Room.nr_Building", callback);
+    
+    properties =
+        
EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacks).
+        isDataBasedPropertySerialization(true).build();
+    provider = createAtomEntityProvider();
+    response =
+        
provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
 roomData,
+            properties);
+
+    xmlString = verifyResponse(response);
+    assertXpathNotExists("/a:entry/m:properties", xmlString);
+    assertXpathExists("/a:entry/a:link", xmlString);
+    verifyBuilding(buildingXPathString, xmlString);
   }
   
   private ExpandSelectTreeNode getSelectExpandTree(final String pathSegment, 
final String selectString,
diff --git 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
index 8487bbc..9402bb0 100644
--- 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
+++ 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
@@ -369,6 +369,20 @@ public class AtomFeedProducerTest extends 
AbstractProviderTest {
     assertXpathNotExists("/a:entry/m:properties", xmlString);
     assertXpathExists("/a:entry/a:link", xmlString);
     verifyEmployees(employeeXPathString, xmlString);
+
+    callbacks.clear();
+    callbacks.put("Room.nr_Employees", callback);
+    properties = 
EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).
+        callbacks(callbacks).isDataBasedPropertySerialization(true).build();
+    provider = createAtomEntityProvider();
+    response =
+        
provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
 roomData,
+            properties);
+
+    xmlString = verifyResponse(response);
+    assertXpathNotExists("/a:entry/m:properties", xmlString);
+    assertXpathExists("/a:entry/a:link", xmlString);
+    verifyEmployees(employeeXPathString, xmlString);
   }
     
   private ExpandSelectTreeNode getSelectExpandTree(final String pathSegment, 
final String selectString,

Reply via email to