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/10/06 17:27:25 UTC
[2/2] olingo-odata4 git commit: [OLINGO-791] Namespaces are not
longer allowed for entity sets, singeltons, action imports, function imports
[OLINGO-791] Namespaces are not longer allowed for entity sets, singeltons, action imports, function imports
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/0989fbd0
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0989fbd0
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0989fbd0
Branch: refs/heads/master
Commit: 0989fbd0743fa3349133d7911644759052a13a36
Parents: d0b225b
Author: Christian Holzer <c....@sap.com>
Authored: Tue Oct 6 17:27:02 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Tue Oct 6 17:27:02 2015 +0200
----------------------------------------------------------------------
.../core/uri/parser/UriParseTreeVisitor.java | 19 ++++++++++++++++++-
.../uri/parser/UriParserSemanticException.java | 6 ++++--
.../server-core-exceptions-i18n.properties | 1 +
.../core/uri/antlr/TestFullResourcePath.java | 9 +++++++++
4 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/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 f61c6ee..7ea1adb 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
@@ -331,6 +331,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmEntitySet != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
+ ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceEntitySetImpl().setEntitSet(edmEntitySet));
return null;
@@ -341,6 +342,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmSingleton != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
+ ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceSingletonImpl().setSingleton(edmSingleton));
return null;
@@ -351,6 +353,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmActionImport != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
+ ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceActionImpl().setActionImport(edmActionImport));
return null;
@@ -396,7 +399,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ "' with parameters [" + tmp.toString() + "] not found",
UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, edmFunctionImport.getName(), tmp.toString()));
}
-
+
+ ensureNamespaceIsNull(ctx.vNS);
uriResource.setFunction(edmFunctionImport.getUnboundFunction(names));
context.contextUriInfo.addResourcePart(uriResource);
return null;
@@ -708,6 +712,19 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriParserSemanticException.MessageKeys.UNKNOWN_PART, fullFilterName.toString()));
}
}
+
+ /**
+ * Ensures that the namespace of the first resource parts is null
+ * @param vNS namespace or null
+ */
+ private void ensureNamespaceIsNull(final NamespaceContext vNS) {
+ if(vNS != null && context.contextUriInfo.getLastResourcePart() == null) {
+ // First resource part and namespace is not null!
+ throw wrap(new UriParserSemanticException("Namespace is not allowed for EntitySets, Singeltons, "
+ + " Action Imports and Function Imports. Found " + vNS.getText(),
+ UriParserSemanticException.MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT, vNS.getText()));
+ }
+ }
private String getName(final EdmType type) {
return type.getFullQualifiedName().getFullQualifiedNameAsString();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
index 672d093..6803e7a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
@@ -77,8 +77,10 @@ public class UriParserSemanticException extends UriParserException {
/** parameter: resource_name */
RESOURCE_NOT_FOUND,
/** parameter: not implemented part */
- NOT_IMPLEMENTED;
-
+ NOT_IMPLEMENTED,
+ /** parameter: namespace **/
+ NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT;
+
@Override
public String getKey() {
return name();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 3484ab3..267db11 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -67,6 +67,7 @@ UriParserSemanticException.NOT_FOR_ENTITY_TYPE=Not allowed for entity type.
UriParserSemanticException.PREVIOUS_PART_TYPED=The previous part is typed.
UriParserSemanticException.RESOURCE_NOT_FOUND=Cannot find EntitySet, Singleton, ActionImport or FunctionImport with name '%1$s'.
UriParserSemanticException.NOT_IMPLEMENTED=%1$s is not implemented!
+UriParserSemanticException.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT=Namespace is not allowed for Entity Sets, Singeltons, Action Imports and Function Imports. Found '%1$s'.
UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/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 3b2ff14..7df684e 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
@@ -5571,6 +5571,15 @@ public class TestFullResourcePath {
}
@Test
+ public void testFirstResourcePathWithNamespace() {
+ testUri.runEx("olingo.odata.test1.ESAllPrim").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.ESAllPrim(0)").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.FINRTInt16()").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.AIRTString").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.SINav").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ }
+
+ @Test
public void navPropertySameNameAsEntitySet() throws Exception {
testUri.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")
.goPath()