public Integer getPrecision() { if (property == null) { return null; } return property.getPrecision(); }
/** Sets all facets from an EDM property. */ public Builder facetsFrom(final EdmProperty property) { options.isNullable = property.isNullable(); options.maxLength = property.getMaxLength(); options.precision = property.getPrecision(); options.scale = property.getScale(); options.isUnicode = property.isUnicode(); return this; }
/** Sets all facets from an EDM property. */ public Builder facetsFrom(final EdmProperty property) { options.isNullable = property.isNullable(); options.maxLength = property.getMaxLength(); options.precision = property.getPrecision(); options.scale = property.getScale(); options.isUnicode = property.isUnicode(); return this; }
/** Sets all facets from an EDM property. */ public Builder facetsFrom(final EdmProperty property) { options.isNullable = property.isNullable(); options.maxLength = property.getMaxLength(); options.precision = property.getPrecision(); options.scale = property.getScale(); options.isUnicode = property.isUnicode(); return this; }
/** Sets all facets from an EDM property. */ public Builder facetsFrom(final EdmProperty property) { options.isNullable = property.isNullable(); options.maxLength = property.getMaxLength(); options.precision = property.getPrecision(); options.scale = property.getScale(); options.isUnicode = property.isUnicode(); return this; }
@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 String getLiteral(final Object value) throws EdmPrimitiveTypeException { final EdmProperty edmProperty = getEdmProperty(); String uriLiteral; if (edmProperty != null) { uriLiteral = ((EdmPrimitiveType) type) .valueToString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()); } else { uriLiteral = ((EdmPrimitiveType) type).valueToString(value, null, null, null, null, null); } return ((EdmPrimitiveType) type).toUriLiteral(uriLiteral); } }
/** * This method returns the object which is the value of the property. * * @param edmProperty EdmProperty * @param value String value * @return Object * @throws ODataApplicationException */ private String readPrimitiveValueInString(EdmProperty edmProperty, Object value) throws ODataApplicationException { if (value == null) { return null; } try { EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmProperty.getType(); return edmPrimitiveType.valueToString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()); } catch (EdmPrimitiveTypeException e) { throw new ODataApplicationException("Invalid value: " + value + " for property: " + edmProperty.getName(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault()); } }
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 void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node, final Entity entity) throws DeserializerException { List<String> propertyNames = edmEntityType.getPropertyNames(); for (String propertyName : propertyNames) { JsonNode jsonNode = node.get(propertyName); if (jsonNode != null) { EdmProperty edmProperty = (EdmProperty) edmEntityType.getProperty(propertyName); if (jsonNode.isNull() && !edmProperty.isNullable()) { throw new DeserializerException("Property: " + propertyName + " must not be null.", DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName); } Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(), edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(), jsonNode); entity.addProperty(property); node.remove(propertyName); } } }
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(), subNode); complexValue.getValue().add(property);
private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node, final Entity entity) throws DeserializerException { List<String> propertyNames = edmEntityType.getPropertyNames(); for (String propertyName : propertyNames) { JsonNode jsonNode = node.get(propertyName); if (jsonNode != null) { EdmProperty edmProperty = (EdmProperty) edmEntityType.getProperty(propertyName); if (jsonNode.isNull() && !edmProperty.isNullable()) { throw new DeserializerException("Property: " + propertyName + " must not be null.", DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName); } Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(), edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(), jsonNode); entity.addProperty(property); node.remove(propertyName); } } }
private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node, final Entity entity) throws DeserializerException { List<String> propertyNames = edmEntityType.getPropertyNames(); for (String propertyName : propertyNames) { JsonNode jsonNode = node.get(propertyName); if (jsonNode != null) { EdmProperty edmProperty = (EdmProperty) edmEntityType.getProperty(propertyName); if (jsonNode.isNull() && !edmProperty.isNullable()) { throw new DeserializerException("Property: " + propertyName + " must not be null.", DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName); } Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(), edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(), jsonNode); entity.addProperty(property); node.remove(propertyName); } } }
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); } }
@Override public DeserializerResult property(final InputStream stream, final EdmProperty edmProperty) throws DeserializerException { try { final ObjectNode tree = parseJsonTree(stream); final Property property; JsonNode jsonNode = tree.get(Constants.VALUE); if (jsonNode != null) { property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(), edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(), jsonNode); tree.remove(Constants.VALUE); } else { property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(), edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(), tree); } return DeserializerResultImpl.with().property(property).build(); } catch (final IOException e) { throw wrapParseException(e); } }
private static UriParameter createUriParameter(final EdmProperty edmProperty, final String parameterName, final String literalValue, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { final AliasQueryOption alias = literalValue.startsWith("@") ? getKeyAlias(literalValue, edmProperty, edm, referringType, aliases) : null; final String value = alias == null ? literalValue : alias.getText(); final EdmPrimitiveType primitiveType = (EdmPrimitiveType) edmProperty.getType(); try { if (!(primitiveType.validate(primitiveType.fromUriLiteral(value), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()))) { throw new UriValidationException("Invalid key property", UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, parameterName); } } catch (final EdmPrimitiveTypeException e) { throw new UriValidationException("Invalid key property", e, UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, parameterName); } return new UriParameterImpl() .setName(parameterName) .setText("null".equals(literalValue) ? null : literalValue) .setAlias(alias == null ? null : literalValue) .setExpression(alias == null ? null : alias.getValue() == null ? new LiteralImpl(value, primitiveType) : alias.getValue()); }
private static UriParameter createUriParameter(final EdmProperty edmProperty, final String parameterName, final String literalValue, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { final AliasQueryOption alias = literalValue.startsWith("@") ? getKeyAlias(literalValue, edmProperty, edm, referringType, aliases) : null; final String value = alias == null ? literalValue : alias.getText(); final EdmPrimitiveType primitiveType = (EdmPrimitiveType) edmProperty.getType(); try { if (!(primitiveType.validate(primitiveType.fromUriLiteral(value), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()))) { throw new UriValidationException("Invalid key property", UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, parameterName); } } catch (final EdmPrimitiveTypeException e) { throw new UriValidationException("Invalid key property", e, UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, parameterName); } return new UriParameterImpl() .setName(parameterName) .setText("null".equals(literalValue) ? null : literalValue) .setAlias(alias == null ? null : literalValue) .setExpression(alias == null ? null : alias.getValue() == null ? new LiteralImpl(value, primitiveType) : alias.getValue()); }
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); } }
@Override public DeserializerResult property(final InputStream input, final EdmProperty edmProperty) throws DeserializerException { try { final XMLEventReader reader = getReader(input); final StartElement start = skipBeforeFirstStartElement(reader); Property property = property(reader, start, edmProperty.getType(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.isCollection()); return DeserializerResultImpl.with().property(property) .build(); } catch (XMLStreamException e) { throw new DeserializerException(e.getMessage(), e, DeserializerException.MessageKeys.IO_EXCEPTION); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException(e.getMessage(), e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY); } }