You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2015/07/24 02:04:34 UTC

olingo-odata4 git commit: OLINGO-650: supporting the complex properties in expand context url generation

Repository: olingo-odata4
Updated Branches:
  refs/heads/master cb0f7f2d7 -> 8f763aade


OLINGO-650: supporting the complex properties in expand context url generation


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/8f763aad
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/8f763aad
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/8f763aad

Branch: refs/heads/master
Commit: 8f763aadea9730ddf518663a24da3d56aa2ae2e8
Parents: cb0f7f2
Author: Ramesh Reddy <ra...@jboss.org>
Authored: Tue Jun 2 12:12:57 2015 -0500
Committer: Ramesh Reddy <ra...@jboss.org>
Committed: Thu Jul 23 18:48:34 2015 -0500

----------------------------------------------------------------------
 .../core/serializer/utils/ContextURLHelper.java | 30 ++++++++++++++++++++
 .../serializer/utils/ExpandSelectHelper.java    | 11 ++-----
 .../serializer/utils/ContextURLHelperTest.java  | 16 +++++++++++
 3 files changed, 49 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8f763aad/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
index 421c6eb..f6c2ae3 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
@@ -29,6 +29,8 @@ import org.apache.olingo.commons.api.edm.EdmStructuredType;
 import org.apache.olingo.commons.core.Encoder;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResource;
+import org.apache.olingo.server.api.uri.UriResourceProperty;
 import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectItem;
@@ -117,11 +119,39 @@ public final class ContextURLHelper {
             }
             result.append(Encoder.encode(propertyName)).append('(').append(innerSelectList).append(')');
           }
+        } else {
+          final List<UriResource> resourceParts = expandItem.getResourcePath().getUriResourceParts();
+          if(resourceParts.size() > 1) {
+            if (result.length() > 0) {
+              result.append(',');
+            }            
+            final List<String> path = getPropertyPath(resourceParts);
+            String propertyPath = buildPropertyPath(path);            
+            result.append(Encoder.encode(propertyName));
+            result.append("/").append(propertyPath);
+          }
         }
       }
     }
   }
 
+  private static List<String> getPropertyPath(final List<UriResource> path) {
+    List<String> result = new LinkedList<String>();
+    int index = 1;
+    while (index < path.size() && path.get(index) instanceof UriResourceProperty) {
+      result.add(((UriResourceProperty) path.get(index)).getProperty().getName());
+      index++;
+    }
+    return result;
+  }
+
+  private static String buildPropertyPath(final List<String> path) {
+    StringBuilder result = new StringBuilder();
+    for (final String segment : path) {
+      result.append(result.length() == 0 ? "" : '/').append(Encoder.encode(segment)); //$NON-NLS-1$
+    }
+    return result.length() == 0?null:result.toString();
+  }  
   private static List<List<String>> getComplexSelectedPaths(final EdmProperty edmProperty,
       final Set<List<String>> selectedPaths) {
     List<List<String>> result = new ArrayList<List<String>>();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8f763aad/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
index 3acdbd3..30810f0 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
@@ -127,14 +127,9 @@ public abstract class ExpandSelectHelper {
     Set<String> expanded = new HashSet<String>();
     for (final ExpandItem item : expandItems) {
       final List<UriResource> resourceParts = item.getResourcePath().getUriResourceParts();
-      if (resourceParts.size() == 1) {
-        final UriResource resource = resourceParts.get(0);
-        if (resource instanceof UriResourceNavigation) {
-          expanded.add(((UriResourceNavigation) resource).getProperty().getName());
-        }
-      } else {
-        throw new SerializerException("Expand is not supported within complex properties.",
-            SerializerException.MessageKeys.NOT_IMPLEMENTED);
+      final UriResource resource = resourceParts.get(0);
+      if (resource instanceof UriResourceNavigation) {
+        expanded.add(((UriResourceNavigation) resource).getProperty().getName());
       }
     }
     return expanded;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8f763aad/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java
index 2416fbe..b94f97e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java
@@ -117,6 +117,22 @@ public class ContextURLHelperTest {
   }
 
   @Test
+  public void buildExpandWithNavigationProperty() throws Exception {
+    final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
+    final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
+        ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne", "PropertyString")));
+    final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(entitySet, "PropertyInt16");
+    final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
+        selectItem1));
+    
+    final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
+        .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, select)).build();
+    assertEquals("$metadata#ESTwoPrim(PropertyInt16,NavPropertyETAllPrimOne/PropertyString)", 
+        ContextURLBuilder.create(contextURL).toASCIIString());
+  }
+
+  
+  @Test
   public void buildExpandSelect() throws Exception {
     final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
     final ExpandItem expandItem1 = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne");