[OLINGO-206] function/action validation

This commit is contained in:
Stephan Klevenz 2014-03-24 17:10:10 +01:00
parent 8c0c670e4f
commit 3321708293
2 changed files with 82 additions and 48 deletions

View File

@ -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.ODataRuntimeException;
import org.apache.olingo.commons.api.edm.Edm; 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.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResource; 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.UriResourcePartTyped;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
@ -171,7 +172,27 @@ public class SystemQueryValidator {
} }
} }
break; 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; break;
case complexProperty: case complexProperty:
if (lastPathSegment instanceof UriResourcePartTyped) { if (lastPathSegment instanceof UriResourcePartTyped) {
@ -197,52 +218,45 @@ public class SystemQueryValidator {
+ lastPathSegment.getClass()); + lastPathSegment.getClass());
} }
break; break;
case function: case function: {
break; UriResourceFunction urf = (UriResourceFunction) lastPathSegment;
case it: EdmReturnType rt = urf.getFunction().getReturnType();
break; switch (rt.getType().getKind()) {
case lambdaAll: case ENTITY:
break; if (((EdmEntityType) rt.getType()).hasStream()) {
case lambdaAny: idx=10;
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 { } else {
idx = 9; 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; break;
case navigationProperty:
idx = ((UriResourceNavigation) lastPathSegment).isCollection() ? 7 : 9;
break;
case primitiveProperty: case primitiveProperty:
if (lastPathSegment instanceof UriResourcePartTyped) { if (lastPathSegment instanceof UriResourcePartTyped) {
if (((UriResourcePartTyped) lastPathSegment).isCollection()) { idx = ((UriResourcePartTyped) lastPathSegment).isCollection() ? 17 : 16;
idx = 17;
} else {
idx = 16;
}
} else { } else {
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: " throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass()); + lastPathSegment.getClass());
} }
break; break;
case ref: { case ref: {
int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2; int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex); UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
if (secondLastPathSegment instanceof UriResourcePartTyped) { if (secondLastPathSegment instanceof UriResourcePartTyped) {
if (((UriResourcePartTyped) secondLastPathSegment).isCollection()) { idx = ((UriResourcePartTyped) secondLastPathSegment).isCollection() ? 11 : 12;
idx = 11;
} else {
idx = 12;
}
} else { } else {
throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: " throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass()); + lastPathSegment.getClass());

View File

@ -135,6 +135,22 @@ public class UriEdmValidatorTest {
{ URI_NAV_ENTITY_SET, QO_COUNT }, /* { URI_NAV_ENTITY_SET, QO_ORDERBY }, */ { 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_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 }, { 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 = { private String[][] urisWithNonValidSystemQueryOptions = {
@ -234,7 +250,6 @@ public class UriEdmValidatorTest {
{ URI_NAV_ENTITY_SET, QO_ID }, { URI_NAV_ENTITY_SET, QO_ID },
}; };
private Parser parser; private Parser parser;
@ -243,17 +258,22 @@ public class UriEdmValidatorTest {
parser = new Parser(); parser = new Parser();
} }
@Test // @Test
// @Ignore //// @Ignore
public // public
void bla() throws Exception { // void bla() throws Exception {
String[][] m = { { URI_NAV_ENTITY_SET, QO_SELECT } }; // String[][] m = {
String[] uris = constructUri(m); // { "" },
System.out.println(uris[0]); // { "" },
// };
parseAndValidate(uris[0]); // String[] uris = constructUri(m);
} // for (String uri : uris) {
// System.out.println(uri);
//
// parseAndValidate(uri);
// }
// }
//
@Test @Test
public void checkValidSystemQueryOption() throws Exception { public void checkValidSystemQueryOption() throws Exception {
String[] uris = constructUri(urisWithValidSystemQueryOptions); String[] uris = constructUri(urisWithValidSystemQueryOptions);