@SuppressWarnings("unchecked")
public static <T> Object convertValueOnAttribute(final OData odata, final JPAAttribute attribute, final String value,
final Boolean isUri) throws ODataJPAFilterException {
try {
final CsdlProperty edmProperty = (CsdlProperty) attribute.getProperty();
final EdmPrimitiveTypeKind edmTypeKind = JPATypeConvertor.convertToEdmSimpleType(attribute);
String targetValue = null;
final EdmPrimitiveType edmType = odata.createPrimitiveTypeInstance(edmTypeKind);
if (isUri) {
targetValue = edmType.fromUriLiteral(value);
} else {
targetValue = value;
}
if (attribute.getConverter() != null) {
AttributeConverter<?, T> dbConverter = attribute.getConverter();
return dbConverter.convertToEntityAttribute(
(T) edmType.valueOfString(targetValue, edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), true, attribute.getType()));
} else
return edmType.valueOfString(targetValue, edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), true, attribute.getType());
} catch (EdmPrimitiveTypeException | ODataJPAModelException e) {
throw new ODataJPAFilterException(e, HttpStatusCode.INTERNAL_SERVER_ERROR);
}
}