@Override public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException { if (value == null) { return null; } else if (typeKind.isGeospatial()) { return reference.cast(value); } else { // TODO: set facets return type.valueOfString(type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference); } }
@Override public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException { if (value == null) { return null; } else if (typeKind.isGeospatial()) { return reference.cast(value); } else { // TODO: set facets return type.valueOfString(type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference); } }
private Object fromPrimitive(final JsonNode node, final EdmTypeInfo typeInfo) throws EdmPrimitiveTypeException { return node.isNull() ? null : typeInfo == null ? node.asText() : typeInfo.getPrimitiveTypeKind().isGeospatial() ? getGeoDeserializer().deserialize(node, typeInfo) : ((EdmPrimitiveType) typeInfo.getType()) .valueOfString(node.asText(), true, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true, ((EdmPrimitiveType) typeInfo.getType()).getDefaultType()); }
private Object fromPrimitive(final JsonNode node, final EdmTypeInfo typeInfo) throws EdmPrimitiveTypeException { return node.isNull() ? null : typeInfo == null ? node.asText() : typeInfo.getPrimitiveTypeKind().isGeospatial() ? getGeoDeserializer().deserialize(node, typeInfo) : ((EdmPrimitiveType) typeInfo.getType()) .valueOfString(node.asText(), true, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true, ((EdmPrimitiveType) typeInfo.getType()).getDefaultType()); }
private Object readPrimitiveValue(final String name, final EdmPrimitiveType type, final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException { checkForValueNode(name, jsonNode); if (isValidNull(name, isNullable, jsonNode)) { return null; } checkJsonTypeBasedOnPrimitiveType(name, type, jsonNode); Class<?> javaClass = getJavaClassForPrimitiveType(mapping, type); try { return type.valueOfString(jsonNode.asText(), isNullable, maxLength, precision, scale, isUnicode, javaClass); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException("Invalid value: " + jsonNode.asText() + " for property: " + name, e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); } }
protected Object castTo(final String value, final EdmPrimitiveType type) throws EdmPrimitiveTypeException { final EdmProperty edmProperty = getEdmProperty(); if (edmProperty != null) { return type.valueOfString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), getDefaultType(type)); } else { return type.valueOfString(value, null, null, null, null, null, getDefaultType(type)); } }
private Object readPrimitiveValue(final String name, final EdmPrimitiveType type, final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException { if (isValidNull(name, isNullable, jsonNode)) { return null; } final boolean isGeoType = type.getName().startsWith("Geo"); if (!isGeoType) { checkForValueNode(name, jsonNode); } checkJsonTypeBasedOnPrimitiveType(name, type, jsonNode); try { if (isGeoType) { return readPrimitiveGeoValue(name, type, (ObjectNode) jsonNode); } return type.valueOfString(jsonNode.asText(), isNullable, maxLength, precision, scale, isUnicode, getJavaClassForPrimitiveType(mapping, type)); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException( "Invalid value: " + jsonNode.asText() + " for property: " + name, e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); } }
@Override public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { return getUnderlyingType().valueOfString(value, isNullable, maxLength == null ? getMaxLength() : maxLength, precision == null ? getPrecision() : precision, scale == null ? getScale() : scale, isUnicode == null ? isUnicode() : isUnicode, returnType); }
@Override public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { return getUnderlyingType().valueOfString(value, isNullable, maxLength == null ? getMaxLength() : maxLength, precision == null ? getPrecision() : precision, scale == null ? getScale() : scale, isUnicode == null ? isUnicode() : isUnicode, returnType); }
@Override public Object primitiveValue(final InputStream content, final EdmProperty property) throws DeserializerException { if (property == null || !property.isPrimitive()) { throw new DeserializerException("Wrong property.", DeserializerException.MessageKeys.NOT_IMPLEMENTED); } try { StringWriter writer = new StringWriter(); InputStreamReader reader = new InputStreamReader(content, "UTF-8"); int c = -1; while ((c = reader.read()) != -1) { writer.append((char) c); } final EdmPrimitiveType type = (EdmPrimitiveType) property.getType(); return type.valueOfString(writer.toString(), property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(), property.isUnicode(), type.getDefaultType()); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException("The value is not valid.", e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, property.getName()); } catch (final IOException e) { throw new DeserializerException("An I/O exception occurred.", e, DeserializerException.MessageKeys.IO_EXCEPTION); } }
@Override public Object primitiveValue(final InputStream content, final EdmProperty property) throws DeserializerException { if (property == null || !property.isPrimitive()) { throw new DeserializerException("Wrong property.", DeserializerException.MessageKeys.NOT_IMPLEMENTED); } try { StringWriter writer = new StringWriter(); InputStreamReader reader = new InputStreamReader(content, "UTF-8"); int c = -1; while ((c = reader.read()) != -1) { writer.append((char) c); } final EdmPrimitiveType type = (EdmPrimitiveType) property.getType(); return type.valueOfString(writer.toString(), property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(), property.isUnicode(), type.getDefaultType()); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException("The value is not valid.", e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, property.getName()); } catch (final IOException e) { throw new DeserializerException("An I/O exception occurred.", e, DeserializerException.MessageKeys.IO_EXCEPTION); } }
private Object getValue(final EdmFunction edmFunction, final JPAParameter parameter, final String uriValue) throws ODataApplicationException { final String value = uriValue.replaceAll("'", ""); final EdmParameter edmParam = edmFunction.getParameter(parameter.getName()); try { return ((EdmPrimitiveType) edmParam.getType()).valueOfString(value, false, parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(), true, parameter.getType()); } catch (EdmPrimitiveTypeException e) { // Unable to convert value %1$s of parameter %2$s throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.PARAMETER_CONVERSION_ERROR, HttpStatusCode.NOT_IMPLEMENTED, uriValue, parameter.getName()); } }
private Object getValue(final EdmFunction edmFunction, final JPAParameter parameter, final String uriValue) throws ODataApplicationException { final String value = uriValue.replaceAll("'", ""); final EdmParameter edmParam = edmFunction.getParameter(parameter.getName()); try { return ((EdmPrimitiveType) edmParam.getType()).valueOfString(value, false, parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(), true, parameter.getType()); } catch (EdmPrimitiveTypeException e) { // Unable to convert value %1$s of parameter %2$s throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.PARAMETER_CONVERSION_ERROR, HttpStatusCode.NOT_IMPLEMENTED, uriValue, parameter.getName()); } }
private Object getValue(final EdmFunction edmFunction, final JPAParameter parameter, final String uriValue) throws ODataApplicationException { final String value = uriValue.replaceAll("'", ""); final EdmParameter edmParam = edmFunction.getParameter(parameter.getName()); try { return ((EdmPrimitiveType) edmParam.getType()).valueOfString(value, false, parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(), true, parameter.getType()); } catch (EdmPrimitiveTypeException e) { // Unable to convert value %1$s of parameter %2$s throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.PARAMETER_CONVERSION_ERROR, HttpStatusCode.NOT_IMPLEMENTED, uriValue, parameter.getName()); } }
public static Object convertValueOnFacet(final OData odata, JPAParamaterFacet returnType, final String value) throws ODataJPAFilterException { try { final EdmPrimitiveTypeKind edmTypeKind = EdmPrimitiveTypeKind.valueOfFQN(returnType.getTypeFQN()); final EdmPrimitiveType edmType = odata.createPrimitiveTypeInstance(edmTypeKind); String targetValue; targetValue = edmType.fromUriLiteral(value); return edmType.valueOfString(targetValue, true, returnType.getMaxLength(), returnType.getPrecision(), returnType .getScale(), true, returnType.getType()); } catch (EdmPrimitiveTypeException | ODataJPAModelException e) { throw new ODataJPAFilterException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } }
public static Object parseLiteral(EdmParameter edmParameter, Class<?> runtimeType, String value) throws TeiidProcessingException { EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind .valueOf(edmParameter.getType() .getFullQualifiedName() .getFullQualifiedNameAsString().substring(4))); try { if (EdmString.getInstance().equals(edmParameter.getType())) { value = EdmString.getInstance().fromUriLiteral(value); } Object converted = primitiveType.valueOfString(value, edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter.getScale(), true, runtimeType); return converted; } catch (EdmPrimitiveTypeException e) { throw new TeiidProcessingException(e); } }
public static Object parseLiteral(EdmParameter edmParameter, Class<?> runtimeType, String value) throws TeiidProcessingException { EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind .valueOf(edmParameter.getType() .getFullQualifiedName() .getFullQualifiedNameAsString().substring(4))); try { if (EdmString.getInstance().equals(edmParameter.getType())) { value = EdmString.getInstance().fromUriLiteral(value); } Object converted = primitiveType.valueOfString(value, edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter.getScale(), true, runtimeType); return converted; } catch (EdmPrimitiveTypeException e) { throw new TeiidProcessingException(e); } }
public static Object parseLiteral(EdmProperty edmProperty, Class<?> runtimeType, String value) throws TeiidException { EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind .valueOf(edmProperty.getType() .getFullQualifiedName() .getFullQualifiedNameAsString().substring(4))); try { if (EdmString.getInstance().equals(edmProperty.getType())) { value = EdmString.getInstance().fromUriLiteral(value); } Object converted = primitiveType.valueOfString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), true, runtimeType); return converted; } catch (EdmPrimitiveTypeException e) { throw new TeiidException(e); } }
public static Object parseLiteral(EdmProperty edmProperty, Class<?> runtimeType, String value) throws TeiidException { EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind .valueOf(edmProperty.getType() .getFullQualifiedName() .getFullQualifiedNameAsString().substring(4))); try { if (EdmString.getInstance().equals(edmProperty.getType())) { value = EdmString.getInstance().fromUriLiteral(value); } Object converted = primitiveType.valueOfString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), true, runtimeType); return converted; } catch (EdmPrimitiveTypeException e) { throw new TeiidException(e); } }
private Object getValue(final EdmFunction edmFunction, final JPAParameter parameter, final String uriValue) throws ODataApplicationException { final String value = uriValue.replaceAll("'", ""); final EdmParameter edmParam = edmFunction.getParameter(parameter.getName()); try { switch (edmParam.getType().getKind()) { case PRIMITIVE: return ((EdmPrimitiveType) edmParam.getType()).valueOfString(value, false, edmParam.getMaxLength(), edmParam.getPrecision(), edmParam.getScale(), true, parameter.getType()); case ENUM: final JPAEnumerationAttribute enumeration = sd.getEnumType(parameter.getTypeFQN() .getFullQualifiedNameAsString()); return enumeration.enumOf(value); default: throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.PARAMETER_CONVERSION_ERROR, HttpStatusCode.NOT_IMPLEMENTED, uriValue, parameter.getName()); } } catch (EdmPrimitiveTypeException | ODataJPAModelException e) { // Unable to convert value %1$s of parameter %2$s throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.PARAMETER_CONVERSION_ERROR, HttpStatusCode.NOT_IMPLEMENTED, uriValue, parameter.getName()); } }