[OLINGO-206] nav prop validation
This commit is contained in:
parent
1274b1e725
commit
8c0c670e4f
|
@ -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.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.EdmNavigationProperty;
|
||||||
|
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.UriResourcePartTyped;
|
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
|
||||||
|
@ -146,9 +150,9 @@ public class SystemQueryValidator {
|
||||||
int idx = 5;
|
int idx = 5;
|
||||||
|
|
||||||
int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
|
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: {
|
case count: {
|
||||||
int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
|
int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
|
||||||
UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
|
UriResource secondLastPathSegment = uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
|
||||||
|
@ -163,34 +167,34 @@ public class SystemQueryValidator {
|
||||||
idx = 18;
|
idx = 18;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UriValidationException("Illegal path part kind: " + lastPathSegemnt.getKind());
|
throw new UriValidationException("Illegal path part kind: " + lastPathSegment.getKind());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case action:
|
case action:
|
||||||
break;
|
break;
|
||||||
case complexProperty:
|
case complexProperty:
|
||||||
if (lastPathSegemnt instanceof UriResourcePartTyped) {
|
if (lastPathSegment instanceof UriResourcePartTyped) {
|
||||||
if (((UriResourcePartTyped) lastPathSegemnt).isCollection()) {
|
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
|
||||||
idx = 14;
|
idx = 14;
|
||||||
} else {
|
} else {
|
||||||
idx = 13;
|
idx = 13;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
|
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
|
||||||
+ lastPathSegemnt.getClass());
|
+ lastPathSegment.getClass());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case entitySet:
|
case entitySet:
|
||||||
if (lastPathSegemnt instanceof UriResourcePartTyped) {
|
if (lastPathSegment instanceof UriResourcePartTyped) {
|
||||||
if (((UriResourcePartTyped) lastPathSegemnt).isCollection()) {
|
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
|
||||||
idx = 7;
|
idx = 7;
|
||||||
} else {
|
} else {
|
||||||
idx = 9;
|
idx = 9;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
|
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
|
||||||
+ lastPathSegemnt.getClass());
|
+ lastPathSegment.getClass());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case function:
|
case function:
|
||||||
|
@ -203,18 +207,29 @@ public class SystemQueryValidator {
|
||||||
break;
|
break;
|
||||||
case lambdaVariable:
|
case lambdaVariable:
|
||||||
break;
|
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;
|
break;
|
||||||
case primitiveProperty:
|
case primitiveProperty:
|
||||||
if (lastPathSegemnt instanceof UriResourcePartTyped) {
|
if (lastPathSegment instanceof UriResourcePartTyped) {
|
||||||
if (((UriResourcePartTyped) lastPathSegemnt).isCollection()) {
|
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
|
||||||
idx = 17;
|
idx = 17;
|
||||||
} else {
|
} else {
|
||||||
idx = 16;
|
idx = 16;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
|
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
|
||||||
+ lastPathSegemnt.getClass());
|
+ lastPathSegment.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -230,7 +245,7 @@ public class SystemQueryValidator {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
|
throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
|
||||||
+ lastPathSegemnt.getClass());
|
+ lastPathSegment.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -256,7 +271,7 @@ public class SystemQueryValidator {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ODataRuntimeException("Unsupported uriResource kind: " + lastPathSegemnt.getKind());
|
throw new ODataRuntimeException("Unsupported uriResource kind: " + lastPathSegment.getKind());
|
||||||
}
|
}
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
|
|
|
@ -58,6 +58,8 @@ public class UriEdmValidatorTest {
|
||||||
"/ESCollAllPrim/CollPropertyString/$count";
|
"/ESCollAllPrim/CollPropertyString/$count";
|
||||||
private static final String URI_PROPERTY_PRIMITIVE_VALUE = "/ESAllPrim(1)/PropertyString/$value";
|
private static final String URI_PROPERTY_PRIMITIVE_VALUE = "/ESAllPrim(1)/PropertyString/$value";
|
||||||
private static final String URI_SINGLETON = "/SI";
|
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_FILTER = "$filter='1' eq '1'";
|
||||||
private static final String QO_FORMAT = "$format=bla";
|
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_FORMAT }, { URI_SINGLETON, QO_EXPAND }, { URI_SINGLETON, QO_SELECT },
|
||||||
{ URI_SINGLETON, QO_LEVELS },
|
{ 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 = {
|
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_FILTER }, { URI_SINGLETON, QO_ID }, { URI_SINGLETON, QO_COUNT },
|
||||||
/* { URI_SINGLETON, QO_ORDERBY }, *//* { URI_SINGLETON, QO_SEARCH }, */{ URI_SINGLETON, QO_SKIP },
|
/* { URI_SINGLETON, QO_ORDERBY }, *//* { URI_SINGLETON, QO_SEARCH }, */{ URI_SINGLETON, QO_SKIP },
|
||||||
{ URI_SINGLETON, QO_SKIPTOKEN }, { URI_SINGLETON, QO_TOP },
|
{ 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;
|
private Parser parser;
|
||||||
|
|
||||||
|
@ -229,7 +247,7 @@ public class UriEdmValidatorTest {
|
||||||
// @Ignore
|
// @Ignore
|
||||||
public
|
public
|
||||||
void bla() throws Exception {
|
void bla() throws Exception {
|
||||||
String[][] m = { { URI_SINGLETON, QO_SELECT } };
|
String[][] m = { { URI_NAV_ENTITY_SET, QO_SELECT } };
|
||||||
String[] uris = constructUri(m);
|
String[] uris = constructUri(m);
|
||||||
System.out.println(uris[0]);
|
System.out.println(uris[0]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue