Repository: olingo-odata4 Updated Branches: refs/heads/OLINGO-650 [created] ec5e716a8
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/ec5e716a Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/ec5e716a Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/ec5e716a Branch: refs/heads/OLINGO-650 Commit: ec5e716a8ef046720a976bab044fe6e17417ae44 Parents: 181e463 Author: Ramesh Reddy <[email protected]> Authored: Tue Jun 2 12:12:57 2015 -0500 Committer: Ramesh Reddy <[email protected]> Committed: Tue Jun 2 12:12:57 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/ec5e716a/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/ec5e716a/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/ec5e716a/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");
