You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/04/04 07:51:04 UTC

[10/21] git commit: [OLINGO-206] function/action validation

[OLINGO-206] function/action validation


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

Branch: refs/heads/master
Commit: 3321708293818683551ce429f1b657322671e171
Parents: 8c0c670
Author: Stephan Klevenz <st...@sap.com>
Authored: Mon Mar 24 17:10:10 2014 +0100
Committer: Stephan Klevenz <st...@sap.com>
Committed: Mon Mar 24 17:11:56 2014 +0100

----------------------------------------------------------------------
 .../uri/validator/SystemQueryValidator.java     | 84 ++++++++++++--------
 .../core/uri/validator/UriEdmValidatorTest.java | 46 ++++++++---
 2 files changed, 82 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/33217082/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/SystemQueryValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/SystemQueryValidator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/SystemQueryValidator.java
index de440a5..d752a09 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/SystemQueryValidator.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/SystemQueryValidator.java
@@ -20,12 +20,13 @@ package org.apache.olingo.server.core.uri.validator;
 
 import org.apache.olingo.commons.api.ODataRuntimeException;
 import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
 import org.apache.olingo.server.api.uri.UriInfo;
 import org.apache.olingo.server.api.uri.UriResource;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
 import org.apache.olingo.server.api.uri.UriResourcePartTyped;
 import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
 import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
@@ -171,7 +172,27 @@ public class SystemQueryValidator {
       }
     }
       break;
-    case action:
+    case action: {
+      UriResourceAction ura = (UriResourceAction) lastPathSegment;
+      EdmReturnType rt = ura.getAction().getReturnType();
+      switch (rt.getType().getKind()) {
+      case ENTITY:
+        if (((EdmEntityType) rt.getType()).hasStream()) {
+          idx=10;
+        } else {
+          idx = rt.isCollection() ? 7 : 9;
+        }
+        break;
+      case PRIMITIVE:
+        idx = rt.isCollection() ? 17 : 16;
+        break;
+      case COMPLEX:
+        idx = rt.isCollection() ? 14 : 13;
+        break;
+      default:
+        throw new UriValidationException("Unsupported function return type: " + rt.getType().getKind());
+      }
+    }
       break;
     case complexProperty:
       if (lastPathSegment instanceof UriResourcePartTyped) {
@@ -197,52 +218,45 @@ public class SystemQueryValidator {
             + lastPathSegment.getClass());
       }
       break;
-    case function:
-      break;
-    case it:
-      break;
-    case lambdaAll:
-      break;
-    case lambdaAny:
-      break;
-    case lambdaVariable:
-      break;
-    case navigationProperty: {
-      int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
-      UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
-
-      EdmEntitySet entitySet = edm.getEntityContainer(null).getEntitySet(secondLastPathSegment.toString());
-      EdmNavigationProperty navProp = entitySet.getEntityType().getNavigationProperty(lastPathSegment.toString());
-      if (navProp.isCollection()) {
-        idx = 7;
-      } else {
-        idx = 9;
+    case function: {
+      UriResourceFunction urf = (UriResourceFunction) lastPathSegment;
+      EdmReturnType rt = urf.getFunction().getReturnType();
+      switch (rt.getType().getKind()) {
+      case ENTITY:
+        if (((EdmEntityType) rt.getType()).hasStream()) {
+          idx=10;
+        } else {
+          idx = rt.isCollection() ? 7 : 9;
+        }
+        break;
+      case PRIMITIVE:
+        idx = rt.isCollection() ? 17 : 16;
+        break;
+      case COMPLEX:
+        idx = rt.isCollection() ? 14 : 13;
+        break;
+      default:
+        throw new UriValidationException("Unsupported function return type: " + rt.getType().getKind());
       }
     }
       break;
+    case navigationProperty:
+      idx = ((UriResourceNavigation) lastPathSegment).isCollection() ? 7 : 9;
+      break;
     case primitiveProperty:
       if (lastPathSegment instanceof UriResourcePartTyped) {
-        if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
-          idx = 17;
-        } else {
-          idx = 16;
-        }
+        idx = ((UriResourcePartTyped) lastPathSegment).isCollection() ? 17 : 16;
       } else {
         throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
             + lastPathSegment.getClass());
       }
-
       break;
     case ref: {
       int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
       UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
 
       if (secondLastPathSegment instanceof UriResourcePartTyped) {
-        if (((UriResourcePartTyped) secondLastPathSegment).isCollection()) {
-          idx = 11;
-        } else {
-          idx = 12;
-        }
+        idx = ((UriResourcePartTyped) secondLastPathSegment).isCollection() ? 11 : 12;
       } else {
         throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
             + lastPathSegment.getClass());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/33217082/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
index 4e7d402..d35105a 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
@@ -135,6 +135,22 @@ public class UriEdmValidatorTest {
       { URI_NAV_ENTITY_SET, QO_COUNT }, /* { URI_NAV_ENTITY_SET, QO_ORDERBY }, */
       /* { URI_NAV_ENTITY_SET, QO_SEARCH }, */{ URI_NAV_ENTITY_SET, QO_SELECT }, { URI_NAV_ENTITY_SET, QO_SKIP },
       { URI_NAV_ENTITY_SET, QO_SKIPTOKEN }, { URI_NAV_ENTITY_SET, QO_LEVELS }, { URI_NAV_ENTITY_SET, QO_TOP },
+
+      { "FINRTInt16()" },
+      { "FICRTETKeyNav()" },
+      { "FICRTESTwoKeyNavParam(ParameterInt16=1)" },
+      { "FICRTCollString()" },
+      { "FICRTCTTwoPrim()" },
+      { "FICRTCollCTTwoPrim()" },
+      { "FICRTETMedia()" },
+      
+      { "ESTwoKeyNav/com.sap.odata.test1.BAESTwoKeyNavRTESTwoKeyNav" },
+      { "ESAllPrim/com.sap.odata.test1.BAESAllPrimRTETAllPrim" },
+      { "AIRTPrimCollParam" },
+      { "AIRTETParam" },
+      { "AIRTPrimParam" },
+
+      
   };
 
   private String[][] urisWithNonValidSystemQueryOptions = {
@@ -231,9 +247,8 @@ public class UriEdmValidatorTest {
       { URI_NAV_ENTITY, QO_FILTER }, { URI_NAV_ENTITY, QO_ID }, { URI_NAV_ENTITY, QO_COUNT },
       /* { URI_NAV_ENTITY, QO_ORDERBY }, *//* { URI_NAV_ENTITY, QO_SEARCH }, */{ URI_NAV_ENTITY, QO_SKIP },
       { URI_NAV_ENTITY, QO_SKIPTOKEN }, { URI_SINGLETON, QO_TOP },
-      
-      { URI_NAV_ENTITY_SET, QO_ID },
 
+      { URI_NAV_ENTITY_SET, QO_ID },
 
   };
   private Parser parser;
@@ -243,17 +258,22 @@ public class UriEdmValidatorTest {
     parser = new Parser();
   }
 
-  @Test
-//  @Ignore
-      public
-      void bla() throws Exception {
-    String[][] m = { { URI_NAV_ENTITY_SET, QO_SELECT } };
-    String[] uris = constructUri(m);
-    System.out.println(uris[0]);
-
-    parseAndValidate(uris[0]);
-  }
-
+//  @Test
+////  @Ignore
+//      public
+//      void bla() throws Exception {
+//    String[][] m = {
+//        { "" },
+//        { "" },
+//    };
+//    String[] uris = constructUri(m);
+//    for (String uri : uris) {
+//      System.out.println(uri);
+//
+//      parseAndValidate(uri);
+//    }
+//  }
+//
   @Test
   public void checkValidSystemQueryOption() throws Exception {
     String[] uris = constructUri(urisWithValidSystemQueryOptions);