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/09/08 18:39:33 UTC
[16/55] [abbrv] olingo-odata4 git commit: [OLINGO-659] TecSvc:
$filter accepts only boolean expression,
all six comparison operators are defined for Edm.String,
Invalid types for binary operations are detected (No class cast exception any
more)
[OLINGO-659] TecSvc: $filter accepts only boolean expression, all six comparison operators are defined for Edm.String, Invalid types for binary operations are detected (No class cast exception any more)
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d414dfb0
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d414dfb0
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d414dfb0
Branch: refs/heads/OLINGO-562_SpringExtension
Commit: d414dfb037984eb0b1e7670952f5712cdd56a548
Parents: 5a43ca9
Author: Christian Holzer <c....@sap.com>
Authored: Thu Aug 27 15:52:15 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Thu Aug 27 15:52:15 2015 +0200
----------------------------------------------------------------------
.../tecsvc/client/FilterSystemQueryITCase.java | 61 ++++++++++++++++++--
.../expression/operand/TypedOperand.java | 6 +-
.../expression/operation/BinaryOperator.java | 6 +-
.../queryoptions/options/FilterHandler.java | 12 ++--
4 files changed, 73 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d414dfb0/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 3a25347..dfcfd50 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
@@ -63,7 +63,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase {
ClientEntity clientEntity = result.getBody().getEntities().get(0);
assertShortOrInt(32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
}
-
+
@Test
public void testBooleanLiteral() {
ODataRetrieveResponse<ClientEntitySet> response = sendRequest(ES_ALL_PRIM, "PropertyBoolean eq false");
@@ -975,12 +975,65 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase {
result = sendRequest("ESKeyNav", "PropertyCompCompNav/PropertyCompNav/PropertyInt16 eq null", cookie);
assertEquals(1, result.getBody().getEntities().size());
}
-
+
+ @Test
+ public void testFilterNotBooleanExpression() {
+ // Check that only boolean expression are allowed
+ fail("ESAllPrim", "PropertytString", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyInt16", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyInt32", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyInt64", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyDate", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyDuation", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyTimeOfDay", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyByte", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyDouble", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertySingle", HttpStatusCode.BAD_REQUEST);
+ }
+
+ @Test
+ public void testComparisonOnStringOperands() {
+ // If check if the expression is true => All entry are returned
+ ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "'Tes' lt 'Test'");
+ assertEquals(3, result.getBody().getEntities().size());
+
+ result = sendRequest(ES_ALL_PRIM, "'Test' le 'Test'");
+ assertEquals(3, result.getBody().getEntities().size());
+
+ result = sendRequest(ES_ALL_PRIM, "'Test1' le 'Test'");
+ assertEquals(0, result.getBody().getEntities().size());
+
+ result = sendRequest(ES_ALL_PRIM, "'Test1' gt 'Test'");
+ assertEquals(3, result.getBody().getEntities().size());
+
+ result = sendRequest(ES_ALL_PRIM, "'Tes' gt 'Test'");
+ assertEquals(0, result.getBody().getEntities().size());
+
+ result = sendRequest(ES_ALL_PRIM, "'Test' ge 'Test'");
+ assertEquals(3, result.getBody().getEntities().size());
+
+ result = sendRequest(ES_ALL_PRIM, "'Test' eq 'Test'");
+ assertEquals(3, result.getBody().getEntities().size());
+
+ result = sendRequest(ES_ALL_PRIM, "'Test1' ne 'Test'");
+ assertEquals(3, result.getBody().getEntities().size());
+ }
+
@Test
- public void testSringFunctionWithoutStringParameters() {
- fail("ESServerSidePaging", "filter=contains(PropertyInt16, 3) eq 'hallo'", HttpStatusCode.BAD_REQUEST);
+ public void testCastException() {
+ fail("ESAllPrim", "PropertyInt16 eq '1'", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyInt16 eq 03:26:05", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyInt16 eq true", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyInt16 eq 2012-12-03T07:16:23Z", HttpStatusCode.BAD_REQUEST);
+ fail("ESAllPrim", "PropertyInt16 eq duration'PT4S'", HttpStatusCode.BAD_REQUEST);
}
+
+ @Test
+ public void testStringFunctionWithoutStringParameters() {
+ fail("ESServerSidePaging", "contains(PropertyInt16, 3) eq 'hallo'", HttpStatusCode.BAD_REQUEST);
+ }
+
private ODataRetrieveResponse<ClientEntitySet> sendRequest(final String entitySet, final String filterString) {
return sendRequest(entitySet, filterString, null);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d414dfb0/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 4eed3db..9b18f46 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
@@ -75,7 +75,7 @@ public class TypedOperand extends VisitorOperand {
// Use type conversion of EdmPrimitive types
try {
final String literal = getLiteral(value);
- newValue = tryCast(literal, (EdmPrimitiveType) type);
+ newValue = tryCast(literal, (EdmPrimitiveType) asType);
} catch (EdmPrimitiveTypeException e) {
// Nothing to do
}
@@ -92,8 +92,8 @@ public class TypedOperand extends VisitorOperand {
public TypedOperand castToCommonType(final VisitorOperand otherOperand) throws ODataApplicationException {
final TypedOperand other = otherOperand.asTypedOperand();
final EdmType oType = other.getType();
-
- // Make sure that the EDM type is equals, check also the java type.
+
+ // 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
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d414dfb0/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 7465ab8..9ff1bc2 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,6 +168,7 @@ public class BinaryOperator {
return new TypedOperand(result, primBoolean);
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private boolean binaryComparison(final int... expect) {
int result;
@@ -179,10 +180,13 @@ 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 {
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/d414dfb0/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 eb809af..5f5c9df 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
@@ -59,10 +59,14 @@ public class FilterHandler {
final VisitorOperand operand = filterOption.getExpression()
.accept(new ExpressionVisitorImpl(iter.next(), edmEntitySet));
final TypedOperand typedOperand = operand.asTypedOperand();
-
- if (!(typedOperand.is(primBoolean)
- && Boolean.TRUE.equals(typedOperand.getTypedValue(Boolean.class)))) {
- iter.remove();
+
+ 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);
}
}