Repository: olingo-odata2 Updated Branches: refs/heads/master 2c5605940 -> 6ce2421a5
[OLINGO-1146] Fix regression for filter with navigation Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/6ce2421a Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/6ce2421a Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/6ce2421a Branch: refs/heads/master Commit: 6ce2421a5d7ebb40d6456d12f38913f725e87457 Parents: 2c56059 Author: mibo <[email protected]> Authored: Sat Sep 23 21:01:51 2017 +0200 Committer: mibo <[email protected]> Committed: Sat Sep 23 21:02:49 2017 +0200 ---------------------------------------------------------------------- .../core/uri/expression/FilterParserImpl.java | 21 +++++++++++++++----- .../odata2/core/uri/expression/TestParser.java | 5 +++-- 2 files changed, 19 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6ce2421a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java index bf16e24..230ec59 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserImpl.java @@ -506,11 +506,13 @@ public class FilterParserImpl implements FilterParser { if (edmProperty != null) { property.setEdmProperty(edmProperty); property.setEdmType(edmProperty.getType()); - if (edmProperty.getMultiplicity() == EdmMultiplicity.MANY) { - throw new ExpressionParserException( - ExpressionParserException.INVALID_MULTIPLICITY.create() - .addContent(propertyName) - .addContent(propertyToken.getPosition() + 1)); + if(isLastFilterElement(propertyName)) { + if (edmProperty.getMultiplicity() == EdmMultiplicity.MANY) { + throw new ExpressionParserException( + ExpressionParserException.INVALID_MULTIPLICITY.create() + .addContent(propertyName) + .addContent(propertyToken.getPosition() + 1)); + } } } else { // Tested with TestParserExceptions.TestPMvalidateEdmProperty CASE 3 @@ -524,6 +526,15 @@ public class FilterParserImpl implements FilterParser { } } + /** + * Check if the property name is the last or only element of the filter + * @param propertyName name of the property + * @return <code>true</code> if this is the last or only otherwise <code>false</code> + */ + private boolean isLastFilterElement(String propertyName) { + return curExpression.contains(propertyName + " "); + } + protected void validateUnaryOperatorTypes(final UnaryExpression unaryExpression) throws ExpressionParserInternalError { InfoUnaryOperator unOpt = availableUnaryOperators.get(unaryExpression.getOperator().toUriLiteral()); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6ce2421a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java index bbec5d9..637287c 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/expression/TestParser.java @@ -389,11 +389,12 @@ public class TestParser extends TestBase { final EdmEntityType entityType = edmInfo.getTypeEtKeyTypeInteger(); final EdmEntityType entityType2 = edmInfo.getTypeEtKeyTypeString(); GetPTF_noTEST(entityType, "navProperty").aExKey(ExpressionParserException.TYPE_EXPECTED_AT); - GetPTF_noTEST(entityType, "navProperty/navProperty").aExKey(ExpressionParserException.INVALID_MULTIPLICITY); + GetPTF_noTEST(entityType, "navProperty/navProperty").aExKey(ExpressionParserException.TYPE_EXPECTED_AT); GetPTF_noTEST(entityType, "navProperty/KeyString eq 'a'") .root().left().left().aEdmType(entityType2) .root().left().right().aEdmType(EdmString.getInstance()); - GetPTF_noTEST(entityType2, "navProperty/KeyInteger eq 1").aExKey(ExpressionParserException.INVALID_MULTIPLICITY); + GetPTF_noTEST(entityType2, "navProperty/KeyInteger eq 1") + .aExKey(ExpressionParserException.INVALID_TYPES_FOR_BINARY_OPERATOR); GetPTF_noTEST(entityType, "navProperty ne null").root().left().aEdmType(entityType2); GetPTF_noTEST(entityType, "navProperty ne null and not (navProperty eq null)") .root().aKind(ExpressionKind.BINARY)
