private static AliasQueryOption getKeyAlias(final String name, final EdmProperty edmProperty, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { if (aliases.containsKey(name)) { return parseAliasValue(name, edmProperty.getType(), edmProperty.isNullable(), edmProperty.isCollection(), edm, referringType, aliases); } else { throw new UriValidationException("Alias '" + name + "' for key value not found.", UriValidationException.MessageKeys.MISSING_ALIAS, name); } }
private static AliasQueryOption getKeyAlias(final String name, final EdmProperty edmProperty, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { if (aliases.containsKey(name)) { return parseAliasValue(name, edmProperty.getType(), edmProperty.isNullable(), edmProperty.isCollection(), edm, referringType, aliases); } else { throw new UriValidationException("Alias '" + name + "' for key value not found.", UriValidationException.MessageKeys.MISSING_ALIAS, name); } }
protected void writeProperty(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set<List<String>> selectedPaths, final String xml10InvalidCharReplacement, final XMLStreamWriter writer, Set<List<String>> expandedPaths, Linked linked, ExpandOption expand) throws XMLStreamException, SerializerException { writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA); if (property == null || property.isNull()) { if (edmProperty.isNullable()) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true"); } else { throw new SerializerException("Non-nullable property not present!", SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName()); } } else { writePropertyValue(metadata, edmProperty, property, selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand); } writer.writeEndElement(); }
protected void writeProperty(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set<List<String>> selectedPaths, final String xml10InvalidCharReplacement, final XMLStreamWriter writer, Set<List<String>> expandedPaths, Linked linked, ExpandOption expand) throws XMLStreamException, SerializerException { writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA); if (property == null || property.isNull()) { if (edmProperty.isNullable()) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true"); } else { throw new SerializerException("Non-nullable property not present!", SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName()); } } else { writePropertyValue(metadata, edmProperty, property, selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand); } writer.writeEndElement(); }
/** 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; }
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); } } }
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 static UriParameter simpleKey(UriTokenizer tokenizer, final EdmKeyPropertyRef edmKeyPropertyRef, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { final EdmProperty edmProperty = edmKeyPropertyRef == null ? null : edmKeyPropertyRef.getProperty(); if (nextPrimitiveTypeValue(tokenizer, edmProperty == null ? null : (EdmPrimitiveType) edmProperty.getType(), edmProperty == null ? false : edmProperty.isNullable())) { final String literalValue = tokenizer.getText(); ParserHelper.requireNext(tokenizer, TokenKind.CLOSE); return createUriParameter(edmProperty, edmKeyPropertyRef.getName(), literalValue, edm, referringType, aliases); } else { return null; } }
private static UriParameter simpleKey(UriTokenizer tokenizer, final EdmKeyPropertyRef edmKeyPropertyRef, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { final EdmProperty edmProperty = edmKeyPropertyRef == null ? null : edmKeyPropertyRef.getProperty(); if (nextPrimitiveTypeValue(tokenizer, edmProperty == null ? null : (EdmPrimitiveType) edmProperty.getType(), edmProperty == null ? false : edmProperty.isNullable())) { final String literalValue = tokenizer.getText(); ParserHelper.requireNext(tokenizer, TokenKind.CLOSE); return createUriParameter(edmProperty, edmKeyPropertyRef.getName(), literalValue, edm, referringType, aliases); } else { return null; } }
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); } }
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)); } }
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()); }
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 static UriParameter keyValuePair(UriTokenizer tokenizer, final String keyPredicateName, final EdmEntityType edmEntityType, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { final EdmKeyPropertyRef keyPropertyRef = edmEntityType.getKeyPropertyRef(keyPredicateName); final EdmProperty edmProperty = keyPropertyRef == null ? null : keyPropertyRef.getProperty(); if (edmProperty == null) { throw new UriValidationException(keyPredicateName + " is not a valid key property name.", UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, keyPredicateName); } ParserHelper.requireNext(tokenizer, TokenKind.EQ); if (tokenizer.next(TokenKind.COMMA) || tokenizer.next(TokenKind.CLOSE) || tokenizer.next(TokenKind.EOF)) { throw new UriParserSyntaxException("Key value expected.", UriParserSyntaxException.MessageKeys.SYNTAX); } if (nextPrimitiveTypeValue(tokenizer, (EdmPrimitiveType) edmProperty.getType(), edmProperty.isNullable())) { return createUriParameter(edmProperty, keyPredicateName, tokenizer.getText(), edm, referringType, aliases); } else { throw new UriParserSemanticException(keyPredicateName + " has not a valid key value.", UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, keyPredicateName); } }