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:32 UTC

[15/55] [abbrv] olingo-odata4 git commit: [OLINGO-713] $filter Tutorial - some minor refactorings

[OLINGO-713] $filter Tutorial - some minor refactorings


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/5a43ca9d
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/5a43ca9d
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/5a43ca9d

Branch: refs/heads/OLINGO-562_SpringExtension
Commit: 5a43ca9d1612459dee2fdb4eda14c238f12d9860
Parents: 71857f9
Author: Christian Holzer <c....@sap.com>
Authored: Thu Aug 27 15:48:53 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Thu Aug 27 15:48:53 2015 +0200

----------------------------------------------------------------------
 .../service/FilterExpressionVisitor.java        | 25 +++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5a43ca9d/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java b/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
index 5a9af92..615c384 100644
--- a/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
+++ b/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
@@ -58,8 +58,14 @@ public class FilterExpressionVisitor implements ExpressionVisitor<Object> {
     if(uriResourceParts.size() == 1 && uriResourceParts.get(0) instanceof UriResourcePrimitiveProperty) {
       UriResourcePrimitiveProperty uriResourceProperty = (UriResourcePrimitiveProperty) uriResourceParts.get(0);
       return currentEntity.getProperty(uriResourceProperty.getProperty().getName()).getValue();
-      
     } else {
+      // The OData specification allows in addition complex properties and navigation properties 
+      // with a target cardinality 0..1 or 1.
+      // This means any combination can occur e.g. Supplier/Address/City
+      //  -> Navigation properties  Supplier 
+      //  -> Complex Property       Address
+      //  -> Primitive Property     City
+      // For such cases the resource path returns a list of UriResourceParts
       throw new ODataApplicationException("Only primitive properties are implemented in filter expressions", 
           HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
     }
@@ -164,16 +170,23 @@ public class FilterExpressionVisitor implements ExpressionVisitor<Object> {
 	  }
 	}
 
-  @SuppressWarnings("unchecked")
   private Object evaluateComparisonOperation(BinaryOperatorKind operator, Object left, Object right) 
       throws ODataApplicationException {
     
     // All types in our tutorial supports all logical operations, but we have to make sure that the types are equals
-    if(left.getClass().equals(right.getClass())) {
+    if(left.getClass().equals(right.getClass()) && left instanceof Comparable) {
       // Luckily all used types String, Boolean and also Integer support the interface Comparable
-      // TODO: Is this OK? Otherwise we can infer generic arguments after using an if statement
-      @SuppressWarnings("rawtypes")
-      int result = ((Comparable) left).compareTo(right);
+      int result;
+      if(left instanceof Integer) {
+        result = ((Comparable<Integer>) (Integer)left).compareTo((Integer) right);
+      } else if(left instanceof String) {
+        result = ((Comparable<String>) (String)left).compareTo((String) right);
+      } else if(left instanceof Boolean) {
+        result = ((Comparable<Boolean>) (Boolean)left).compareTo((Boolean) right);
+      } else {
+        throw new ODataApplicationException("Class " + left.getClass().getCanonicalName() + " not expected", 
+            HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ENGLISH);
+      }
       
       if (operator == BinaryOperatorKind.EQ) {
         return result == 0;