[OLINGO-821] small fix for UriParser handling of Enum/TypeDefinition Signed-off-by: Christian Amend <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/6614aea6 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/6614aea6 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/6614aea6 Branch: refs/heads/OLINGO-568_SearchParser_Draft Commit: 6614aea6bae1cacfaa71712f8335c253cef7dd0c Parents: 0c100df Author: Klaus Straubinger <[email protected]> Authored: Tue Nov 10 16:10:44 2015 +0100 Committer: Christian Amend <[email protected]> Committed: Tue Nov 10 16:16:53 2015 +0100 ---------------------------------------------------------------------- .../server/core/edm/provider/EdmEnumTest.java | 28 +++-- .../core/uri/parser/UriParseTreeVisitor.java | 18 +++- .../TechnicalPrimitiveComplexProcessor.java | 8 +- .../core/uri/antlr/TestFullResourcePath.java | 105 +++++++++++++++---- 4 files changed, 117 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6614aea6/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java index 04be8ae..af2d12f 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java @@ -68,7 +68,7 @@ public class EdmEnumTest { .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName())); when(edm.getEnumType(new FullQualifiedName("namespace.name"))).thenReturn(instance); when(edm.getEnumType(new FullQualifiedName("alias.name"))).thenReturn(instance); - + otherInstance = new EdmEnumTypeImpl(null, enumName, new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true) .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName())); @@ -178,15 +178,15 @@ public class EdmEnumTest { assertEquals("first", instance.fromUriLiteral("namespace.name'first'")); assertEquals("first", instance.fromUriLiteral("alias.name'first'")); - expectErrorInFromUriLiteral(instance, "", null); - expectErrorInFromUriLiteral(instance, "'", null); - expectErrorInFromUriLiteral(instance, "''", null); - expectErrorInFromUriLiteral(instance, "name'first'", null); - expectErrorInFromUriLiteral(instance, "namespace.name'", null); - expectErrorInFromUriLiteral(instance, "namespace.name'first", null); - expectErrorInFromUriLiteral(instance, "namespace.namespace'first", null); - expectErrorInFromUriLiteral(instance, "namespace.namespace'fi'rst", null); - expectErrorInFromUriLiteral(instance, "namespace.namespace'first'", null); + expectErrorInFromUriLiteral(instance, ""); + expectErrorInFromUriLiteral(instance, "'"); + expectErrorInFromUriLiteral(instance, "''"); + expectErrorInFromUriLiteral(instance, "name'first'"); + expectErrorInFromUriLiteral(instance, "namespace.name'"); + expectErrorInFromUriLiteral(instance, "namespace.name'first"); + expectErrorInFromUriLiteral(instance, "namespace.namespace'first"); + expectErrorInFromUriLiteral(instance, "namespace.namespace'fi'rst"); + expectErrorInFromUriLiteral(instance, "namespace.namespace'first'"); } @Test @@ -291,17 +291,13 @@ public class EdmEnumTest { expectContentErrorInValueToString(int16EnumType, Integer.MAX_VALUE); } - protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value, final String error) { + protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) { try { instance.fromUriLiteral(value); fail("Expected exception not thrown"); } catch (final EdmPrimitiveTypeException e) { assertNotNull(e.getLocalizedMessage()); - if(error == null){ - assertThat(e.getLocalizedMessage(), containsString("' has illegal content.")); - }else{ - assertThat(e.getLocalizedMessage(), containsString(error)); - } + assertThat(e.getLocalizedMessage(), containsString("' has illegal content.")); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6614aea6/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 eaf1075..c155355 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 @@ -483,7 +483,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> { } if (property instanceof EdmProperty) { - if (((EdmProperty) property).isPrimitive()) { + if (((EdmProperty) property).isPrimitive() + || property.getType().getKind() == EdmTypeKind.ENUM + || property.getType().getKind() == EdmTypeKind.DEFINITION) { // create simple property UriResourcePrimitivePropertyImpl simpleResource = new UriResourcePrimitivePropertyImpl() .setProperty((EdmProperty) property); @@ -1046,6 +1048,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> { return type; } + type = edm.getTypeDefinition(fullName); + if (type != null) { + return type; + } + type = edm.getEnumType(fullName); if (type != null) { return type; @@ -1994,8 +2001,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> { @Override public Object visitDecimalLiteral(final DecimalLiteralContext ctx) { final EdmType type = EdmPrimitiveTypeFactory.getInstance( - ctx.getText().contains("e") || ctx.getText().contains("E") ? EdmPrimitiveTypeKind.Double - : EdmPrimitiveTypeKind.Decimal); + ctx.getText().contains("e") || ctx.getText().contains("E") ? + EdmPrimitiveTypeKind.Double : + EdmPrimitiveTypeKind.Decimal); return new LiteralImpl().setText(ctx.getText()).setType(type); } @@ -2216,7 +2224,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> { // contextSelectItem.addSegment(newSegment); if (element instanceof EdmProperty) { EdmProperty property = (EdmProperty) element; - if (property.isPrimitive()) { + if (property.isPrimitive() + || property.getType().getKind() == EdmTypeKind.ENUM + || property.getType().getKind() == EdmTypeKind.DEFINITION) { UriResourcePrimitivePropertyImpl simple = new UriResourcePrimitivePropertyImpl(); simple.setProperty(property); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6614aea6/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java index 5928c30..87fbf00 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java @@ -460,8 +460,12 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor if (entitySet != null && !path.isEmpty()) { builder = builder.navOrPropertyPath(buildPropertyPath(path)); } - builder = builder.selectList(type.getKind() == EdmTypeKind.PRIMITIVE ? null : - helper.buildContextURLSelectList((EdmStructuredType) type, expand, select)); + builder = builder.selectList( + type.getKind() == EdmTypeKind.PRIMITIVE + || type.getKind() == EdmTypeKind.ENUM + || type.getKind() == EdmTypeKind.DEFINITION ? + null : + helper.buildContextURLSelectList((EdmStructuredType) type, expand, select)); return builder.build(); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6614aea6/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 58ccf16..fc48b9d 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 @@ -54,6 +54,7 @@ import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider; import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider; import org.apache.olingo.server.tecsvc.provider.PropertyProvider; +import org.apache.olingo.server.tecsvc.provider.TypeDefinitionProvider; import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; @@ -1424,6 +1425,26 @@ public class TestFullResourcePath { .isComplex("PropertyComp") .n() .isComplex("PropertyComp"); + + testUri.run("ESMixEnumDefCollComp(PropertyEnumString=olingo.odata.test1.ENString'String1'," + + "PropertyDefString='key1')/PropertyEnumString") + .isKind(UriInfoKind.resource).goPath() + .first() + .isEntitySet("ESMixEnumDefCollComp") + .isKeyPredicate(0, "PropertyEnumString", "olingo.odata.test1.ENString'String1'") + .isKeyPredicate(1, "PropertyDefString", "'key1'") + .n() + .isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false); + + testUri.run("ESMixEnumDefCollComp(PropertyEnumString=olingo.odata.test1.ENString'String1'," + + "PropertyDefString='key1')/PropertyDefString") + .isKind(UriInfoKind.resource).goPath() + .first() + .isEntitySet("ESMixEnumDefCollComp") + .isKeyPredicate(0, "PropertyEnumString", "olingo.odata.test1.ENString'String1'") + .isKeyPredicate(1, "PropertyDefString", "'key1'") + .n() + .isPrimitiveProperty("PropertyDefString", TypeDefinitionProvider.nameTDString, false); } @Test @@ -1458,6 +1479,26 @@ public class TestFullResourcePath { .isType(ComplexTypeProvider.nameCTPrimComp, true) .n() .isCount(); + + testUri.run("ESMixEnumDefCollComp(PropertyEnumString=olingo.odata.test1.ENString'String1'," + + "PropertyDefString='key1')/CollPropertyEnumString") + .isKind(UriInfoKind.resource).goPath() + .first() + .isEntitySet("ESMixEnumDefCollComp") + .isKeyPredicate(0, "PropertyEnumString", "olingo.odata.test1.ENString'String1'") + .isKeyPredicate(1, "PropertyDefString", "'key1'") + .n() + .isPrimitiveProperty("CollPropertyEnumString", EnumTypeProvider.nameENString, true); + + testUri.run("ESMixEnumDefCollComp(PropertyEnumString=olingo.odata.test1.ENString'String1'," + + "PropertyDefString='key1')/CollPropertyDefString") + .isKind(UriInfoKind.resource).goPath() + .first() + .isEntitySet("ESMixEnumDefCollComp") + .isKeyPredicate(0, "PropertyEnumString", "olingo.odata.test1.ENString'String1'") + .isKeyPredicate(1, "PropertyDefString", "'key1'") + .n() + .isPrimitiveProperty("CollPropertyDefString", TypeDefinitionProvider.nameTDString, true); } @Test @@ -2717,6 +2758,17 @@ public class TestFullResourcePath { .goUpExpandValidator() .isSelectText("PropertyCompNav/PropertyInt16"); + testUri.run("ESMixEnumDefCollComp", + "$select=PropertyEnumString,PropertyDefString,CollPropertyEnumString,CollPropertyDefString") + .isKind(UriInfoKind.resource) + .goSelectItemPath(0).isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) + .goUpUriValidator() + .goSelectItemPath(1).isPrimitiveProperty("PropertyDefString", TypeDefinitionProvider.nameTDString, false) + .goUpUriValidator() + .goSelectItemPath(2).isPrimitiveProperty("CollPropertyEnumString", EnumTypeProvider.nameENString, true) + .goUpUriValidator() + .goSelectItemPath(3).isPrimitiveProperty("CollPropertyDefString", TypeDefinitionProvider.nameTDString, true); + testUri.runEx("ESKeyNav", "$expand=undefined") .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); testUri.runEx("ESTwoKeyNav", "$expand=PropertyCompNav/undefined") @@ -3599,7 +3651,6 @@ public class TestFullResourcePath { .root().right() .isType(PropertyProvider.nameDecimal); - // testFilter.runOnETAllPrim("PropertyDecimal ge PropertyDecimal") .is("<<PropertyDecimal> ge <PropertyDecimal>>") .isBinary(BinaryOperatorKind.GE) @@ -4397,8 +4448,6 @@ public class TestFullResourcePath { .goUpFilterValidator().root() .goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoPrim); - // testFilter.runOnETKeyNav(" Xcast(PropertyCompTwoPrim,olingo.odata.test1.CTAllPrim)"); - testFilter.runOnETKeyNav("cast(NavPropertyETKeyNavOne,olingo.odata.test1.ETKeyPrimNav)") .is("<cast(<NavPropertyETKeyNavOne>,<olingo.odata.test1.ETKeyPrimNav>)>") .isMethod(MethodKind.CAST, 2) @@ -4657,7 +4706,7 @@ public class TestFullResourcePath { .goUpFilterValidator() .root().goParameter(1).isTypedLiteral(PropertyProvider.nameTimeOfDay); - testFilter.runOnETTwoKeyNav(" isof(PropertyComp/PropertyComp/PropertyDuration,Edm.Duration)") + testFilter.runOnETTwoKeyNav("isof(PropertyComp/PropertyComp/PropertyDuration,Edm.Duration)") .is("<isof(<PropertyComp/PropertyComp/PropertyDuration>,<Edm.Duration>)>") .root() .isMethod(MethodKind.ISOF, 2) @@ -4689,6 +4738,20 @@ public class TestFullResourcePath { .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) .goUpFilterValidator() .root().goParameter(1).isTypedLiteral(PropertyProvider.nameGuid); + + testFilter.runOnETMixEnumDefCollComp("isof(PropertyEnumString,Namespace1_Alias.ENString)") + .isMethod(MethodKind.ISOF, 2) + .goParameter(0).goPath() + .first().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) + .goUpFilterValidator() + .root().goParameter(1).isTypedLiteral(EnumTypeProvider.nameENString); + + testFilter.runOnETMixEnumDefCollComp("isof(PropertyDefString,Namespace1_Alias.TDString)") + .isMethod(MethodKind.ISOF, 2) + .goParameter(0).goPath() + .first().isPrimitiveProperty("PropertyDefString", TypeDefinitionProvider.nameTDString, false) + .goUpFilterValidator() + .root().goParameter(1).isTypedLiteral(TypeDefinitionProvider.nameTDString); } @Test @@ -4697,7 +4760,7 @@ public class TestFullResourcePath { testFilter.runOnETMixEnumDefCollComp("PropertyEnumString has olingo.odata.test1.ENString'String1'") .is("<<PropertyEnumString> has <olingo.odata.test1.ENString<String1>>>") .isBinary(BinaryOperatorKind.HAS) - .root().left().goPath().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) + .root().left().goPath().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) .goUpFilterValidator() .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); @@ -4707,8 +4770,7 @@ public class TestFullResourcePath { .isBinary(BinaryOperatorKind.HAS) .root().left().goPath() .first().isComplex("PropertyCompMixedEnumDef") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .isType(EnumTypeProvider.nameENString) + .n().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) .goUpFilterValidator() .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String2")); @@ -4722,7 +4784,7 @@ public class TestFullResourcePath { .isBinary(BinaryOperatorKind.HAS) .root().left().left().goPath() .first().isComplex("PropertyCompMixedEnumDef") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) + .n().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) .goUpFilterValidator() .root().left().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String2")); @@ -4730,8 +4792,7 @@ public class TestFullResourcePath { .is("<<PropertyEnumString> has <olingo.odata.test1.ENString<String3>>>") .isBinary(BinaryOperatorKind.HAS) .root().left().goPath() - .first().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .isType(EnumTypeProvider.nameENString) + .first().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) .goUpFilterValidator() .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String3")); @@ -4739,8 +4800,7 @@ public class TestFullResourcePath { .is("<<PropertyEnumString> has <olingo.odata.test1.ENString<String,String3>>>") .isBinary(BinaryOperatorKind.HAS) .root().left().goPath() - .first().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .isType(EnumTypeProvider.nameENString) + .first().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) .goUpFilterValidator() .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String", "String3")); @@ -4749,7 +4809,8 @@ public class TestFullResourcePath { .root() .isBinary(BinaryOperatorKind.HAS) .root().left().goPath() - .first().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator() + .first().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) + .goUpFilterValidator() .root().right().isNull(); testFilter.runOnETTwoKeyNav("endswith(PropertyComp/PropertyComp/PropertyString,'dorf')") @@ -4964,14 +5025,14 @@ public class TestFullResourcePath { testFilter.runOnETMixEnumDefCollComp("PropertyEnumString eq olingo.odata.test1.ENString'String1'") .is("<<PropertyEnumString> eq <olingo.odata.test1.ENString<String1>>>") .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) + .root().left().goPath().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) .goUpFilterValidator() .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); testFilter.runOnETMixEnumDefCollComp("PropertyEnumString eq olingo.odata.test1.ENString'String2'") .is("<<PropertyEnumString> eq <olingo.odata.test1.ENString<String2>>>") .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) + .root().left().goPath().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) .goUpFilterValidator() .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String2")); @@ -4981,7 +5042,8 @@ public class TestFullResourcePath { .isBinary(BinaryOperatorKind.EQ) .root().left().goPath() .first().isComplex("PropertyCompMixedEnumDef") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator() + .n().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) + .goUpFilterValidator() .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String3")); testFilter @@ -4993,10 +5055,11 @@ public class TestFullResourcePath { .isBinary(BinaryOperatorKind.EQ) .root().left().goPath() .first().isComplex("PropertyCompMixedEnumDef") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator() + .n().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) + .goUpFilterValidator() .root().right().goPath() .first().isComplex("PropertyCompMixedEnumDef") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator(); + .n().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false); testFilter.runUriEx("ESMixEnumDefCollComp", "$filter=PropertyEnumString has ENString'String1'") .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); @@ -5337,12 +5400,14 @@ public class TestFullResourcePath { testFilter.runOrderByOnETMixEnumDefCollComp("PropertyEnumString eq olingo.odata.test1.ENString'String1'") .isSortOrder(0, false) - .goOrder(0).left().goPath().isComplex("PropertyEnumString").goUpFilterValidator() + .goOrder(0).left().goPath().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) + .goUpFilterValidator() .goOrder(0).right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); testFilter.runOrderByOnETMixEnumDefCollComp("PropertyEnumString eq olingo.odata.test1.ENString'String1' desc") .isSortOrder(0, true) - .goOrder(0).left().goPath().isComplex("PropertyEnumString").goUpFilterValidator() + .goOrder(0).left().goPath().isPrimitiveProperty("PropertyEnumString", EnumTypeProvider.nameENString, false) + .goUpFilterValidator() .goOrder(0).right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 1")
