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/03/25 10:24:59 UTC

[1/2] git commit: [OLINGO-206] function/action validation

Repository: olingo-odata4
Updated Branches:
  refs/heads/olingo-206-validator 8c0c670e4 -> 3bfc3893f


[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/olingo-206-validator
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);


[2/2] git commit: [OLINGO-206] re-factor validator

Posted by sk...@apache.org.
[OLINGO-206] re-factor validator


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

Branch: refs/heads/olingo-206-validator
Commit: 3bfc3893f04e932fb092b55e87b4ab12d9023571
Parents: 3321708
Author: Stephan Klevenz <st...@sap.com>
Authored: Tue Mar 25 10:23:53 2014 +0100
Committer: Stephan Klevenz <st...@sap.com>
Committed: Tue Mar 25 10:24:28 2014 +0100

----------------------------------------------------------------------
 .../uri/validator/SystemQueryValidator.java     | 315 --------------
 .../server/core/uri/validator/UriValidator.java | 423 +++++++++++++++++++
 .../core/uri/validator/UriEdmValidatorTest.java |  14 +-
 3 files changed, 429 insertions(+), 323 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3bfc3893/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
deleted file mode 100644
index d752a09..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/SystemQueryValidator.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-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.EdmEntityType;
-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;
-
-public class SystemQueryValidator {
-
-  //@formatter:off (Eclipse formatter)
-  //CHECKSTYLE:OFF (Maven checkstyle)
-  private boolean[][] decisionMatrix =
-      {
-          /*                                          0-FILTER 1-FORMAT 2-EXPAND 3-ID     4-COUNT  5-ORDERBY 6-SEARCH 7-SELECT 8-SKIP   9-SKIPTOKEN 10-LEVELS 11-TOP */
-          /*                              all  0 */ { true ,   true ,   true ,   false,   true ,   true ,    true ,   true ,   true ,   true ,      true ,    false },
-          /*                            batch  1 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                        crossjoin  2 */ { true ,   true ,   true ,   false,   true ,   true ,    true ,   true ,   true ,   true ,      true ,    true  },
-          /*                         entityId  3 */ { false,   true ,   true ,   true ,   false,   false,    false,   true ,   false,   false,      true ,    false },
-          /*                         metadata  4 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                         resource  5 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                          service  6 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                        entitySet  7 */ { true ,   true ,   true ,   false,   true ,   true ,    true ,   true ,   true ,   true ,      true ,    true  },
-          /*                   entitySetCount  8 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                           entity  9 */ { false,   true ,   true ,   false,   false,   false,    false,   true ,   false,   false,      true ,    false },
-          /*                      mediaStream 10 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                       references 11 */ { true ,   true ,   false,   false,   false,   true ,    true ,   false,   true ,   true ,      false,    true  },
-          /*                        reference 12 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                  propertyComplex 13 */ { false,   true ,   true ,   false,   false,   false,    false,   true ,   false,   false,      true ,    false },
-          /*        propertyComplexCollection 14 */ { true ,   true ,   true ,   false,   true ,   true ,    false,   false,   true ,   true ,      true ,    true  },
-          /*   propertyComplexCollectionCount 15 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*                propertyPrimitive 16 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*      propertyPrimitiveCollection 17 */ { true ,   true ,   false,   false,   false,   true ,    false,   false,   true ,   true ,      false,    true  },
-          /* propertyPrimitiveCollectionCount 18 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
-          /*           propertyPrimitiveValue 19 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },                    
-      };
-  //CHECKSTYLE:ON
-  //@formatter:on
-
-  public void validate(final UriInfo uriInfo, final Edm edm) throws UriValidationException {
-
-    validateQueryOptions(uriInfo, edm);
-    validateKeyPredicateTypes(uriInfo, edm);
-
-  }
-
-  private int colIndex(SystemQueryOptionKind queryOptionKind) {
-    int idx;
-    switch (queryOptionKind) {
-    case FILTER:
-      idx = 0;
-      break;
-    case FORMAT:
-      idx = 1;
-      break;
-    case EXPAND:
-      idx = 2;
-      break;
-    case ID:
-      idx = 3;
-      break;
-    case COUNT:
-      idx = 4;
-      break;
-    case ORDERBY:
-      idx = 5;
-      break;
-    case SEARCH:
-      idx = 6;
-      break;
-    case SELECT:
-      idx = 7;
-      break;
-    case SKIP:
-      idx = 8;
-      break;
-    case SKIPTOKEN:
-      idx = 9;
-      break;
-    case LEVELS:
-      idx = 10;
-      break;
-    case TOP:
-      idx = 11;
-      break;
-    default:
-      throw new ODataRuntimeException("Unsupported option: " + queryOptionKind);
-    }
-
-    return idx;
-  }
-
-  private int rowIndex(final UriInfo uriInfo, Edm edm) throws UriValidationException {
-    int idx;
-
-    switch (uriInfo.getKind()) {
-    case all:
-      idx = 0;
-      break;
-    case batch:
-      idx = 1;
-      break;
-    case crossjoin:
-      idx = 2;
-      break;
-    case entityId:
-      idx = 3;
-      break;
-    case metadata:
-      idx = 4;
-      break;
-    case resource:
-      idx = rowIndexForResourceKind(uriInfo, edm);
-      break;
-    case service:
-      idx = 6;
-      break;
-    default:
-      throw new ODataRuntimeException("Unsupported uriInfo kind: " + uriInfo.getKind());
-    }
-
-    return idx;
-  }
-
-  private int rowIndexForResourceKind(UriInfo uriInfo, Edm edm) throws UriValidationException {
-    int idx = 5;
-
-    int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
-    UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
-
-    switch (lastPathSegment.getKind()) {
-    case count: {
-      int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
-      UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
-      switch (secondLastPathSegment.getKind()) {
-      case entitySet:
-        idx = 8;
-        break;
-      case complexProperty:
-        idx = 15;
-        break;
-      case primitiveProperty:
-        idx = 18;
-        break;
-      default:
-        throw new UriValidationException("Illegal path part kind: " + lastPathSegment.getKind());
-      }
-    }
-      break;
-    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) {
-        if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
-          idx = 14;
-        } else {
-          idx = 13;
-        }
-      } else {
-        throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
-            + lastPathSegment.getClass());
-      }
-      break;
-    case entitySet:
-      if (lastPathSegment instanceof UriResourcePartTyped) {
-        if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
-          idx = 7;
-        } else {
-          idx = 9;
-        }
-      } else {
-        throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
-            + lastPathSegment.getClass());
-      }
-      break;
-    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) {
-        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) {
-        idx = ((UriResourcePartTyped) secondLastPathSegment).isCollection() ? 11 : 12;
-      } else {
-        throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
-            + lastPathSegment.getClass());
-      }
-    }
-      break;
-    case root:
-      break;
-    case singleton:
-      idx = 9;
-      break;
-    case value: {
-      int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
-      UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
-      switch (secondLastPathSegment.getKind()) {
-      case primitiveProperty:
-        idx = 19;
-        break;
-      case entitySet:
-        idx = 10;
-        break;
-      default:
-        throw new UriValidationException("Unexpected kind in path segment before $value: "
-            + secondLastPathSegment.getKind());
-      }
-    }
-      break;
-    default:
-      throw new ODataRuntimeException("Unsupported uriResource kind: " + lastPathSegment.getKind());
-    }
-
-    return idx;
-  }
-
-  private void validateQueryOptions(final UriInfo uriInfo, Edm edm) throws UriValidationException {
-    try {
-      int row = rowIndex(uriInfo, edm);
-
-      for (SystemQueryOption option : uriInfo.getSystemQueryOptions()) {
-        int col = colIndex(option.getKind());
-
-        System.out.print("[" + row + "][" + col + "]");
-
-        if (!decisionMatrix[row][col]) {
-          throw new UriValidationException("System query option not allowed: " + option.getName());
-        }
-      }
-    } finally {
-      System.out.println();
-    }
-
-  }
-
-  private void validateKeyPredicateTypes(final UriInfo uriInfo, final Edm edm) throws UriValidationException {}
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3bfc3893/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
new file mode 100644
index 0000000..f5b785b
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
@@ -0,0 +1,423 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+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.EdmEntityType;
+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;
+
+public class UriValidator {
+
+  //@formatter:off (Eclipse formatter)
+  //CHECKSTYLE:OFF (Maven checkstyle)
+  private boolean[][] decisionMatrix =
+      {
+          /*                                          0-FILTER 1-FORMAT 2-EXPAND 3-ID     4-COUNT  5-ORDERBY 6-SEARCH 7-SELECT 8-SKIP   9-SKIPTOKEN 10-LEVELS 11-TOP */
+          /*                              all  0 */ { true ,   true ,   true ,   false,   true ,   true ,    true ,   true ,   true ,   true ,      true ,    false },
+          /*                            batch  1 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                        crossjoin  2 */ { true ,   true ,   true ,   false,   true ,   true ,    true ,   true ,   true ,   true ,      true ,    true  },
+          /*                         entityId  3 */ { false,   true ,   true ,   true ,   false,   false,    false,   true ,   false,   false,      true ,    false },
+          /*                         metadata  4 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                         resource  5 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                          service  6 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                        entitySet  7 */ { true ,   true ,   true ,   false,   true ,   true ,    true ,   true ,   true ,   true ,      true ,    true  },
+          /*                   entitySetCount  8 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                           entity  9 */ { false,   true ,   true ,   false,   false,   false,    false,   true ,   false,   false,      true ,    false },
+          /*                      mediaStream 10 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                       references 11 */ { true ,   true ,   false,   false,   false,   true ,    true ,   false,   true ,   true ,      false,    true  },
+          /*                        reference 12 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                  propertyComplex 13 */ { false,   true ,   true ,   false,   false,   false,    false,   true ,   false,   false,      true ,    false },
+          /*        propertyComplexCollection 14 */ { true ,   true ,   true ,   false,   true ,   true ,    false,   false,   true ,   true ,      true ,    true  },
+          /*   propertyComplexCollectionCount 15 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*                propertyPrimitive 16 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*      propertyPrimitiveCollection 17 */ { true ,   true ,   false,   false,   false,   true ,    false,   false,   true ,   true ,      false,    true  },
+          /* propertyPrimitiveCollectionCount 18 */ { false,   false,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },
+          /*           propertyPrimitiveValue 19 */ { false,   true ,   false,   false,   false,   false,    false,   false,   false,   false,      false,    false },                    
+      };
+  //CHECKSTYLE:ON
+  //@formatter:on
+
+  private enum RowIndex {
+    all(0),
+    batch(1),
+    crossjoin(2),
+    entityId(3),
+    metadata(4),
+    resource(5),
+    service(6),
+    entitySet(7),
+    entitySetCount(8),
+    entity(9),
+    mediaStream(10),
+    references(11),
+    reference(12),
+    propertyComplex(13),
+    propertyComplexCollection(14),
+    propertyComplexCollectionCount(15),
+    propertyPrimitive(16),
+    propertyPrimitiveCollection(17),
+    propertyPrimitiveCollectionCount(18),
+    propertyPrimitiveValue(19);
+
+    private int idx;
+
+    RowIndex(int i) {
+      idx = i;
+    }
+
+    public int getIndex() {
+      return idx;
+    }
+  }
+
+  private enum ColumnIndex {
+    filter(0),
+    format(1),
+    expand(2),
+    id(3),
+    count(4),
+    orderby(5),
+    search(6),
+    select(7),
+    skip(8),
+    skiptoken(9),
+    levels(10),
+    top(11);
+
+    private int idx;
+
+    ColumnIndex(int i) {
+      idx = i;
+    }
+
+    public int getIndex() {
+      return idx;
+    }
+
+  }
+
+  public void validate(final UriInfo uriInfo, final Edm edm) throws UriValidationException {
+
+    validateQueryOptions(uriInfo, edm);
+    validateKeyPredicateTypes(uriInfo, edm);
+
+  }
+
+  private ColumnIndex colIndex(SystemQueryOptionKind queryOptionKind) {
+    ColumnIndex idx;
+    switch (queryOptionKind) {
+    case FILTER:
+      idx = ColumnIndex.filter;
+      break;
+    case FORMAT:
+      idx = ColumnIndex.format;
+      break;
+    case EXPAND:
+      idx = ColumnIndex.expand;
+      break;
+    case ID:
+      idx = ColumnIndex.id;
+      break;
+    case COUNT:
+      idx = ColumnIndex.count;
+      break;
+    case ORDERBY:
+      idx = ColumnIndex.orderby;
+      break;
+    case SEARCH:
+      idx = ColumnIndex.search;
+      break;
+    case SELECT:
+      idx = ColumnIndex.select;
+      break;
+    case SKIP:
+      idx = ColumnIndex.skip;
+      break;
+    case SKIPTOKEN:
+      idx = ColumnIndex.skiptoken;
+      break;
+    case LEVELS:
+      idx = ColumnIndex.levels;
+      break;
+    case TOP:
+      idx = ColumnIndex.top;
+      break;
+    default:
+      throw new ODataRuntimeException("Unsupported option: " + queryOptionKind);
+    }
+
+    return idx;
+  }
+
+  private RowIndex rowIndex(final UriInfo uriInfo, Edm edm) throws UriValidationException {
+    RowIndex idx;
+
+    switch (uriInfo.getKind()) {
+    case all:
+      idx = RowIndex.all;
+      break;
+    case batch:
+      idx = RowIndex.batch;
+      break;
+    case crossjoin:
+      idx = RowIndex.crossjoin;
+      break;
+    case entityId:
+      idx = RowIndex.entityId;
+      break;
+    case metadata:
+      idx = RowIndex.metadata;
+      break;
+    case resource:
+      idx = rowIndexForResourceKind(uriInfo, edm);
+      break;
+    case service:
+      idx = RowIndex.service;
+      break;
+    default:
+      throw new ODataRuntimeException("Unsupported uriInfo kind: " + uriInfo.getKind());
+    }
+
+    return idx;
+  }
+
+  private RowIndex rowIndexForResourceKind(UriInfo uriInfo, Edm edm) throws UriValidationException {
+    RowIndex idx;
+
+    int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
+    UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
+
+    switch (lastPathSegment.getKind()) {
+    case count:
+      idx = rowIndexForCount(uriInfo, lastPathSegment);
+      break;
+    case action:
+      idx = rowIndexForAction(lastPathSegment);
+      break;
+    case complexProperty:
+      idx = rowIndexForComplexProperty(lastPathSegment);
+      break;
+    case entitySet:
+      idx = rowIndexForEntitySet(lastPathSegment);
+      break;
+    case function:
+      idx = rowIndexForFunction(lastPathSegment);
+      break;
+    case navigationProperty:
+      idx = ((UriResourceNavigation) lastPathSegment).isCollection() ? RowIndex.entitySet : RowIndex.entity;
+      break;
+    case primitiveProperty:
+      idx = rowIndexForPrimitiveProperty(lastPathSegment);
+      break;
+    case ref:
+      idx = rowIndexForRef(uriInfo, lastPathSegment);
+      break;
+    case root:
+      idx = RowIndex.service;
+      break;
+    case singleton:
+      idx = RowIndex.entity;
+      break;
+    case value:
+      idx = rowIndexForValue(uriInfo);
+      break;
+    default:
+      throw new ODataRuntimeException("Unsupported uriResource kind: " + lastPathSegment.getKind());
+    }
+
+    return idx;
+  }
+
+  private RowIndex rowIndexForValue(UriInfo uriInfo) throws UriValidationException {
+    RowIndex idx;
+    int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
+    UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
+    switch (secondLastPathSegment.getKind()) {
+    case primitiveProperty:
+      idx = RowIndex.propertyPrimitiveValue;
+      break;
+    case entitySet:
+      idx = RowIndex.mediaStream;
+      break;
+    default:
+      throw new UriValidationException("Unexpected kind in path segment before $value: "
+          + secondLastPathSegment.getKind());
+
+    }
+    return idx;
+  }
+
+  private RowIndex rowIndexForRef(UriInfo uriInfo, UriResource lastPathSegment)
+      throws UriValidationException {
+    RowIndex idx;
+    int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
+    UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
+
+    if (secondLastPathSegment instanceof UriResourcePartTyped) {
+      idx = ((UriResourcePartTyped) secondLastPathSegment).isCollection() ? RowIndex.references : RowIndex.reference;
+    } else {
+      throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
+          + lastPathSegment.getClass());
+    }
+
+    return idx;
+  }
+
+  private RowIndex rowIndexForPrimitiveProperty(UriResource lastPathSegment)
+      throws UriValidationException {
+    RowIndex idx;
+    if (lastPathSegment instanceof UriResourcePartTyped) {
+      idx =
+          ((UriResourcePartTyped) lastPathSegment).isCollection() ? RowIndex.propertyPrimitiveCollection
+              : RowIndex.propertyPrimitive;
+    } else {
+      throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+          + lastPathSegment.getClass());
+    }
+    return idx;
+  }
+
+  private RowIndex rowIndexForFunction(UriResource lastPathSegment) throws UriValidationException {
+    RowIndex idx;
+    UriResourceFunction urf = (UriResourceFunction) lastPathSegment;
+    EdmReturnType rt = urf.getFunction().getReturnType();
+    switch (rt.getType().getKind()) {
+    case ENTITY:
+      if (((EdmEntityType) rt.getType()).hasStream()) {
+        idx = RowIndex.mediaStream;
+      } else {
+        idx = rt.isCollection() ? RowIndex.entitySet : RowIndex.entity;
+      }
+      break;
+    case PRIMITIVE:
+      idx = rt.isCollection() ? RowIndex.propertyPrimitiveCollection : RowIndex.propertyPrimitive;
+      break;
+    case COMPLEX:
+      idx = rt.isCollection() ? RowIndex.propertyComplexCollection : RowIndex.propertyComplex;
+      break;
+    default:
+      throw new UriValidationException("Unsupported function return type: " + rt.getType().getKind());
+    }
+
+    return idx;
+  }
+
+  private RowIndex rowIndexForEntitySet(UriResource lastPathSegment) throws UriValidationException {
+    RowIndex idx;
+    if (lastPathSegment instanceof UriResourcePartTyped) {
+      idx = ((UriResourcePartTyped) lastPathSegment).isCollection() ? RowIndex.entitySet : RowIndex.entity;
+    } else {
+      throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+          + lastPathSegment.getClass());
+    }
+    return idx;
+  }
+
+  private RowIndex rowIndexForComplexProperty(UriResource lastPathSegment) throws UriValidationException {
+    RowIndex idx;
+    if (lastPathSegment instanceof UriResourcePartTyped) {
+      idx =
+          ((UriResourcePartTyped) lastPathSegment).isCollection() ? RowIndex.propertyComplexCollection
+              : RowIndex.propertyComplex;
+    } else {
+      throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+          + lastPathSegment.getClass());
+    }
+    return idx;
+  }
+
+  private RowIndex rowIndexForAction(UriResource lastPathSegment) throws UriValidationException {
+    RowIndex idx;
+    UriResourceAction ura = (UriResourceAction) lastPathSegment;
+    EdmReturnType rt = ura.getAction().getReturnType();
+    switch (rt.getType().getKind()) {
+    case ENTITY:
+      if (((EdmEntityType) rt.getType()).hasStream()) {
+        idx = RowIndex.mediaStream;
+      } else {
+        idx = rt.isCollection() ? RowIndex.entitySet : RowIndex.entity;
+      }
+      break;
+    case PRIMITIVE:
+      idx = rt.isCollection() ? RowIndex.propertyPrimitiveCollection : RowIndex.propertyPrimitive;
+      break;
+    case COMPLEX:
+      idx = rt.isCollection() ? RowIndex.propertyComplexCollection : RowIndex.propertyComplex;
+      break;
+    default:
+      throw new UriValidationException("Unsupported action return type: " + rt.getType().getKind());
+    }
+
+    return idx;
+  }
+
+  private RowIndex rowIndexForCount(UriInfo uriInfo, UriResource lastPathSegment)
+      throws UriValidationException {
+
+    RowIndex idx;
+    int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
+    UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
+    switch (secondLastPathSegment.getKind()) {
+    case entitySet:
+      idx = RowIndex.entitySetCount;
+      break;
+    case complexProperty:
+      idx = RowIndex.propertyComplexCollectionCount;
+      break;
+    case primitiveProperty:
+      idx = RowIndex.propertyPrimitiveCollectionCount;
+      break;
+    default:
+      throw new UriValidationException("Illegal path part kind: " + lastPathSegment.getKind());
+    }
+
+    return idx;
+  }
+
+  private void validateQueryOptions(final UriInfo uriInfo, Edm edm) throws UriValidationException {
+    try {
+      RowIndex row = rowIndex(uriInfo, edm);
+
+      for (SystemQueryOption option : uriInfo.getSystemQueryOptions()) {
+        ColumnIndex col = colIndex(option.getKind());
+
+        System.out.print("[" + row + "][" + col + "]");
+
+        if (!decisionMatrix[row.getIndex()][col.getIndex()]) {
+          throw new UriValidationException("System query option not allowed: " + option.getName());
+        }
+      }
+    } finally {
+      System.out.println();
+    }
+
+  }
+
+  private void validateKeyPredicateTypes(final UriInfo uriInfo, final Edm edm) throws UriValidationException {}
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3bfc3893/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 d35105a..9ec844c 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
@@ -30,7 +30,6 @@ import org.apache.olingo.server.core.testutil.EdmTechProvider;
 import org.apache.olingo.server.core.uri.parser.Parser;
 import org.apache.olingo.server.core.uri.parser.UriParserException;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class UriEdmValidatorTest {
@@ -143,14 +142,13 @@ public class UriEdmValidatorTest {
       { "FICRTCTTwoPrim()" },
       { "FICRTCollCTTwoPrim()" },
       { "FICRTETMedia()" },
-      
+
       { "ESTwoKeyNav/com.sap.odata.test1.BAESTwoKeyNavRTESTwoKeyNav" },
       { "ESAllPrim/com.sap.odata.test1.BAESAllPrimRTETAllPrim" },
       { "AIRTPrimCollParam" },
       { "AIRTETParam" },
       { "AIRTPrimParam" },
 
-      
   };
 
   private String[][] urisWithNonValidSystemQueryOptions = {
@@ -251,6 +249,7 @@ public class UriEdmValidatorTest {
       { URI_NAV_ENTITY_SET, QO_ID },
 
   };
+  
   private Parser parser;
 
   @Before
@@ -259,12 +258,11 @@ public class UriEdmValidatorTest {
   }
 
 //  @Test
-////  @Ignore
+//  @Ignore
 //      public
 //      void bla() throws Exception {
 //    String[][] m = {
-//        { "" },
-//        { "" },
+//        { "/ESMedia(1)/$value?$filter='1' eq '1'" },
 //    };
 //    String[] uris = constructUri(m);
 //    for (String uri : uris) {
@@ -273,7 +271,7 @@ public class UriEdmValidatorTest {
 //      parseAndValidate(uri);
 //    }
 //  }
-//
+
   @Test
   public void checkValidSystemQueryOption() throws Exception {
     String[] uris = constructUri(urisWithValidSystemQueryOptions);
@@ -321,7 +319,7 @@ public class UriEdmValidatorTest {
 
   private void parseAndValidate(String uri) throws UriParserException, UriValidationException {
     UriInfo uriInfo = parser.parseUri(uri.trim(), edm);
-    SystemQueryValidator validator = new SystemQueryValidator();
+    UriValidator validator = new UriValidator();
 
     System.out.print("URI: " + uri);
     validator.validate(uriInfo, edm);