"bad request" for not existing properties in expressions

Change-Id: I4061e0d4dd9de3c6fe1419eb5a7a0fdee88c62c2

Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
Klaus Straubinger 2014-10-08 15:54:56 +02:00 committed by Christian Amend
parent 42043f4643
commit cf032b690c
6 changed files with 48 additions and 19 deletions

View File

@ -87,7 +87,6 @@ import org.apache.olingo.server.core.uri.antlr.UriParserParser.BatchEOFContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.BooleanNonCaseContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.CastExprContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.CeilingMethodCallExprContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.CommonExprContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.ConcatMethodCallExprContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.ConstSegmentContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.ContainsMethodCallExprContext;
@ -157,7 +156,6 @@ import org.apache.olingo.server.core.uri.antlr.UriParserParser.TopContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.TotalOffsetMinutesMethodCallExprContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.TotalsecondsMethodCallExprContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.TrimMethodCallExprContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.UnaryContext;
import org.apache.olingo.server.core.uri.antlr.UriParserParser.YearMethodCallExprContext;
import org.apache.olingo.server.core.uri.queryoption.CountOptionImpl;
import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl;
@ -409,7 +407,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (property == null) {
throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '"
+ structType.getNamespace() + "." + structType.getName() + "'",
UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE,
ctx.depth() > 2 ? // resource path or path evaluation inside an expression?
UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE :
UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE,
structType.getFullQualifiedName().toString(), odi));
}
@ -1872,7 +1872,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EdmElement element = structType.getProperty(odi);
if (element == null) {
throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi,
UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE, structType.getName(), odi));
UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE, structType.getName(), odi));
}
// create new segment

View File

@ -28,6 +28,7 @@ public class UriParserSemanticException extends UriParserException {
/** parameter: resource part */ RESOURCE_PART_ONLY_FOR_TYPED_PARTS,
/** parameter: resource part */ RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE,
/** parameters: type name, property name */ PROPERTY_NOT_IN_TYPE,
/** parameters: type name, property name */ EXPRESSION_PROPERTY_NOT_IN_TYPE,
/** parameter: property name */ UNKNOWN_PROPERTY_TYPE,
/** parameter: type filter */ INCOMPATIBLE_TYPE_FILTER,
/** parameters: previous type filter, last type filter */ TYPE_FILTER_NOT_CHAINABLE,
@ -50,7 +51,7 @@ public class UriParserSemanticException extends UriParserException {
COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED,
NOT_FOR_ENTITY_TYPE,
PREVIOUS_PART_TYPED,
/** parameter: resource_name */RESOURCE_NOT_FOUND;
/** parameter: resource_name */ RESOURCE_NOT_FOUND;
@Override
public String getKey() {

View File

@ -37,6 +37,7 @@ UriParserSemanticException.FUNCTION_NOT_FOUND=The function import '%1$s' has no
UriParserSemanticException.RESOURCE_PART_ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for typed parts.
UriParserSemanticException.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE=The resource part '%1$s' must be preceded by a structural type.
UriParserSemanticException.PROPERTY_NOT_IN_TYPE=The type '%1$s' has no property '%2$s'.
UriParserSemanticException.EXPRESSION_PROPERTY_NOT_IN_TYPE=The property '%2$s', used in a query expression, is not defined in type '%1$s'.
UriParserSemanticException.UNKNOWN_PROPERTY_TYPE=The type of the property '%1$s' is unknown.
UriParserSemanticException.INCOMPATIBLE_TYPE_FILTER=The type filter '%1$s' is incompatible.
UriParserSemanticException.TYPE_FILTER_NOT_CHAINABLE=The type filter '%2$s' can not be chained with '%1$s'.

View File

@ -2505,6 +2505,11 @@ public class TestFullResourcePath {
.isType(EntityTypeProvider.nameETKeyNav)
.goUpExpandValidator()
.isSelectText("PropertyComp/PropertyInt16");
testUri.runEx("ESKeyNav", "$expand=undefined")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testUri.runEx("ESTwoKeyNav", "$expand=PropertyCompNav/undefined")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
}
@Test
@ -2940,20 +2945,22 @@ public class TestFullResourcePath {
.isLiteral("'SomeString'");
testFilter.runOnETTwoKeyNavEx("invalid")
.isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("PropertyComp")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("PropertyComp/invalid")
.isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("concat('a','b')/invalid").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOnETTwoKeyNavEx("PropertyComp/concat('a','b')")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyInt16 eq '1'")
.isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1")
.isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyString eq 1")
.isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1")
.isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyInt16 eq '1'")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyComp/PropertyDate eq 1")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyComp/PropertyString eq 1")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyInt64 eq 1")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETAllPrim("PropertySByte eq PropertySByte")
.is("<<PropertySByte> eq <PropertySByte>>")
@ -4152,10 +4159,9 @@ public class TestFullResourcePath {
.goParameter(1).isTypedLiteral(EntityTypeProvider.nameETKeyPrimNav);
testFilter.runOnETKeyNavEx("cast(NavPropertyETKeyPrimNavOne,olingo.odata.test1.ETKeyNav)")
.isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE);
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOnETKeyNav("any()")
.isMember().goPath().first().isUriPathInfoKind(UriResourceKind.lambdaAny);
}
@Test
@ -5073,6 +5079,12 @@ public class TestFullResourcePath {
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc, PropertyInt32 PropertyDuration desc")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc desc")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testFilter.runOrderByOnETTwoKeyNavEx("undefined")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testFilter.runOrderByOnETTwoKeyNavEx("PropertyComp/undefined")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
}
@Test

View File

@ -596,7 +596,6 @@ public class TestUriParserImpl {
testFilter.runESabc("1 div 2 add 3 div 4").isCompr("<< <1> div <2>> add <<3> div <4>>>");
testFilter.runESabc("1 div 2 div 3 add 4").isCompr("<<< <1> div <2>> div <3>> add <4>>");
testFilter.runESabc("1 div 2 div 3 div 4").isCompr("<<< <1> div <2>> div <3>> div <4>>");
}
@Test
@ -622,7 +621,7 @@ public class TestUriParserImpl {
}
@Test
public void testFunctionImport_VarRetruning() {
public void testFunctionImport_VarReturning() {
// returning primitive
testRes.run("FINRTInt16()")
.isFunctionImport("FINRTInt16")
@ -1145,6 +1144,21 @@ public class TestUriParserImpl {
.isComplexProperty("PropertyCompNav", ComplexTypeProvider.nameCTBasePrimCompNav, false)
.n()
.isTypeFilterOnCollection(ComplexTypeProvider.nameCTTwoBasePrimCompNav);
testUri.run("ESAllPrim", "$select=PropertyTimeOfDay,PropertyDate,PropertyTimeOfDay")
.isKind(UriInfoKind.resource)
.goSelectItemPath(0).first().isPrimitiveProperty("PropertyTimeOfDay", PropertyProvider.nameTimeOfDay, false)
.goUpUriValidator()
.goSelectItemPath(1).first().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false);
testUri.runEx("ESMixPrimCollComp", "$select=wrong")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testUri.runEx("ESMixPrimCollComp", "$select=PropertyComp/wrong")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
testUri.runEx("ESMixPrimCollComp", "$select=PropertyComp///PropertyInt16")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testUri.runEx("ESMixPrimCollComp", "$select=/PropertyInt16")
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
}
public static String encode(final String decoded) throws UnsupportedEncodingException {

View File

@ -224,6 +224,7 @@ public class FilterValidator implements TestValidator {
try {
uriInfo = parser.parseUri(path, query, null, edm);
fail("Expected exception not thrown.");
} catch (UriParserException e) {
exception = e;
return this;