From 7062aff86701571385d4283e011b7bc7c24ae7ed Mon Sep 17 00:00:00 2001 From: Klaus Straubinger Date: Tue, 12 May 2015 15:23:00 +0200 Subject: [PATCH] [OLINGO-659] Fix for filter parsing of $count resources Change-Id: I3359c25f233b6c18360a280b45355cf8ddd9a851 Signed-off-by: Christian Amend --- .../olingo/server/core/uri/parser/Parser.java | 9 +++++++++ .../server/core/uri/antlr/TestFullResourcePath.java | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java index cc788da73..6391212e0 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java @@ -36,7 +36,10 @@ import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriInfoKind; import org.apache.olingo.server.api.uri.UriResource; +import org.apache.olingo.server.api.uri.UriResourceCount; import org.apache.olingo.server.api.uri.UriResourcePartTyped; +import org.apache.olingo.server.api.uri.UriResourceRef; +import org.apache.olingo.server.api.uri.UriResourceValue; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; import org.apache.olingo.server.core.uri.UriInfoImpl; @@ -144,6 +147,12 @@ public class Parser { } UriResource lastSegment = context.contextUriInfo.getLastResourcePart(); + if (lastSegment instanceof UriResourceCount + || lastSegment instanceof UriResourceRef + || lastSegment instanceof UriResourceValue) { + final List parts = context.contextUriInfo.getUriResourceParts(); + lastSegment = parts.get(parts.size() - 2); + } if (lastSegment instanceof UriResourcePartTyped) { UriResourcePartTyped typed = (UriResourcePartTyped) lastSegment; 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 e46bca725..989b05818 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 @@ -4756,7 +4756,20 @@ public class TestFullResourcePath { .root().right().goPath() .first().isComplex("PropertyCompMixedEnumDef") .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator(); + } + @Test + public void filterOnCountAndRef() throws Exception { + testUri.run("ESKeyNav/$count", "$filter=PropertyInt16 ge 0") + .goPath().isCount() + .goUpUriValidator().goFilter().isBinary(BinaryOperatorKind.GE) + .left().goPath().first().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) + .goUpFilterValidator().root().right().isLiteral("0"); + testUri.run("ESKeyNav/$ref", "$filter=PropertyInt16 ge 0") + .goPath().isRef() + .goUpUriValidator().goFilter().isBinary(BinaryOperatorKind.GE) + .left().goPath().first().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) + .goUpFilterValidator().root().right().isLiteral("0"); } @Test