From 75ed6367221e7b786c19894e5718fe2062a27811 Mon Sep 17 00:00:00 2001 From: Ramesh Reddy Date: Mon, 8 Jun 2015 14:17:24 -0500 Subject: [PATCH] OLINGO-687: Adding correct passing of context during the parsing --- .../server/api/uri/UriInfoCrossjoin.java | 54 +++++++++++++++++++ .../core/RequestURLHierarchyVisitor.java | 35 ++++++++++++ .../server/example/TripPinServiceTest.java | 3 +- .../core/uri/parser/UriParseTreeVisitor.java | 17 +++++- 4 files changed, 107 insertions(+), 2 deletions(-) diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/UriInfoCrossjoin.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/UriInfoCrossjoin.java index bdf16d390..0229ec39f 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/UriInfoCrossjoin.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/UriInfoCrossjoin.java @@ -20,6 +20,16 @@ package org.apache.olingo.server.api.uri; import java.util.List; +import org.apache.olingo.server.api.uri.queryoption.CountOption; +import org.apache.olingo.server.api.uri.queryoption.ExpandOption; +import org.apache.olingo.server.api.uri.queryoption.FilterOption; +import org.apache.olingo.server.api.uri.queryoption.FormatOption; +import org.apache.olingo.server.api.uri.queryoption.OrderByOption; +import org.apache.olingo.server.api.uri.queryoption.SelectOption; +import org.apache.olingo.server.api.uri.queryoption.SkipOption; +import org.apache.olingo.server.api.uri.queryoption.SkipTokenOption; +import org.apache.olingo.server.api.uri.queryoption.TopOption; + /** * Used for URI info kind {@link UriInfoKind#crossjoin} to describe URIs like * http://.../serviceroot/$crossjoin(...) @@ -30,5 +40,49 @@ public interface UriInfoCrossjoin { * @return List of entity set names */ List getEntitySetNames(); + + /** + * @return Object containing information of the $expand option + */ + ExpandOption getExpandOption(); + /** + * @return Object containing information of the $filter option + */ + FilterOption getFilterOption(); + + /** + * @return Object containing information of the $format option + */ + FormatOption getFormatOption(); + + /** + * @return Object containing information of the $count option + */ + CountOption getCountOption(); + + /** + * @return Object containing information of the $orderby option + */ + OrderByOption getOrderByOption(); + + /** + * @return Object containing information of the $select option + */ + SelectOption getSelectOption(); + + /** + * @return Object containing information of the $skip option + */ + SkipOption getSkipOption(); + + /** + * @return Object containing information of the $skiptoken option + */ + SkipTokenOption getSkipTokenOption(); + + /** + * @return Object containing information of the $top option + */ + TopOption getTopOption(); } diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java index ee0063819..bc48f7106 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java @@ -110,6 +110,41 @@ public class RequestURLHierarchyVisitor implements RequestURLVisitor { @Override public void visit(UriInfoCrossjoin info) { + if (info.getFilterOption() != null) { + visit(info.getFilterOption()); + } + + if (info.getCountOption() != null) { + visit(info.getCountOption()); + } + + if(info.getOrderByOption() != null) { + visit(info.getOrderByOption()); + } + + if (info.getSkipOption() != null) { + visit(info.getSkipOption()); + } + + if (info.getTopOption() != null) { + visit(info.getTopOption()); + } + + if (info.getExpandOption() != null) { + visit(info.getExpandOption()); + } + + if(info.getSelectOption() != null) { + visit(info.getSelectOption()); + } + + if (info.getFormatOption() != null) { + visit(info.getFormatOption()); + } + + if (info.getSkipTokenOption() != null) { + visit(info.getSkipTokenOption()); + } } @Override diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java index 9476f0987..b318f4265 100644 --- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java +++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java @@ -728,7 +728,8 @@ public class TripPinServiceTest { @Test public void testCrossJoin() throws Exception { - String editUrl = baseURL + "/$crossjoin(People,Airlines)"; + String editUrl = baseURL + "/$crossjoin(People,Airlines)?$filter="+ + Encoder.encode("People/UserName eq Airlines/AirlineCode"); HttpResponse response = httpGET(editUrl, 200); EntityUtils.consumeQuietly(response.getEntity()); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java index a6f50f1c4..803b0ad62 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java @@ -1063,7 +1063,22 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { UriInfoImpl crossJoin = new UriInfoImpl().setKind(UriInfoKind.crossjoin); for (OdataIdentifierContext obj : ctx.vlODI) { - crossJoin.addEntitySetName(obj.getText()); + String odi = obj.getText(); + crossJoin.addEntitySetName(odi); + + EdmEntitySet edmEntitySet = edmEntityContainer.getEntitySet(odi); + if (edmEntitySet == null) { + throw wrap(new UriParserSemanticException("Expected EntityTypeName", + UriParserSemanticException.MessageKeys.UNKNOWN_PART, odi)); + } + + EdmEntityType type = edmEntitySet.getEntityType(); + if (type == null) { + throw wrap(new UriParserSemanticException("Expected EntityTypeName", + UriParserSemanticException.MessageKeys.UNKNOWN_ENTITY_TYPE, odi)); + } + // contextUriInfo = uriInfo; + context.contextTypes.push(new TypeInformation(type, true)); } context.contextUriInfo = crossJoin;