[OLINGO-603] Action Parameter deserialization based on type kind
This commit is contained in:
parent
26be7d2e7c
commit
ef6ed4e3ef
|
@ -23,6 +23,6 @@ package org.apache.olingo.commons.api.edm.constants;
|
||||||
*/
|
*/
|
||||||
public enum EdmTypeKind {
|
public enum EdmTypeKind {
|
||||||
|
|
||||||
UNDEFINED, PRIMITIVE, ENUM, DEFINITION, COMPLEX, ENTITY, NAVIGATION, ACTION, FUNCTION, SYSTEM
|
PRIMITIVE, ENUM, DEFINITION, COMPLEX, ENTITY, NAVIGATION, ACTION, FUNCTION
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,9 @@ public class DeserializerException extends ODataTranslatedException {
|
||||||
/** parameter: navigationPropertyName */NAVIGATION_PROPERTY_NOT_FOUND,
|
/** parameter: navigationPropertyName */NAVIGATION_PROPERTY_NOT_FOUND,
|
||||||
/** parameter: annotationName */INVALID_ANNOTATION_TYPE,
|
/** parameter: annotationName */INVALID_ANNOTATION_TYPE,
|
||||||
/** parameter: annotationName */INVALID_NULL_ANNOTATION,
|
/** parameter: annotationName */INVALID_NULL_ANNOTATION,
|
||||||
/** parameter: binding link */INVALID_ENTITY_BINDING_LINK;
|
/** parameter: binding link */INVALID_ENTITY_BINDING_LINK,
|
||||||
|
/** parameter: action parameter name */INVALID_ACTION_PARAMETER_TYPE,
|
||||||
|
/** parameter: parameterName */ INVALID_NULL_PARAMETER;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
|
|
@ -215,13 +215,17 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
ParameterImpl parameter = new ParameterImpl();
|
ParameterImpl parameter = new ParameterImpl();
|
||||||
parameter.setName(name);
|
parameter.setName(name);
|
||||||
JsonNode jsonNode = node.get(name);
|
JsonNode jsonNode = node.get(name);
|
||||||
if (jsonNode == null) {
|
if (jsonNode == null || jsonNode.isNull()) {
|
||||||
if (!edmParameter.isNullable()) {
|
if (!edmParameter.isNullable()) {
|
||||||
// TODO: new message key.
|
|
||||||
throw new DeserializerException("Non-nullable parameter not present or null",
|
throw new DeserializerException("Non-nullable parameter not present or null",
|
||||||
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
|
DeserializerException.MessageKeys.INVALID_NULL_PARAMETER, name);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
switch (edmParameter.getType().getKind()) {
|
||||||
|
case PRIMITIVE:
|
||||||
|
case DEFINITION:
|
||||||
|
case ENUM:
|
||||||
Property consumePropertyNode =
|
Property consumePropertyNode =
|
||||||
consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
|
consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
|
||||||
edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
|
edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
|
||||||
|
@ -231,6 +235,14 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
|
parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
|
||||||
parameters.add(parameter);
|
parameters.add(parameter);
|
||||||
node.remove(name);
|
node.remove(name);
|
||||||
|
break;
|
||||||
|
case COMPLEX:
|
||||||
|
case ENTITY:
|
||||||
|
throw new DeserializerException("Entity an complex parameters currently not Implemented",
|
||||||
|
DeserializerException.MessageKeys.NOT_IMPLEMENTED);
|
||||||
|
default:
|
||||||
|
throw new DeserializerException("Invalid type kind " + edmParameter.getType().getKind().toString()
|
||||||
|
+ " for action parameter: " + name, DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,8 @@ DeserializerException.UNKNOWN_PRIMITIVE_TYPE=Unknown primitive type '%1$s' for p
|
||||||
DeserializerException.NAVIGATION_PROPERTY_NOT_FOUND=Can`t find navigation property with name: '%1$s'.
|
DeserializerException.NAVIGATION_PROPERTY_NOT_FOUND=Can`t find navigation property with name: '%1$s'.
|
||||||
DeserializerException.INVALID_ANNOTATION_TYPE=The annotation '%1$s' has the wrong JSON type.
|
DeserializerException.INVALID_ANNOTATION_TYPE=The annotation '%1$s' has the wrong JSON type.
|
||||||
DeserializerException.INVALID_ENTITY_BINDING_LINK=The binding link '%1$s' is malformed.
|
DeserializerException.INVALID_ENTITY_BINDING_LINK=The binding link '%1$s' is malformed.
|
||||||
|
DeserializerException.INVALID_ACTION_PARAMETER_TYPE=The action parameter '%1$s' must be either primitive, complex or an entity or a collection of those types.
|
||||||
|
DeserializerException.INVALID_NULL_PARAMETER=The parameter '%1$s' must not be null.
|
||||||
|
|
||||||
BatchDeserializerException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'.
|
BatchDeserializerException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'.
|
||||||
BatchDeserializerException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'.
|
BatchDeserializerException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'.
|
||||||
|
|
|
@ -37,10 +37,10 @@ public class EdmTypeImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getterTest() {
|
public void getterTest() {
|
||||||
EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.UNDEFINED);
|
EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.PRIMITIVE);
|
||||||
assertEquals("name", type.getName());
|
assertEquals("name", type.getName());
|
||||||
assertEquals("namespace", type.getNamespace());
|
assertEquals("namespace", type.getNamespace());
|
||||||
assertEquals(EdmTypeKind.UNDEFINED, type.getKind());
|
assertEquals(EdmTypeKind.PRIMITIVE, type.getKind());
|
||||||
EdmAnnotatable an = (EdmAnnotatable) type;
|
EdmAnnotatable an = (EdmAnnotatable) type;
|
||||||
assertNotNull(an.getAnnotations().get(0));
|
assertNotNull(an.getAnnotations().get(0));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue