You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2015/10/22 10:08:55 UTC
[1/2] olingo-odata4 git commit: [OLINGO-795] enum type validation in
URI parser
Repository: olingo-odata4
Updated Branches:
refs/heads/master 397f8e200 -> 23fb86a87
[OLINGO-795] enum type validation in URI parser
Signed-off-by: Michael Bolz <mi...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/4134b2e8
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/4134b2e8
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/4134b2e8
Branch: refs/heads/master
Commit: 4134b2e82cdf86a876cdbcb0e584eda5c0e667b6
Parents: 397f8e2
Author: Klaus Straubinger <kl...@sap.com>
Authored: Wed Oct 21 09:56:34 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Oct 22 10:03:31 2015 +0200
----------------------------------------------------------------------
.../core/uri/parser/UriParseTreeVisitor.java | 51 ++--
.../core/uri/antlr/TestFullResourcePath.java | 235 +++++++++----------
2 files changed, 132 insertions(+), 154 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4134b2e8/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 7ea1adb..9adf5da 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
@@ -998,14 +998,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
@Override
public Object visitBooleanNonCaseLiteral(final BooleanNonCaseLiteralContext ctx) {
- String text = ctx.getText().toLowerCase();
-
- if (text.equals("false")) {
- return new LiteralImpl().setText("false").setType(
- EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean));
- }
- return new LiteralImpl().setText("true").setType(
- EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean));
+ final String text = ctx.getText().toLowerCase();
+ return new LiteralImpl().setText(text.equals("false") ? "false" : "true")
+ .setType(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean));
}
@Override
@@ -1195,11 +1190,15 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EnumerationImpl enum1 = new EnumerationImpl();
// get type
- String odi = ctx.vODI.getText();
-
- FullQualifiedName fullName = getFullNameFromContext(ctx.vNS, odi);
- EdmEnumType edmEnumType = edm.getEnumType(fullName);
-
+ final String odi = ctx.vODI.getText();
+
+ final FullQualifiedName fullName = getFullNameFromContext(ctx.vNS, odi);
+ final EdmEnumType edmEnumType = edm.getEnumType(fullName);
+ if (edmEnumType == null) {
+ throw wrap(new UriParserSemanticException(
+ "Enum type '" + fullName.getFullQualifiedNameAsString() + "' not found!",
+ UriParserSemanticException.MessageKeys.UNKNOWN_TYPE, fullName.getFullQualifiedNameAsString()));
+ }
enum1.setType(edmEnumType);
String valueString = ctx.vValues.getText();
@@ -1237,7 +1236,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
levels.setText(ctx.vM.getText());
try {
expandItem.setSystemQueryOption(levels);
- } catch(ODataRuntimeException e) {
+ } catch (ODataRuntimeException e) {
// Thrown if duplicated system query options are detected
throw wrap(new UriParserSyntaxException("Double system query option!", e,
UriParserSyntaxException.MessageKeys.DOUBLE_SYSTEM_QUERY_OPTION, e.getMessage()));
@@ -1968,7 +1967,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
@Override
public Object visitStringLiteral(final StringLiteralContext ctx) {
return new LiteralImpl().setText(ctx.getText())
- .setType(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String));
+ .setType(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String));
}
@Override
@@ -1982,27 +1981,25 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
@Override
public Object visitIntLiteral(final IntLiteralContext ctx) {
+ EdmPrimitiveTypeKind typeKind = null;
try {
final long value = Long.parseLong(ctx.getText());
- EdmType type = null;
-
if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
- type = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte);
+ typeKind = EdmPrimitiveTypeKind.SByte;
} else if (value >= 0 && value <= 255) {
- type = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte);
+ typeKind = EdmPrimitiveTypeKind.Byte;
} else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
- type = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16);
+ typeKind = EdmPrimitiveTypeKind.Int16;
} else if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
- type = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
+ typeKind = EdmPrimitiveTypeKind.Int32;
} else {
- type = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64);
+ typeKind = EdmPrimitiveTypeKind.Int64;
}
-
- return new LiteralImpl().setText(ctx.getText()).setType(type);
- } catch( NumberFormatException e) {
- return new LiteralImpl().setText(ctx.getText())
- .setType(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal));
+ } catch (final NumberFormatException e) {
+ typeKind = EdmPrimitiveTypeKind.Decimal;
}
+ return new LiteralImpl().setText(ctx.getText())
+ .setType(EdmPrimitiveTypeFactory.getInstance(typeKind));
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4134b2e8/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 4d39d97..3299a92 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
@@ -20,39 +20,24 @@ package org.apache.olingo.server.core.uri.antlr;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
+import java.util.Collections;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.core.Encoder;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmBinary;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmBoolean;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmByte;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmGuid;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmSByte;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
+import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.uri.UriInfoKind;
import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
import org.apache.olingo.server.core.uri.parser.UriParserException;
-import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException.MessageKeys;
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
-import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
import org.apache.olingo.server.core.uri.validator.UriValidationException;
import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
@@ -64,15 +49,15 @@ import org.junit.Ignore;
import org.junit.Test;
public class TestFullResourcePath {
- Edm edm = null;
- TestUriValidator testUri = null;
- ResourceValidator testRes = null;
- FilterValidator testFilter = null;
+
+ private static final OData oData = OData.newInstance();
+ private final TestUriValidator testUri;
+ private final FilterValidator testFilter;
public TestFullResourcePath() {
- edm = new EdmProviderImpl(new EdmTechTestProvider());
+ final Edm edm = oData.createServiceMetadata(new EdmTechTestProvider(), Collections.<EdmxReference> emptyList())
+ .getEdm();
testUri = new TestUriValidator().setEdm(edm);
- testRes = new ResourceValidator().setEdm(edm);
testFilter = new FilterValidator().setEdm(edm);
}
@@ -437,9 +422,9 @@ public class TestFullResourcePath {
.isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
testUri.runEx("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNavParam(WrongParameter='1')")
- .isExSemantic(UriParserSemanticException.MessageKeys.UNKNOWN_PART);
+ .isExSemantic(MessageKeys.UNKNOWN_PART);
testUri.runEx("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString=wrong)")
- .isExSemantic(UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE);
+ .isExSemantic(MessageKeys.INVALID_KEY_VALUE);
}
@Test
@@ -960,57 +945,42 @@ public class TestFullResourcePath {
@Test
public void runEsNameError() {
- testUri.runEx("ESAllPrim/$count/$ref")
- .isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PROPERTIES);
- testUri.runEx("ESAllPrim/$ref/$count")
- .isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS);
- testUri.runEx("ESAllPrim/$ref/invalid")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
- testUri.runEx("ESAllPrim/$count/invalid")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
- testUri.runEx("ESAllPrim/PropertyString")
- .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_AFTER_COLLECTION);
- testUri.runEx("ESAllPrim(1)/whatever")
- .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
- testUri.runEx("ESAllPrim(PropertyInt16)")
- .isExSemantic(UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE);
- testUri.runEx("ESAllPrim(PropertyInt16=)")
- .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
- testUri.runEx("ESAllPrim(PropertyInt16=1,Invalid='1')")
- .isExSemantic(UriParserSemanticException.MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES);
+ testUri.runEx("ESAllPrim/$count/$ref").isExSemantic(MessageKeys.ONLY_FOR_TYPED_PROPERTIES);
+ testUri.runEx("ESAllPrim/$ref/$count").isExSemantic(MessageKeys.ONLY_FOR_TYPED_PARTS);
+ testUri.runEx("ESAllPrim/$ref/invalid").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ testUri.runEx("ESAllPrim/$count/invalid").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ testUri.runEx("ESAllPrim/PropertyString").isExSemantic(MessageKeys.PROPERTY_AFTER_COLLECTION);
+ testUri.runEx("ESAllPrim(1)/whatever").isExSemantic(MessageKeys.PROPERTY_NOT_IN_TYPE);
+ testUri.runEx("ESAllPrim(PropertyInt16)").isExSemantic(MessageKeys.INVALID_KEY_VALUE);
+ testUri.runEx("ESAllPrim(PropertyInt16=)").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
+ testUri.runEx("ESAllPrim(PropertyInt16=1,Invalid='1')").isExSemantic(MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES);
testUri.runEx("ESBase/olingo.odata.test1.ETBase/PropertyInt16")
- .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_AFTER_COLLECTION);
+ .isExSemantic(MessageKeys.PROPERTY_AFTER_COLLECTION);
testUri.runEx("ETBaseTwoKeyTwoPrim/olingo.odata.test1.ETBaseTwoKeyTwoPrim"
+ "/olingo.odata.test1.ETTwoBaseTwoKeyTwoPrim")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
+ .isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
testUri.runEx("ETBaseTwoKeyTwoPrim/olingo.odata.test1.ETBaseTwoKeyTwoPrim(1)/olingo.odata.test1.ETAllKey")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
+ .isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/olingo.odata.test1.ETBaseTwoKeyTwoPrim('1')/olingo.odata.test1.ETAllKey")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
+ .isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/olingo.odata.test1.ETBaseTwoKeyTwoPrim"
+ "/olingo.odata.test1.ETTwoBaseTwoKeyTwoPrim")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
+ .isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
testUri.runEx("ETBaseTwoKeyTwoPrim/olingo.odata.test1.ETBaseTwoKeyTwoPrim"
+ "/olingo.odata.test1.ETTwoBaseTwoKeyTwoPrim(1)")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
-
- testUri.runEx("ETBaseTwoKeyTwoPrim/olingo.odata.test1.ETAllKey")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
-
- testUri.runEx("ETBaseTwoKeyTwoPrim()")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
+ .isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
- testUri.runEx("ESAllNullable(1)/CollPropertyString/$value")
- .isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS);
+ testUri.runEx("ETBaseTwoKeyTwoPrim/olingo.odata.test1.ETAllKey").isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
+ testUri.runEx("ETBaseTwoKeyTwoPrim()").isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
+ testUri.runEx("ESAllNullable(1)/CollPropertyString/$value").isExSemantic(MessageKeys.ONLY_FOR_TYPED_PARTS);
- testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
+ testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value").isExSemantic(MessageKeys.RESOURCE_NOT_FOUND);
}
@Test
@@ -1286,10 +1256,8 @@ public class TestFullResourcePath {
.isKeyPredicate(2, "KeyAlias2", "'3'")
.isKeyPredicate(3, "KeyAlias3", "'4'");
- testUri.runEx("ESTwoPrim(wrong)")
- .isExSemantic(UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE);
- testUri.runEx("ESTwoPrim(PropertyInt16=wrong)")
- .isExSemantic(UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE);
+ testUri.runEx("ESTwoPrim(wrong)").isExSemantic(MessageKeys.INVALID_KEY_VALUE);
+ testUri.runEx("ESTwoPrim(PropertyInt16=wrong)").isExSemantic(MessageKeys.INVALID_KEY_VALUE);
}
@Test
@@ -1322,13 +1290,12 @@ public class TestFullResourcePath {
@Test
public void runEsNameKeyCast() throws Exception {
// testUri.runEx("ESTwoPrim(1)/olingo.odata.test1.ETBase(1)")
- // .isExSemantic(UriParserSemanticException.MessageKeys.xxx);
+ // .isExSemantic(MessageKeys.xxx);
// testUri.runEx("ESTwoPrim/olingo.odata.test1.ETBase(1)/olingo.odata.test1.ETTwoBase(1)")
- // .isExSemantic(UriParserSemanticException.MessageKeys.xxx);
+ // .isExSemantic(MessageKeys.xxx);
- testUri.runEx("ESBase/olingo.odata.test1.ETTwoPrim(1)")
- .isExSemantic(UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER);
+ testUri.runEx("ESBase/olingo.odata.test1.ETTwoPrim(1)").isExSemantic(MessageKeys.INCOMPATIBLE_TYPE_FILTER);
testUri.run("ESTwoPrim(1)/olingo.odata.test1.ETBase")
.isKind(UriInfoKind.resource).goPath()
@@ -2025,10 +1992,8 @@ public class TestFullResourcePath {
public void runFunctionImpError() {
testUri.runEx("FICRTCollCTTwoPrimTwoParam")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
- testUri.runEx("FICRTCollCTTwoPrimTwoParam()")
- .isExSemantic(UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND);
- testUri.runEx("FICRTCollCTTwoPrimTwoParam(invalidParam=2)")
- .isExSemantic(UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND);
+ testUri.runEx("FICRTCollCTTwoPrimTwoParam()").isExSemantic(MessageKeys.FUNCTION_NOT_FOUND);
+ testUri.runEx("FICRTCollCTTwoPrimTwoParam(invalidParam=2)").isExSemantic(MessageKeys.FUNCTION_NOT_FOUND);
}
@Test
@@ -2715,9 +2680,9 @@ public class TestFullResourcePath {
.isSelectText("PropertyCompNav/PropertyInt16");
testUri.runEx("ESKeyNav", "$expand=undefined")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testUri.runEx("ESTwoKeyNav", "$expand=PropertyCompNav/undefined")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
}
@Test
@@ -2897,7 +2862,7 @@ public class TestFullResourcePath {
.goPath().first()
.isEntitySet("ESKeyNav")
.isKeyPredicate(0, "PropertyInt16", "1");
- testUri.runEx("ESKeyNav()").isExSemantic(UriParserSemanticException.MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES);
+ testUri.runEx("ESKeyNav()").isExSemantic(MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES);
testUri.run("SINav")
.isKind(UriInfoKind.resource)
@@ -3187,12 +3152,12 @@ public class TestFullResourcePath {
.isLiteral("'SomeString'");
testFilter.runOnETTwoKeyNavEx("invalid")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
// TODO: This should throw an exception because the top node of the filter tree must be boolean.
// testFilter.runOnETTwoKeyNavEx("PropertyComp")
- // .isExSemantic(UriParserSemanticException.MessageKeys.XYZ);
+ // .isExSemantic(MessageKeys.XYZ);
testFilter.runOnETTwoKeyNavEx("PropertyComp/invalid")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("concat('a','b')/invalid").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOnETTwoKeyNavEx("PropertyComp/concat('a','b')")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
@@ -3204,11 +3169,11 @@ public class TestFullResourcePath {
// testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyComp/PropertyString eq 1")
// .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyInt64 eq 1")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("NavPropertyETKeyNavMany/PropertyInt16 gt 42")
- .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_AFTER_COLLECTION);
+ .isExSemantic(MessageKeys.PROPERTY_AFTER_COLLECTION);
testFilter.runOnETTwoKeyNavEx("NavPropertyETKeyNavMany/NavPropertyETTwoKeyNavOne eq null")
- .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_AFTER_COLLECTION);
+ .isExSemantic(MessageKeys.PROPERTY_AFTER_COLLECTION);
testFilter.runOnETAllPrim("PropertySByte eq PropertySByte")
.is("<<PropertySByte> eq <PropertySByte>>")
@@ -4405,7 +4370,7 @@ public class TestFullResourcePath {
.goParameter(1).isTypedLiteral(EntityTypeProvider.nameETKeyPrimNav);
testFilter.runOnETKeyNavEx("cast(NavPropertyETKeyPrimNavOne,olingo.odata.test1.ETKeyNav)")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETKeyNav("any()")
.isMember().goPath().first().isUriPathInfoKind(UriResourceKind.lambdaAny);
}
@@ -4995,8 +4960,14 @@ public class TestFullResourcePath {
.first().isComplex("PropertyCompMixedEnumDef")
.n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator();
+ testFilter.runUriEx("ESMixEnumDefCollComp", "$filter=PropertyEnumString has ENString'String1'")
+ .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
+ testFilter.runUriEx("ESMixEnumDefCollComp", "$filter=PropertyEnumString has wrongNamespace.ENString'String1'")
+ .isExSemantic(MessageKeys.UNKNOWN_TYPE);
+ testFilter.runUriEx("ESMixEnumDefCollComp", "$filter=PropertyEnumString has olingo.odata.test1.Wrong'String1'")
+ .isExSemantic(MessageKeys.UNKNOWN_TYPE);
}
-
+
@Test
public void filterOnCountAndRef() throws Exception {
testUri.run("ESKeyNav/$count", "$filter=PropertyInt16 ge 0")
@@ -5347,9 +5318,9 @@ public class TestFullResourcePath {
testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc desc")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOrderByOnETTwoKeyNavEx("undefined")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOrderByOnETTwoKeyNavEx("PropertyComp/undefined")
- .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
+ .isExSemantic(MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
}
@Test
@@ -5392,62 +5363,62 @@ public class TestFullResourcePath {
@Test
public void testErrors() {
testUri.runEx("FICRTString(wrong1='ABC')/olingo.odata.test1.BFCStringRTESTwoKeyNav()")
- .isExSemantic(UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND);
+ .isExSemantic(MessageKeys.FUNCTION_NOT_FOUND);
testUri.runEx("FICRTString(wrong1='ABC', wrong2=1)/olingo.odata.test1.BFCStringRTESTwoKeyNav()")
- .isExSemantic(UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND);
+ .isExSemantic(MessageKeys.FUNCTION_NOT_FOUND);
// type filter for entity incompatible
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/olingo.odata.test1.ETBase")
- .isExSemantic(UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER);
+ .isExSemantic(MessageKeys.INCOMPATIBLE_TYPE_FILTER);
// type filter for entity double on entry
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')"
+ "/olingo.odata.test1.ETBaseTwoKeyNav/olingo.odata.test1.ETBaseTwoKeyNav")
- .isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
+ .isExSemantic(MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
// type filter for entity double on collection
testUri.runEx("ESTwoKeyNav/olingo.odata.test1.ETBaseTwoKeyNav/olingo.odata.test1.ETBaseTwoKeyNav")
- .isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
+ .isExSemantic(MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
// type filter for entity double on non key pred
testUri.runEx("SINav/olingo.odata.test1.ETBaseTwoKeyNav/olingo.odata.test1.ETBaseTwoKeyNav")
- .isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
+ .isExSemantic(MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
// type filter for complex incompatible
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim"
+ "/olingo.odata.test1.CTCollAllPrim")
- .isExSemantic(UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER);
+ .isExSemantic(MessageKeys.INCOMPATIBLE_TYPE_FILTER);
// type filter for complex double on entry
testUri.runEx("FICRTCTTwoPrimTwoParam(ParameterInt16=1,ParameterString='2')"
+ "/olingo.odata.test1.CTBase/olingo.odata.test1.CTBase")
- .isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
+ .isExSemantic(MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
// type filter for complex double on collection
testUri.runEx("FICRTCollCTTwoPrimTwoParam(ParameterInt16=1,ParameterString='2')"
+ "/olingo.odata.test1.CTBase/olingo.odata.test1.CTBase")
- .isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
+ .isExSemantic(MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
// type filter for complex double on non key pred
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim"
+ "/olingo.odata.test1.CTBase/olingo.odata.test1.CTBase")
- .isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
+ .isExSemantic(MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
testUri.runEx("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav")
- .isExSemantic(UriParserSemanticException.MessageKeys.UNKNOWN_TYPE);
+ .isExSemantic(MessageKeys.UNKNOWN_TYPE);
// $ref
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$ref")
- .isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_ENTITY_TYPES);
+ .isExSemantic(MessageKeys.ONLY_FOR_ENTITY_TYPES);
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$count")
- .isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_COLLECTIONS);
+ .isExSemantic(MessageKeys.ONLY_FOR_COLLECTIONS);
// Actions must not be followed by anything.
testUri.runEx(ContainerProvider.AIRT_STRING + "/$value")
.isExValidation(UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_VALUE);
testUri.runEx(ContainerProvider.AIRTCT_TWO_PRIM_PARAM + "/PropertyInt16")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ .isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/"
+ "olingo.odata.test1.BAETTwoKeyNavRTETTwoKeyNav/olingo.odata.test1.ETTwoKeyNav")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ .isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
testUri.runEx("ESTwoKeyNav/olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav/$count")
.isExValidation(UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_COUNT);
}
@@ -5586,80 +5557,90 @@ public class TestFullResourcePath {
public void filterLiteralTypes() throws Exception {
testUri.run("ESAllPrim", "$filter='1' eq 42")
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("'1'").isLiteralType(EdmString.getInstance())
+ .left().isLiteral("'1'").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String))
.root()
- .right().isLiteral("42").isLiteralType(EdmSByte.getInstance());
+ .right().isLiteral("42").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte));
testUri.run("ESAllPrim", "$filter=127 eq 128")
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("127").isLiteralType(EdmSByte.getInstance())
+ .left().isLiteral("127").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte))
.root()
- .right().isLiteral("128").isLiteralType(EdmByte.getInstance());
+ .right().isLiteral("128").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte));
testUri.run("ESAllPrim", "$filter=null eq 42.1")
.goFilter().isBinary(BinaryOperatorKind.EQ)
.left().isLiteral("null").isNullLiteralType()
.root()
- .right().isLiteral("42.1").isLiteralType(EdmDecimal.getInstance());
+ .right().isLiteral("42.1").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal));
testUri.run("ESAllPrim", "$filter=15.6E300 eq 3.4E37")
.goFilter().isBinary(BinaryOperatorKind.EQ)
.left().isLiteral("15.6E300")
- .isLiteralType(EdmDouble.getInstance())
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double))
.root()
- .right().isLiteral("3.4E37").isLiteralType(EdmDouble.getInstance());
+ .right().isLiteral("3.4E37").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double));
testUri.run("ESAllPrim", "$filter=15.55555555555555555555555555555555555555555555 eq 3.1")
.goFilter().isBinary(BinaryOperatorKind.EQ)
.left().isLiteral("15.55555555555555555555555555555555555555555555")
- .isLiteralType(EdmDecimal.getInstance())
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal))
.root()
- .right().isLiteral("3.1").isLiteralType(EdmDecimal.getInstance());
+ .right().isLiteral("3.1").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal));
testUri.run("ESAllPrim", "$filter=duration'PT1H2S' eq 2012-12-03")
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("duration'PT1H2S'").isLiteralType(EdmDuration.getInstance())
+ .left().isLiteral("duration'PT1H2S'")
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration))
.root()
- .right().isLiteral("2012-12-03").isLiteralType(EdmDate.getInstance());
+ .right().isLiteral("2012-12-03").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Date));
testUri.run("ESAllPrim", "$filter=true eq 2012-12-03T07:16:23Z")
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("true").isLiteralType(EdmBoolean.getInstance())
+ .left().isLiteral("true").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean))
.root()
- .right().isLiteral("2012-12-03T07:16:23Z").isLiteralType(EdmDateTimeOffset.getInstance());
+ .right().isLiteral("2012-12-03T07:16:23Z")
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset));
testUri.run("ESAllPrim", "$filter=07:59:59.999 eq 01234567-89ab-cdef-0123-456789abcdef")
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("07:59:59.999").isLiteralType(EdmTimeOfDay.getInstance())
+ .left().isLiteral("07:59:59.999")
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.TimeOfDay))
.root()
- .right().isLiteral("01234567-89ab-cdef-0123-456789abcdef").isLiteralType(EdmGuid.getInstance());
+ .right().isLiteral("01234567-89ab-cdef-0123-456789abcdef")
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid));
testUri.run("ESAllPrim", "$filter=binary'0FAB7B' eq true")
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("binary'0FAB7B'").isLiteralType(EdmBinary.getInstance())
+ .left().isLiteral("binary'0FAB7B'").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Binary))
.root()
- .right().isLiteral("true").isLiteralType(EdmBoolean.getInstance());
+ .right().isLiteral("true").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean));
testUri.run("ESAllPrim", "$filter=" + Short.MIN_VALUE + " eq " + Short.MAX_VALUE)
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("" + Short.MIN_VALUE).isLiteralType(EdmInt16.getInstance())
+ .left().isLiteral("" + Short.MIN_VALUE)
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16))
.root()
- .right().isLiteral("" + Short.MAX_VALUE).isLiteralType(EdmInt16.getInstance());
-
+ .right().isLiteral("" + Short.MAX_VALUE)
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16));
+
testUri.run("ESAllPrim", "$filter=" + Integer.MIN_VALUE + " eq " + Integer.MAX_VALUE)
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("" + Integer.MIN_VALUE).isLiteralType(EdmInt32.getInstance())
+ .left().isLiteral("" + Integer.MIN_VALUE)
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32))
.root()
- .right().isLiteral("" + Integer.MAX_VALUE).isLiteralType(EdmInt32.getInstance());
+ .right().isLiteral("" + Integer.MAX_VALUE)
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32));
testUri.run("ESAllPrim", "$filter=" + Long.MIN_VALUE + " eq " + Long.MAX_VALUE)
.goFilter().isBinary(BinaryOperatorKind.EQ)
- .left().isLiteral("" + Long.MIN_VALUE).isLiteralType(EdmInt64.getInstance())
+ .left().isLiteral("" + Long.MIN_VALUE)
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64))
.root()
- .right().isLiteral("" + Long.MAX_VALUE).isLiteralType(EdmInt64.getInstance());
+ .right().isLiteral("" + Long.MAX_VALUE)
+ .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64));
}
- public static String encode(final String decoded) throws UnsupportedEncodingException {
- return Encoder.encode(decoded);
+ public static String encode(final String decoded) {
+ return decoded.replaceAll(":", "%3A");
}
}
[2/2] olingo-odata4 git commit: [OLINGO-801] better enum and alias
support in technical service
Posted by mi...@apache.org.
[OLINGO-801] better enum and alias support in technical service
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/23fb86a8
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/23fb86a8
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/23fb86a8
Branch: refs/heads/master
Commit: 23fb86a870ce1c85b2a41ea6612a5749385e8fe2
Parents: 4134b2e8
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Oct 22 10:04:49 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Oct 22 10:04:49 2015 +0200
----------------------------------------------------------------------
.../tecsvc/client/FilterSystemQueryITCase.java | 8 ++-
.../processor/TechnicalEntityProcessor.java | 18 +++---
.../ExpandSystemQueryOptionHandler.java | 29 +++++-----
.../expression/ExpressionVisitorImpl.java | 44 ++++++++++-----
.../expression/operand/TypedOperand.java | 59 +++++++++++---------
.../expression/operand/UntypedOperand.java | 33 +++++++----
.../expression/operand/VisitorOperand.java | 2 +-
.../expression/operation/BinaryOperator.java | 17 ++++--
.../queryoptions/options/FilterHandler.java | 27 ++++-----
.../queryoptions/options/OrderByHandler.java | 27 ++++-----
10 files changed, 156 insertions(+), 108 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
index 2045802..aa22966 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
@@ -19,6 +19,7 @@
package org.apache.olingo.fit.tecsvc.client;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.net.URI;
import java.util.LinkedHashMap;
@@ -41,6 +42,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
private static final String ES_COMP_ALL_PRIM = "ESCompAllPrim";
private static final String ES_TWO_KEY_NAV = "ESTwoKeyNav";
private static final String ES_ALL_PRIM = "ESAllPrim";
+ private static final String ES_MIX_ENUM_DEF_COLL_COMP = "ESMixEnumDefCollComp";
@Test
public void timeOfDayLiteral() {
@@ -184,6 +186,9 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
clientEntity = result.getBody().getEntities().get(1);
assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());
+
+ result = sendRequest(ES_MIX_ENUM_DEF_COLL_COMP, "PropertyEnumString has Namespace1_Alias.ENString'String1'");
+ assertTrue(result.getBody().getEntities().isEmpty());
}
@Test
@@ -994,7 +999,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
result = sendRequest(ES_ALL_PRIM, "'Test1' ne 'Test'");
assertEquals(3, result.getBody().getEntities().size());
}
-
+
@Test
public void castException() {
fail("ESAllPrim", "PropertyInt16 eq '1'", HttpStatusCode.BAD_REQUEST);
@@ -1004,7 +1009,6 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
fail("ESAllPrim", "PropertyInt16 eq duration'PT4S'", HttpStatusCode.BAD_REQUEST);
}
-
@Test
public void stringFunctionWithoutStringParameters() {
fail("ESServerSidePaging", "contains(PropertyInt16, 3) eq 'hallo'", HttpStatusCode.BAD_REQUEST);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 95bcdc7..74cdd51 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -91,15 +91,15 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
}
@Override
- public void countEntityCollection(final ODataRequest request, final ODataResponse response, final UriInfo
- uriInfo) throws ODataApplicationException, ODataLibraryException {
+ public void countEntityCollection(final ODataRequest request, final ODataResponse response,
+ final UriInfo uriInfo) throws ODataApplicationException, ODataLibraryException {
validateOptions(uriInfo.asUriInfoResource());
- final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo); // including checks
+ getEdmEntitySet(uriInfo); // including checks
final EntityCollection entitySetInitial = readEntityCollection(uriInfo);
EntityCollection entitySet = new EntityCollection();
entitySet.getEntities().addAll(entitySetInitial.getEntities());
- FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, edmEntitySet);
+ FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, uriInfo, serviceMetadata.getEdm());
response.setContent(odata.createFixedFormatSerializer().count(
entitySet.getEntities().size()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
@@ -430,7 +430,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final ExpandSystemQueryOptionHandler expandHandler = new ExpandSystemQueryOptionHandler();
final Entity entitySerialization = expandHandler.transformEntityGraphToTree(entity, edmEntitySet, expand);
- expandHandler.applyExpandQueryOptions(entitySerialization, edmEntitySet, expand);
+ expandHandler.applyExpandQueryOptions(entitySerialization, edmEntitySet, expand, uriInfo,
+ serviceMetadata.getEdm());
final SerializerResult serializerResult = isReference ?
serializeReference(entity, edmEntitySet, requestedFormat) :
@@ -480,9 +481,9 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
entitySet.getEntities().addAll(entitySetInitial.getEntities());
// Apply system query options
- FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, edmEntitySet);
+ FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, uriInfo, serviceMetadata.getEdm());
CountHandler.applyCountSystemQueryOption(uriInfo.getCountOption(), entitySet);
- OrderByHandler.applyOrderByOption(uriInfo.getOrderByOption(), entitySet, edmEntitySet);
+ OrderByHandler.applyOrderByOption(uriInfo.getOrderByOption(), entitySet, uriInfo, serviceMetadata.getEdm());
SkipHandler.applySkipSystemQueryHandler(uriInfo.getSkipOption(), entitySet);
TopHandler.applyTopSystemQueryOption(uriInfo.getTopOption(), entitySet);
@@ -505,7 +506,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final EntityCollection entitySetSerialization = expandHandler.transformEntitySetGraphToTree(entitySet,
edmEntitySet,
expand);
- expandHandler.applyExpandQueryOptions(entitySetSerialization, edmEntitySet, expand);
+ expandHandler.applyExpandQueryOptions(entitySetSerialization, edmEntitySet, expand, uriInfo,
+ serviceMetadata.getEdm());
final CountOption countOption = uriInfo.getCountOption();
String id;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
index e0faf41..4cc88f8 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
@@ -27,6 +27,7 @@ import java.util.Set;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection;
import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
import org.apache.olingo.commons.api.edm.EdmElement;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
@@ -35,6 +36,7 @@ import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.uri.UriInfoResource;
import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.queryoption.CountOption;
@@ -53,29 +55,28 @@ import org.apache.olingo.server.tecsvc.processor.queryoptions.options.TopHandler
public class ExpandSystemQueryOptionHandler {
public void applyExpandQueryOptions(final EntityCollection entitySet, final EdmEntitySet edmEntitySet,
- final ExpandOption expandOption) throws ODataApplicationException {
+ final ExpandOption expandOption, final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {
if (expandOption == null) {
return;
}
for (final Entity entity : entitySet.getEntities()) {
- applyExpandOptionToEntity(entity, edmEntitySet, expandOption);
+ applyExpandOptionToEntity(entity, edmEntitySet, expandOption, uriInfo, edm);
}
}
public void applyExpandQueryOptions(final Entity entity, final EdmEntitySet edmEntitySet,
- final ExpandOption expandOption)
- throws ODataApplicationException {
+ final ExpandOption expandOption, final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {
if (expandOption == null) {
return;
}
- applyExpandOptionToEntity(entity, edmEntitySet, expandOption);
+ applyExpandOptionToEntity(entity, edmEntitySet, expandOption, uriInfo, edm);
}
private void applyExpandOptionToEntity(final Entity entity, final EdmBindingTarget edmBindingTarget,
- final ExpandOption expandOption) throws ODataApplicationException {
-
+ final ExpandOption expandOption, final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {
+
final EdmEntityType entityType = edmBindingTarget.getEntityType();
for (ExpandItem item : expandOption.getExpandItems()) {
@@ -103,7 +104,7 @@ public class ExpandSystemQueryOptionHandler {
}
}
- for(EdmNavigationProperty navigationProperty: navigationProperties) {
+ for (EdmNavigationProperty navigationProperty: navigationProperties) {
final String navPropertyName = navigationProperty.getName();
final EdmBindingTarget targetEdmEntitySet = edmBindingTarget.getRelatedBindingTarget(navPropertyName);
@@ -116,7 +117,8 @@ public class ExpandSystemQueryOptionHandler {
item.getCountOption(),
item.getSkipOption(),
item.getTopOption(),
- item.getExpandOption());
+ item.getExpandOption(),
+ uriInfo, edm);
}
}
}
@@ -125,11 +127,12 @@ public class ExpandSystemQueryOptionHandler {
private void applyOptionsToEntityCollection(final EntityCollection entitySet,
final EdmBindingTarget edmBindingTarget,
final FilterOption filterOption, final OrderByOption orderByOption, final CountOption countOption,
- final SkipOption skipOption, final TopOption topOption, final ExpandOption expandOption)
+ final SkipOption skipOption, final TopOption topOption, final ExpandOption expandOption,
+ final UriInfoResource uriInfo, final Edm edm)
throws ODataApplicationException {
- FilterHandler.applyFilterSystemQuery(filterOption, entitySet, edmBindingTarget);
- OrderByHandler.applyOrderByOption(orderByOption, entitySet, edmBindingTarget);
+ FilterHandler.applyFilterSystemQuery(filterOption, entitySet, uriInfo, edm);
+ OrderByHandler.applyOrderByOption(orderByOption, entitySet, uriInfo, edm);
CountHandler.applyCountSystemQueryOption(countOption, entitySet);
SkipHandler.applySkipSystemQueryHandler(skipOption, entitySet);
TopHandler.applyTopSystemQueryOption(topOption, entitySet);
@@ -137,7 +140,7 @@ public class ExpandSystemQueryOptionHandler {
// Apply nested expand system query options to remaining entities
if (expandOption != null) {
for (final Entity entity : entitySet.getEntities()) {
- applyExpandOptionToEntity(entity, edmBindingTarget, expandOption);
+ applyExpandOptionToEntity(entity, edmBindingTarget, expandOption, uriInfo, edm);
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
index 969a754..b362456 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
@@ -23,8 +23,9 @@ import java.util.Locale;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.http.HttpStatusCode;
@@ -48,16 +49,19 @@ import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operati
public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand> {
- final private Entity entity;
+ private final Entity entity;
+ private final UriInfoResource uriInfo;
+ private final Edm edm;
- public ExpressionVisitorImpl(final Entity entity, final EdmBindingTarget bindingTarget) {
+ public ExpressionVisitorImpl(final Entity entity, final UriInfoResource uriInfo, final Edm edm) {
this.entity = entity;
+ this.uriInfo = uriInfo;
+ this.edm = edm;
}
@Override
public VisitorOperand visitBinaryOperator(final BinaryOperatorKind operator, final VisitorOperand left,
- final VisitorOperand right)
- throws ExpressionVisitException, ODataApplicationException {
+ final VisitorOperand right) throws ExpressionVisitException, ODataApplicationException {
final BinaryOperator binaryOperator = new BinaryOperator(left, right);
@@ -84,6 +88,9 @@ public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand>
case DIV:
case MOD:
return binaryOperator.arithmeticOperator(operator);
+ case HAS:
+ return binaryOperator.hasOperator();
+
default:
return throwNotImplemented();
}
@@ -161,15 +168,13 @@ public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand>
@Override
public VisitorOperand visitLambdaExpression(final String lambdaFunction, final String lambdaVariable,
- final Expression expression)
- throws ExpressionVisitException, ODataApplicationException {
-
+ final Expression expression) throws ExpressionVisitException, ODataApplicationException {
return throwNotImplemented();
}
@Override
public VisitorOperand visitLiteral(final Literal literal) throws ExpressionVisitException, ODataApplicationException {
- return new UntypedOperand(literal.getText());
+ return new UntypedOperand(literal.getText(), edm);
}
@Override
@@ -204,12 +209,12 @@ public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand>
@Override
public VisitorOperand visitAlias(final String aliasName) throws ExpressionVisitException, ODataApplicationException {
- return throwNotImplemented();
+ return new UntypedOperand(uriInfo.getValueForAlias(aliasName), edm);
}
@Override
- public VisitorOperand visitTypeLiteral(final EdmType type) throws ExpressionVisitException,
- ODataApplicationException {
+ public VisitorOperand visitTypeLiteral(final EdmType type)
+ throws ExpressionVisitException, ODataApplicationException {
return throwNotImplemented();
}
@@ -221,9 +226,18 @@ public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand>
@Override
public VisitorOperand visitEnum(final EdmEnumType type, final List<String> enumValues)
- throws ExpressionVisitException,
- ODataApplicationException {
- return throwNotImplemented();
+ throws ExpressionVisitException, ODataApplicationException {
+ Long result = null;
+ try {
+ for (final String enumValue : enumValues) {
+ final Long value = type.valueOfString(enumValue, null, null, null, null, null, Long.class);
+ result = result == null ? value : result | value;
+ }
+ } catch (final EdmPrimitiveTypeException e) {
+ throw new ODataApplicationException("Illegal enum value.",
+ HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT, e);
+ }
+ return new TypedOperand(result, type);
}
private VisitorOperand throwNotImplemented() throws ODataApplicationException {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/TypedOperand.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/TypedOperand.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/TypedOperand.java
index 11cf3ab..fc36f96 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/TypedOperand.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/TypedOperand.java
@@ -19,6 +19,7 @@
package org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand;
import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.Locale;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
@@ -54,38 +55,44 @@ public class TypedOperand extends VisitorOperand {
}
@Override
- public TypedOperand asTypedOperand(final EdmPrimitiveType... asTypes) throws ODataApplicationException {
+ public TypedOperand asTypedOperand(final EdmPrimitiveType asType) throws ODataApplicationException {
if (is(primNull)) {
return this;
} else if (isNull()) {
- return new TypedOperand(null, asTypes[0]);
+ return new TypedOperand(null, asType);
}
Object newValue = null;
- for (EdmPrimitiveType asType : asTypes) {
- // Use BigDecimal for unlimited precision
- if (asType.equals(primDouble) || asType.equals(primSingle) || asType.equals(primDecimal)) {
-
- try {
- newValue = new BigDecimal(value.toString());
- } catch (NumberFormatException e) {
- // Nothing to do
- }
- } else {
- // Use type conversion of EdmPrimitive types
- try {
- final String literal = getLiteral(value);
- newValue = tryCast(literal, asType);
- } catch (EdmPrimitiveTypeException e) {
- // Nothing to do
- }
+ // Use BigInteger for arbitrarily large whole numbers.
+ if (asType.equals(primSByte) || asType.equals(primByte)
+ || asType.equals(primInt16) || asType.equals(primInt32) || asType.equals(primInt64)) {
+ if (value instanceof BigInteger) {
+ newValue = value;
+ } else if (value instanceof Byte || value instanceof Short
+ || value instanceof Integer || value instanceof Long) {
+ newValue = BigInteger.valueOf(((Number) value).longValue());
}
-
- if (newValue != null) {
- return new TypedOperand(newValue, asType);
+ // Use BigDecimal for unlimited precision.
+ } else if (asType.equals(primDouble) || asType.equals(primSingle) || asType.equals(primDecimal)) {
+ try {
+ newValue = new BigDecimal(value.toString());
+ } catch (NumberFormatException e) {
+ // Nothing to do
+ }
+ } else {
+ // Use type conversion of EdmPrimitive types
+ try {
+ final String literal = getLiteral(value);
+ newValue = tryCast(literal, asType);
+ } catch (EdmPrimitiveTypeException e) {
+ // Nothing to do
}
}
+ if (newValue != null) {
+ return new TypedOperand(newValue, asType);
+ }
+
throw new ODataApplicationException("Cast failed", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
}
@@ -93,11 +100,9 @@ public class TypedOperand extends VisitorOperand {
final TypedOperand other = otherOperand.asTypedOperand();
final EdmType oType = other.getType();
- // In case of numberic values make sure that the EDM type is equals, check also the java type.
- // So it is possible, that there is an conversation even if the same
- // EdmType is provided.
- // For example consider an Edm16 (internal Integer) and Edm16(internal
- // Short)
+ // In case of numberic values make sure that the EDM type is equal, check also the java type.
+ // It is possible that there is an conversion even if the same EdmType is provided.
+ // For example consider an Edm.Int32 (internal Integer) and an Edm.Int16 (internal Short) value:
// shortInstance.equals(intInstance) will always be false!
if (type == oType && value != null && other.getValue() != null
&& value.getClass() == other.getValue().getClass()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/UntypedOperand.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/UntypedOperand.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/UntypedOperand.java
index ffc4a62..755d8d1 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/UntypedOperand.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/UntypedOperand.java
@@ -20,15 +20,21 @@ package org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operan
import java.util.Locale;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.server.api.ODataApplicationException;
public class UntypedOperand extends VisitorOperand {
- public UntypedOperand(final String literal) {
+ private final Edm edm;
+
+ public UntypedOperand(final String literal, final Edm edm) {
super(literal);
+ this.edm = edm;
}
@Override
@@ -37,22 +43,18 @@ public class UntypedOperand extends VisitorOperand {
}
@Override
- public TypedOperand asTypedOperand(final EdmPrimitiveType... types) throws ODataApplicationException {
+ public TypedOperand asTypedOperand(final EdmPrimitiveType type) throws ODataApplicationException {
final String literal = (String) value;
Object newValue = null;
- // First try the null literal
+ // First try the null literal.
if ((newValue = tryCast(literal, primNull)) != null) {
return new TypedOperand(newValue, primNull);
}
- // Than try the given types
- for (EdmPrimitiveType type : types) {
- newValue = tryCast(literal, type);
-
- if (newValue != null) {
- return new TypedOperand(newValue, type);
- }
+ // Then try the given type.
+ if ((newValue = tryCast(literal, type)) != null) {
+ return new TypedOperand(newValue, type);
}
throw new ODataApplicationException("Cast failed", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
@@ -130,6 +132,17 @@ public class UntypedOperand extends VisitorOperand {
return new TypedOperand(newValue, primDouble);
}
+ // Enum
+ final EdmSchema schema = edm.getSchema(edm.getEntityContainer().getNamespace());
+ final String enumValue = schema.getAlias() != null && literal.startsWith(schema.getAlias()) ?
+ literal.replace(schema.getAlias(), schema.getNamespace()) :
+ literal;
+ for (final EdmEnumType enumType : schema.getEnumTypes()) {
+ if ((newValue = tryCast(enumValue, enumType)) != null) {
+ return new TypedOperand(newValue, enumType);
+ }
+ }
+
throw new ODataApplicationException("Could not determine type for literal " + literal,
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/VisitorOperand.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/VisitorOperand.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/VisitorOperand.java
index bc4bfd5..c06b6bb 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/VisitorOperand.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operand/VisitorOperand.java
@@ -85,7 +85,7 @@ public abstract class VisitorOperand {
public abstract TypedOperand asTypedOperand() throws ODataApplicationException;
- public abstract TypedOperand asTypedOperand(EdmPrimitiveType... types) throws ODataApplicationException;
+ public abstract TypedOperand asTypedOperand(EdmPrimitiveType type) throws ODataApplicationException;
public abstract EdmProperty getEdmProperty();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java
index 9ff1bc2..5c24127 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java
@@ -168,7 +168,15 @@ public class BinaryOperator {
return new TypedOperand(result, primBoolean);
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
+ public VisitorOperand hasOperator() throws ODataApplicationException {
+ final boolean result = isBinaryComparisonNecessary()
+ && !left.getTypedValue(BigInteger.class).equals(BigInteger.ZERO)
+ && left.getTypedValue(BigInteger.class).and(BigInteger.valueOf(right.getTypedValue(Number.class).longValue()))
+ .equals(BigInteger.valueOf(right.getTypedValue(Number.class).longValue()));
+ return new TypedOperand(result, primBoolean);
+ }
+
+ @SuppressWarnings("unchecked")
private boolean binaryComparison(final int... expect) {
int result;
@@ -180,13 +188,14 @@ public class BinaryOperator {
result = left.getTypedValue(BigInteger.class).compareTo(right.getTypedValue(BigInteger.class));
} else if (left.isDecimalType()) {
result = left.getTypedValue(BigDecimal.class).compareTo(right.getTypedValue(BigDecimal.class));
- } else if(left.getValue().getClass() == right.getValue().getClass() && left.getValue() instanceof Comparable) {
- result = ((Comparable)left.getValue()).compareTo(right.getValue());
+ } else if(left.getValue().getClass() == right.getValue().getClass()
+ && left.getValue() instanceof Comparable<?>) {
+ result = ((Comparable<Object>) left.getValue()).compareTo(right.getValue());
} else {
result = left.getValue().equals(right.getValue()) ? 0 : 1;
}
}
-
+
for (int expectedValue : expect) {
if (expectedValue == result) {
return true;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/FilterHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/FilterHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/FilterHandler.java
index 5f5c9df..b2bd405 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/FilterHandler.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/FilterHandler.java
@@ -23,12 +23,13 @@ import java.util.Locale;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.uri.UriInfoResource;
import org.apache.olingo.server.api.uri.queryoption.FilterOption;
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.ExpressionVisitorImpl;
@@ -37,16 +38,11 @@ import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand
public class FilterHandler {
- protected static final OData oData;
- protected static final EdmPrimitiveType primBoolean;
-
- static {
- oData = OData.newInstance();
- primBoolean = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean);
- }
+ protected static final EdmPrimitiveType primBoolean =
+ OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean);
public static void applyFilterSystemQuery(final FilterOption filterOption, final EntityCollection entitySet,
- final EdmBindingTarget edmEntitySet) throws ODataApplicationException {
+ final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {
if (filterOption == null) {
return;
@@ -57,16 +53,17 @@ public class FilterHandler {
while (iter.hasNext()) {
final VisitorOperand operand = filterOption.getExpression()
- .accept(new ExpressionVisitorImpl(iter.next(), edmEntitySet));
+ .accept(new ExpressionVisitorImpl(iter.next(), uriInfo, edm));
final TypedOperand typedOperand = operand.asTypedOperand();
-
- if(typedOperand.is(primBoolean)) {
- if(Boolean.FALSE.equals(typedOperand.getTypedValue(Boolean.class))) {
+
+ if (typedOperand.is(primBoolean)) {
+ if (Boolean.FALSE.equals(typedOperand.getTypedValue(Boolean.class))) {
iter.remove();
}
} else {
- throw new ODataApplicationException("Invalid filter expression. Filter expressions must return a value of "
- + "type Edm.Boolean", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
+ throw new ODataApplicationException(
+ "Invalid filter expression. Filter expressions must return a value of type Edm.Boolean",
+ HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/23fb86a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/OrderByHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/OrderByHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/OrderByHandler.java
index ce472ba..ad1d2d5 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/OrderByHandler.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/OrderByHandler.java
@@ -24,9 +24,10 @@ import java.util.Locale;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.uri.UriInfoResource;
import org.apache.olingo.server.api.uri.queryoption.OrderByItem;
import org.apache.olingo.server.api.uri.queryoption.OrderByOption;
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
@@ -35,43 +36,43 @@ import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand
public class OrderByHandler {
public static void applyOrderByOption(final OrderByOption orderByOption, final EntityCollection entitySet,
- final EdmBindingTarget edmBindingTarget) throws ODataApplicationException {
+ final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {
if (orderByOption == null) {
return;
}
try {
- applyOrderByOptionInternal(orderByOption, entitySet, edmBindingTarget);
+ applyOrderByOptionInternal(orderByOption, entitySet, uriInfo, edm);
} catch (SystemQueryOptionsRuntimeException e) {
if (e.getCause() instanceof ODataApplicationException) {
// Throw the nested exception, to send the correct HTTP status code in the HTTP response
throw (ODataApplicationException) e.getCause();
} else {
- throw new ODataApplicationException("Exception in orderBy evaluation", HttpStatusCode.INTERNAL_SERVER_ERROR
- .getStatusCode(), Locale.ROOT);
+ throw new ODataApplicationException("Exception in orderBy evaluation",
+ HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
}
}
private static void applyOrderByOptionInternal(final OrderByOption orderByOption, final EntityCollection entitySet,
- final EdmBindingTarget edmBindingTarget) throws ODataApplicationException {
+ final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {
Collections.sort(entitySet.getEntities(), new Comparator<Entity>() {
@Override
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings("unchecked")
public int compare(final Entity e1, final Entity e2) {
- // Evaluate the first order option for both entity
- // If and only if the result of the previous order option is equals to 0
- // evaluate the next order option until all options are evaluated or they are not equals
+ // Evaluate the first order option for both entities.
+ // If and only if the result of the previous order option is equal to 0
+ // evaluate the next order option until all options are evaluated or they are not equal.
int result = 0;
for (int i = 0; i < orderByOption.getOrders().size() && result == 0; i++) {
try {
final OrderByItem item = orderByOption.getOrders().get(i);
final TypedOperand op1 =
- item.getExpression().accept(new ExpressionVisitorImpl(e1, edmBindingTarget)).asTypedOperand();
+ item.getExpression().accept(new ExpressionVisitorImpl(e1, uriInfo, edm)).asTypedOperand();
final TypedOperand op2 =
- item.getExpression().accept(new ExpressionVisitorImpl(e2, edmBindingTarget)).asTypedOperand();
+ item.getExpression().accept(new ExpressionVisitorImpl(e2, uriInfo, edm)).asTypedOperand();
if (op1.isNull() || op2.isNull()) {
if (op1.isNull() && op2.isNull()) {
@@ -84,7 +85,7 @@ public class OrderByHandler {
Object o2 = op2.getValue();
if (o1.getClass() == o2.getClass() && o1 instanceof Comparable) {
- result = ((Comparable) o1).compareTo(o2);
+ result = ((Comparable<Object>) o1).compareTo(o2);
} else {
result = 0;
}