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 de440a51e..d752a09ab 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()); 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 4e7d40239..d35105a3b 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);