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-odata4.git
The following commit(s) were added to refs/heads/master by this push:
new b914808 [OLINGO-1495]Uri parsing error for GET request on child
entity with ID
b914808 is described below
commit b914808524484f7d3a72c9e1193ef40cff7512d6
Author: ramya vasanth <[email protected]>
AuthorDate: Tue Nov 24 15:48:13 2020 +0530
[OLINGO-1495]Uri parsing error for GET request on child entity with ID
---
.../server/core/uri/parser/ParserHelper.java | 8 ++++++-
.../server/tecsvc/provider/EntityTypeProvider.java | 2 ++
.../server/tecsvc/provider/PropertyProvider.java | 13 +++++++++++
.../serializer/xml/ODataXmlSerializerTest.java | 15 +++++++++++++
.../server/core/uri/parser/UriParserTest.java | 9 ++++++++
.../core/uri/testutil/ResourceValidator.java | 25 ++++++++++++++++++++++
6 files changed, 71 insertions(+), 1 deletion(-)
diff --git
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
index 2304888..ee91b01 100644
---
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
+++
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
@@ -310,11 +310,17 @@ public class ParserHelper {
referencedNames.put(name, referencedName);
}
}
+ for (final EdmKeyPropertyRef candidate : keyPropertyRefs) {
+ final UriParameter simpleKey = simpleKey(tokenizer, candidate, edm,
referringType, aliases);
+ if (simpleKey != null) {
+ keys.add(simpleKey);
+ }
+ }
}
if (keyPropertyRefs.size() - referencedNames.size() == 1) {
for (final EdmKeyPropertyRef candidate : keyPropertyRefs) {
- if (referencedNames.get(candidate.getName()) == null) {
+ if (referencedNames.get(candidate.getName()) == null) {
final UriParameter simpleKey = simpleKey(tokenizer, candidate, edm,
referringType, aliases);
if (simpleKey != null) {
keys.add(simpleKey);
diff --git
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
index 6a76e27..9a6a637 100644
---
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
+++
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
@@ -292,6 +292,7 @@ public class EntityTypeProvider {
.setName("ETMedia")
.setKey(Arrays.asList(new
CsdlPropertyRef().setName("PropertyInt16")))
.setProperties(Arrays.asList(PropertyProvider.propertyInt16_NotNullable))
+
.setNavigationProperties(Arrays.asList(PropertyProvider.navPropertyETMediaOne_ETKeyNavMany))
.setHasStream(true);
} else if (entityTypeName.equals(nameETServerSidePaging)) {
@@ -430,6 +431,7 @@ public class EntityTypeProvider {
new CsdlNavigationProperty()
.setName("NavPropertyETKeyNavOne")
.setType(nameETKeyNav)
+ .setPartner("NavPropertyETTwoKeyNavMany")
.setReferentialConstraints(Arrays.asList(
new CsdlReferentialConstraint()
.setProperty("PropertyInt16")
diff --git
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
index febb04e..e34987a 100644
---
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
+++
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
@@ -18,10 +18,13 @@
*/
package org.apache.olingo.server.tecsvc.provider;
+import java.util.Arrays;
+
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
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.CsdlReferentialConstraint;
public class PropertyProvider {
@@ -775,6 +778,7 @@ public class PropertyProvider {
public static final CsdlNavigationProperty
collectionNavPropertyETMediaMany_ETMedia = new CsdlNavigationProperty()
.setName("NavPropertyETMediaMany")
.setType(EntityTypeProvider.nameETMedia)
+ .setPartner("NavPropertyETKeyNavOne")
.setCollection(true);
public static final CsdlNavigationProperty
collectionNavPropertyETTwoKeyNavMany_ETTwoKeyNav_WithPartnerERKeyNavOne =
@@ -852,6 +856,15 @@ public class PropertyProvider {
.setName("NavPropertyETTwoPrimOne")
.setType(EntityTypeProvider.nameETTwoPrim)
.setNullable(false);
+
+ public static final CsdlNavigationProperty
navPropertyETMediaOne_ETKeyNavMany = new CsdlNavigationProperty()
+ .setName("NavPropertyETKeyNavOne")
+ .setType(EntityTypeProvider.nameETKeyNav)
+ .setPartner("NavPropertyETMediaMany")
+ .setReferentialConstraints(Arrays.asList(
+ new CsdlReferentialConstraint()
+ .setProperty("PropertyInt16")
+ .setReferencedProperty("PropertyInt16")));
public static final CsdlNavigationProperty navPropertyETAllPrimOne_ETAllPrim
= new CsdlNavigationProperty()
.setName("NavPropertyETAllPrimOne")
diff --git
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
index 56ddf19..3321d7d 100644
---
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
+++
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
@@ -1327,6 +1327,9 @@ public class ODataXmlSerializerTest {
" <a:link rel=\"edit\" href=\"ESMedia(1)\"/>\n" +
" <a:content type=\"image/svg+xml\" src=\"ESMedia(1)/$value\" />\n" +
" <a:link rel=\"edit-media\" title=\"ESMedia\"
href=\"ESMedia(1)/$value\"/>\n" +
+ " <a:link
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETKeyNavOne\" "
+ + "type=\"application/atom+xml;type=feed\"
title=\"NavPropertyETKeyNavOne\" "
+ + "href=\"ESMedia(1)/NavPropertyETKeyNavOne\"/>" +
" <a:category
scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETMedia\" />\n" +
" <m:properties>\n" +
@@ -1366,6 +1369,9 @@ public class ODataXmlSerializerTest {
" <a:link rel=\"edit\" href=\"ESMedia(1)\"/>\n" +
" <a:content type=\"image/svg+xml\" src=\"ESMedia(1)/$value\" />\n"
+
" <a:link rel=\"edit-media\" title=\"ESMedia\"
href=\"ESMedia(1)/$value\"/>\n" +
+ " <a:link
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETKeyNavOne\" "
+ + "type=\"application/atom+xml;type=feed\" "
+ + "title=\"NavPropertyETKeyNavOne\"
href=\"ESMedia(1)/NavPropertyETKeyNavOne\"/>" +
" <a:category
scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETMedia\" />\n" +
" <m:properties>\n" +
@@ -1383,6 +1389,9 @@ public class ODataXmlSerializerTest {
" <a:link rel=\"edit\" href=\"ESMedia(2)\"/>\n" +
" <a:content type=\"image/svg+xml\" src=\"ESMedia(2)/$value\" />\n"
+
" <a:link rel=\"edit-media\" title=\"ESMedia\"
href=\"ESMedia(2)/$value\"/>\n" +
+ " <a:link
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETKeyNavOne\" "
+ + "type=\"application/atom+xml;type=feed\" "
+ + "title=\"NavPropertyETKeyNavOne\"
href=\"ESMedia(2)/NavPropertyETKeyNavOne\"/>" +
" <a:category
scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETMedia\" />\n" +
" <m:properties>\n" +
@@ -1400,6 +1409,9 @@ public class ODataXmlSerializerTest {
" <a:link rel=\"edit\" href=\"ESMedia(3)\"/>\n" +
" <a:content type=\"image/svg+xml\" src=\"ESMedia(3)/$value\" />\n"
+
" <a:link rel=\"edit-media\" title=\"ESMedia\"
href=\"ESMedia(3)/$value\"/>\n" +
+ " <a:link
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETKeyNavOne\" "
+ + "type=\"application/atom+xml;type=feed\" "
+ + "title=\"NavPropertyETKeyNavOne\"
href=\"ESMedia(3)/NavPropertyETKeyNavOne\"/>" +
" <a:category
scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETMedia\" />\n" +
" <m:properties>\n" +
@@ -1417,6 +1429,9 @@ public class ODataXmlSerializerTest {
" <a:link rel=\"edit\" href=\"ESMedia(4)\"/>\n" +
" <a:content type=\"image/svg+xml\" src=\"ESMedia(4)/$value\" />\n"
+
" <a:link rel=\"edit-media\" title=\"ESMedia\"
href=\"ESMedia(4)/$value\"/>\n" +
+ " <a:link
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETKeyNavOne\" "
+ + "type=\"application/atom+xml;type=feed\" "
+ + "title=\"NavPropertyETKeyNavOne\"
href=\"ESMedia(4)/NavPropertyETKeyNavOne\"/>" +
" <a:category
scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETMedia\" />\n" +
" <m:properties>\n" +
diff --git
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
index c97cb93..8ee4938 100644
---
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
+++
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
@@ -117,6 +117,15 @@ public class UriParserTest {
.isType(EntityTypeProvider.nameETTwoKeyNav)
.isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
.n().isRef();
+
+
testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')")
+ .isEntityType("ETTwoKeyNav")
+ .isKeyPredicateForNavSeg(0, "PropertyInt16", "1")
+ .isKeyPredicateForNavSeg(1, "PropertyString", "'1'");
+
+ testRes.run("ESKeyNav(1)/NavPropertyETMediaMany(1)")
+ .isEntityType("ETMedia")
+ .isKeyPredicateForNavSeg(0, "PropertyInt16", "1");
}
@Test
diff --git
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
index 147cbd3..c57f76e 100644
---
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
+++
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.util.List;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmElement;
import org.apache.olingo.commons.api.edm.EdmType;
@@ -236,12 +238,27 @@ public class ResourceValidator implements TestValidator {
assertEquals(text, keyPredicate.getText());
return this;
}
+
+ public ResourceValidator isKeyPredicateForNavSeg(final int index, final
String name, final String text) {
+ final UriParameter keyPredicate =
getKeyPredicateForNavSegment(index);
+ assertEquals(name, keyPredicate.getName());
+ assertEquals(text, keyPredicate.getText());
+ return this;
+ }
private UriParameter getKeyPredicate(final int index) {
assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(),
uriPathInfo instanceof UriResourceWithKeysImpl);
return ((UriResourceWithKeysImpl)
uriPathInfo).getKeyPredicates().get(index);
}
+
+ private UriParameter getKeyPredicateForNavSegment(final int index) {
+ List<UriResource> uriResources = uriInfo.getUriResourceParts();
+ UriResource lastSegment = uriResources.get(uriResources.size() - 1);
+ assertTrue("invalid resource kind: " + lastSegment.getKind(),
+ lastSegment instanceof UriResourceNavigation);
+ return
((UriResourceNavigation)lastSegment).getKeyPredicates().get(index);
+ }
public ResourceValidator isParameter(final int index, final String name,
final String text) {
isUriPathInfoKind(UriResourceKind.function);
@@ -319,6 +336,14 @@ public class ResourceValidator implements TestValidator {
assertEquals(name, ((UriResourceEntitySet)
uriPathInfo).getEntitySet().getName());
return this;
}
+
+ public ResourceValidator isEntityType(final String name) {
+ isUriPathInfoKind(UriResourceKind.entitySet);
+ List<UriResource> uriResources = uriInfo.getUriResourceParts();
+ UriResource lastSegment = uriResources.get(uriResources.size() - 1);
+ assertEquals(name,
((UriResourceNavigation)lastSegment).getType().getName());
+ return this;
+ }
public ResourceValidator isSingleton(final String name) {
isUriPathInfoKind(UriResourceKind.singleton);