[OLINGO-206] nav prop 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/8c0c670e Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/8c0c670e Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/8c0c670e Branch: refs/heads/master Commit: 8c0c670e4f1674555537265a69006531f6b64aaa Parents: 1274b1e Author: Stephan Klevenz <[email protected]> Authored: Mon Mar 24 13:17:07 2014 +0100 Committer: Stephan Klevenz <[email protected]> Committed: Mon Mar 24 13:17:07 2014 +0100 ---------------------------------------------------------------------- .../uri/validator/SystemQueryValidator.java | 45 +++++++++++++------- .../core/uri/validator/UriEdmValidatorTest.java | 20 ++++++++- 2 files changed, 49 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8c0c670e/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 31604b2..de440a5 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,6 +20,10 @@ 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.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourcePartTyped; @@ -146,9 +150,9 @@ public class SystemQueryValidator { int idx = 5; int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1; - UriResource lastPathSegemnt = uriInfo.getUriResourceParts().get(lastPathSegmentIndex); + UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex); - switch (lastPathSegemnt.getKind()) { + switch (lastPathSegment.getKind()) { case count: { int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2; UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex); @@ -163,34 +167,34 @@ public class SystemQueryValidator { idx = 18; break; default: - throw new UriValidationException("Illegal path part kind: " + lastPathSegemnt.getKind()); + throw new UriValidationException("Illegal path part kind: " + lastPathSegment.getKind()); } } break; case action: break; case complexProperty: - if (lastPathSegemnt instanceof UriResourcePartTyped) { - if (((UriResourcePartTyped) lastPathSegemnt).isCollection()) { + if (lastPathSegment instanceof UriResourcePartTyped) { + if (((UriResourcePartTyped) lastPathSegment).isCollection()) { idx = 14; } else { idx = 13; } } else { throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: " - + lastPathSegemnt.getClass()); + + lastPathSegment.getClass()); } break; case entitySet: - if (lastPathSegemnt instanceof UriResourcePartTyped) { - if (((UriResourcePartTyped) lastPathSegemnt).isCollection()) { + if (lastPathSegment instanceof UriResourcePartTyped) { + if (((UriResourcePartTyped) lastPathSegment).isCollection()) { idx = 7; } else { idx = 9; } } else { throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: " - + lastPathSegemnt.getClass()); + + lastPathSegment.getClass()); } break; case function: @@ -203,18 +207,29 @@ public class SystemQueryValidator { break; case lambdaVariable: break; - case navigationProperty: + 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; + } + } break; case primitiveProperty: - if (lastPathSegemnt instanceof UriResourcePartTyped) { - if (((UriResourcePartTyped) lastPathSegemnt).isCollection()) { + if (lastPathSegment instanceof UriResourcePartTyped) { + if (((UriResourcePartTyped) lastPathSegment).isCollection()) { idx = 17; } else { idx = 16; } } else { throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: " - + lastPathSegemnt.getClass()); + + lastPathSegment.getClass()); } break; @@ -230,7 +245,7 @@ public class SystemQueryValidator { } } else { throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: " - + lastPathSegemnt.getClass()); + + lastPathSegment.getClass()); } } break; @@ -256,7 +271,7 @@ public class SystemQueryValidator { } break; default: - throw new ODataRuntimeException("Unsupported uriResource kind: " + lastPathSegemnt.getKind()); + throw new ODataRuntimeException("Unsupported uriResource kind: " + lastPathSegment.getKind()); } return idx; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8c0c670e/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 494f71b..4e7d402 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 @@ -58,6 +58,8 @@ public class UriEdmValidatorTest { "/ESCollAllPrim/CollPropertyString/$count"; private static final String URI_PROPERTY_PRIMITIVE_VALUE = "/ESAllPrim(1)/PropertyString/$value"; private static final String URI_SINGLETON = "/SI"; + private static final String URI_NAV_ENTITY = "/ESKeyNav/NavPropertyETKeyNavOne"; + private static final String URI_NAV_ENTITY_SET = "/ESKeyNav/NavPropertyETKeyNavMany"; private static final String QO_FILTER = "$filter='1' eq '1'"; private static final String QO_FORMAT = "$format=bla"; @@ -125,6 +127,14 @@ public class UriEdmValidatorTest { { URI_SINGLETON, QO_FORMAT }, { URI_SINGLETON, QO_EXPAND }, { URI_SINGLETON, QO_SELECT }, { URI_SINGLETON, QO_LEVELS }, + + { URI_NAV_ENTITY, QO_FORMAT }, { URI_NAV_ENTITY, QO_EXPAND }, { URI_NAV_ENTITY, QO_SELECT }, + { URI_NAV_ENTITY, QO_LEVELS }, + + { URI_NAV_ENTITY_SET, QO_FILTER, }, { URI_NAV_ENTITY_SET, QO_FORMAT }, { URI_NAV_ENTITY_SET, QO_EXPAND }, + { 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 }, }; private String[][] urisWithNonValidSystemQueryOptions = { @@ -217,6 +227,14 @@ public class UriEdmValidatorTest { { URI_SINGLETON, QO_FILTER }, { URI_SINGLETON, QO_ID }, { URI_SINGLETON, QO_COUNT }, /* { URI_SINGLETON, QO_ORDERBY }, *//* { URI_SINGLETON, QO_SEARCH }, */{ URI_SINGLETON, QO_SKIP }, { URI_SINGLETON, QO_SKIPTOKEN }, { URI_SINGLETON, QO_TOP }, + + { 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 }, + + }; private Parser parser; @@ -229,7 +247,7 @@ public class UriEdmValidatorTest { // @Ignore public void bla() throws Exception { - String[][] m = { { URI_SINGLETON, QO_SELECT } }; + String[][] m = { { URI_NAV_ENTITY_SET, QO_SELECT } }; String[] uris = constructUri(m); System.out.println(uris[0]);
