You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/09/08 16:45:22 UTC

olingo-odata4 git commit: [OLINGO-659] UriParser: The uri parser detects multiple entity sets in the resource path. Navigation properties with the very same name as entity sets will now be found

Repository: olingo-odata4
Updated Branches:
  refs/heads/master 02479200e -> 72b081388


[OLINGO-659] UriParser: The uri parser detects multiple entity sets in the
resource path. Navigation properties with the very same name as entity
sets will now be found


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

Branch: refs/heads/master
Commit: 72b08138887772f067d88e86ebc7a8587c633d9b
Parents: 0247920
Author: Christia Holzer <c....@sap.com>
Authored: Tue Sep 8 15:49:58 2015 +0200
Committer: Christia Holzer <c....@sap.com>
Committed: Tue Sep 8 16:44:52 2015 +0200

----------------------------------------------------------------------
 .../core/uri/parser/UriParseTreeVisitor.java    | 17 ++++++++++-----
 .../core/uri/antlr/TestFullResourcePath.java    | 21 ++++++++++++++++++
 .../core/uri/testutil/EdmTechTestProvider.java  | 23 ++++++++++++++++++--
 3 files changed, 53 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/72b08138/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
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 9408ab8..36717cc 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
@@ -323,13 +323,18 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
     if (searchInContainer) {
       // check EntitySet
       EdmEntitySet edmEntitySet = edmEntityContainer.getEntitySet(odi);
-      if (edmEntitySet != null) {
-        UriResourceEntitySetImpl uriResource = new UriResourceEntitySetImpl()
-            .setEntitSet(edmEntitySet);
-        context.contextUriInfo.addResourcePart(uriResource);
-        return null;
+      if( !context.contextUriInfo.getUriResourceParts().isEmpty() 
+          && context.contextUriInfo.getUriResourceParts().get(0) instanceof UriResourceEntitySet) {
+        edmEntitySet = null;
+      } else {
+        if (edmEntitySet != null) {
+          UriResourceEntitySetImpl uriResource = new UriResourceEntitySetImpl()
+              .setEntitSet(edmEntitySet);
+          context.contextUriInfo.addResourcePart(uriResource);
+          return null;
+        }
       }
-
+      
       // check Singleton
       EdmSingleton edmSingleton = edmEntityContainer.getSingleton(odi);
       if (edmSingleton != null) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/72b08138/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 6a17d4b..b4fe8fe 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -48,6 +48,7 @@ import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitEx
 import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
 import org.apache.olingo.server.core.uri.parser.UriParserException;
 import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
+import org.apache.olingo.server.core.uri.parser.UriParserSemanticException.MessageKeys;
 import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
 import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
 import org.apache.olingo.server.core.uri.testutil.FilterValidator;
@@ -5349,6 +5350,26 @@ public class TestFullResourcePath {
   }
   
   @Test
+  public void testEntitySetsInsteadOfNavigationProperties() {
+    testUri.runEx("ESAllPrim(0)/ESAllPrim(0)/ESAllPrim(0)")
+      .isExSemantic(MessageKeys.PROPERTY_NOT_IN_TYPE);
+  }
+  
+  @Test
+  public void testNavPropertySameNameAsEntitySet() throws Exception {
+    
+    testUri.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")
+      .goPath()
+      .at(0).isEntitySet("ESNavProp")
+      .at(0).isKeyPredicate(0, "a", "1")
+      .at(1).isNavProperty("ESNavProp", EdmTechTestProvider.nameETNavProp, false)
+      .at(1).isKeyPredicate(0, "a", "2")    
+      .at(2).isNavProperty("ESNavProp", EdmTechTestProvider.nameETNavProp, false)
+      .at(2).isKeyPredicate(0, "a", "3")
+      .at(3).isNavProperty("ESNavProp", EdmTechTestProvider.nameETNavProp, true);
+  }
+  
+  @Test
   public void testFilterLiteralTypes() throws Exception {
     testUri.run("ESAllPrim", "$filter='1' eq 42")
       .goFilter().isBinary(BinaryOperatorKind.EQ)

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/72b08138/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java
index e3250ea..08c6c91 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java
@@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
 import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet;
 import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
+import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
 import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
 import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
 import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
@@ -34,8 +35,10 @@ import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
 /**
  * Implement the EdmTechProvider and
  * <li>adds a entity type <b>ETabc with</b> properties a,b,c,d,e,f</li>
+ * <li>adds a entity type <b>ETNavProp with</b> with a navigation property ESNavProp (named like the entity set)</li>
  * <li>adds a complex type <b>CTabc</b> with properties a,b,c,d,e,f</li>
  * <li>adds a <b>abc</b> entity set of type <b>ETabc</b></li>
+ * <li>adds a <b>ESNavProp</b> entity set of type <b>ETNavProp</b></li>
  */
 public class EdmTechTestProvider extends EdmTechProvider {
 
@@ -50,6 +53,7 @@ public class EdmTechTestProvider extends EdmTechProvider {
   CsdlProperty propertyEInt16 = new CsdlProperty().setName("e").setType(nameInt16);
   CsdlProperty propertyFInt16 = new CsdlProperty().setName("f").setType(nameInt16);
 
+  public static final FullQualifiedName nameETNavProp = new FullQualifiedName(NAMESPACE, "ETNavProp");
   public static final FullQualifiedName nameCTabc = new FullQualifiedName(NAMESPACE, "CTabc");
   public static final FullQualifiedName nameETabc = new FullQualifiedName(NAMESPACE, "ETabc");
 
@@ -73,8 +77,12 @@ public class EdmTechTestProvider extends EdmTechProvider {
     if (nameContainer.equals(entityContainer)) {
       if (name.equals("ESabc")) {
         return new CsdlEntitySet()
-        .setName("ESabc")
-        .setType(nameETabc);
+            .setName("ESabc")
+            .setType(nameETabc);
+      } else if(name.equals("ESNavProp")) {
+        return new CsdlEntitySet()
+            .setName("ESNavProp")
+            .setType(nameETNavProp);
       }
     }
 
@@ -92,6 +100,17 @@ public class EdmTechTestProvider extends EdmTechProvider {
           propertyAInt16, propertyBInt16, propertyCInt16,
           propertyDInt16, propertyEInt16, propertyFInt16))
           .setKey(oneKeyPropertyInt16);
+    } else if(entityTypeName.equals(nameETNavProp)) {
+      return new CsdlEntityType()
+          .setName("ETNavProp")
+          .setProperties(Arrays.asList(propertyAInt16))
+          .setKey(oneKeyPropertyInt16)
+          .setNavigationProperties(Arrays.asList(new CsdlNavigationProperty[] {
+              new CsdlNavigationProperty()
+                .setCollection(true)
+                .setName("ESNavProp")
+                .setType(nameETNavProp)
+          }));
     }
 
     return super.getEntityType(entityTypeName);