@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); } }
/** 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 boolean isStreamProperty(EdmProperty edmProperty) { final EdmType type = edmProperty.getType(); return (edmProperty.isPrimitive() && type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Stream)); }
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); } }
@Override public String getSegmentValue() { return property.getName(); } }
@Override public EdmType getType() { return property.getType(); }
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; } }
@Override public void execute(ServiceHandler handler, ODataResponse response) throws ODataLibraryException, ODataApplicationException { EdmProperty edmProperty = getUriResourceProperty().getProperty(); if (isGET()) { handler.read(DataRequest.this, PrimitiveValueResponse.getInstance(DataRequest.this, response, isCollection(), getUriResourceProperty().getProperty())); } else if (isDELETE()) { Property property = new Property( edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString(), edmProperty.getName()); PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response, edmProperty.getType(), getContextURL(odata), edmProperty.isCollection()); handler.updateProperty(DataRequest.this, property, true, false, getETag(), propertyResponse); } else if (isPUT()) { PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response, edmProperty.getType(), getContextURL(odata), edmProperty.isCollection()); Property property = new Property( edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString(), edmProperty.getName()); property.setValue(ValueType.PRIMITIVE, getRawValueFromClient()); handler.updateProperty(DataRequest.this, property, true, false, getETag(), propertyResponse); } }
@Override public void visit(PropertyResponse response) throws ODataApplicationException, SerializerException { EdmProperty edmProperty = request.getUriResourceProperty().getProperty(); Property property = details.entity.getProperty(edmProperty.getName()); response.writeProperty(edmProperty.getType(), property); }
private PropertyResponse buildResponse(ODataResponse response, EdmProperty edmProperty) throws ContentNegotiatorException, SerializerException { PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response, edmProperty.getType(), getContextURL(odata), edmProperty.isCollection()); return propertyResponse; }
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(); }
static SQLParameter asParam(EdmProperty edmProp, Object value, boolean rawValue) throws TeiidException { String teiidType = ODataTypeManager.teiidType((SingletonPrimitiveType)edmProp.getType(), edmProp.isCollection()); int sqlType = JDBCSQLTypeInfo.getSQLType(teiidType); if (value == null) { return new SQLParameter(null, sqlType); } if (rawValue) { return new SQLParameter(ODataTypeManager.convertByteArrayToTeiidRuntimeType( DataTypeManager.getDataTypeClass(teiidType), (byte[])value, ((SingletonPrimitiveType)edmProp.getType()).getFullQualifiedName().getFullQualifiedNameAsString(), edmProp.getSrid() != null?edmProp.getSrid().toString():null), sqlType); } return new SQLParameter(ODataTypeManager.convertToTeiidRuntimeType( DataTypeManager.getDataTypeClass(teiidType), value, ((SingletonPrimitiveType)edmProp.getType()).getFullQualifiedName().getFullQualifiedNameAsString(), edmProp.getSrid() != null?edmProp.getSrid().toString():null), sqlType); }
private void validatePropertyOperations(final UriInfo uriInfo, final HttpMethod method) throws UriValidationException { final List<UriResource> parts = uriInfo.getUriResourceParts(); final UriResource last = !parts.isEmpty() ? parts.get(parts.size() - 1) : null; final UriResource previous = parts.size() > 1 ? parts.get(parts.size() - 2) : null; if (last != null && (last.getKind() == UriResourceKind.primitiveProperty || last.getKind() == UriResourceKind.complexProperty || (last.getKind() == UriResourceKind.value && previous != null && previous.getKind() == UriResourceKind.primitiveProperty))) { final EdmProperty property = ((UriResourceProperty) (last.getKind() == UriResourceKind.value ? previous : last)).getProperty(); if (method == HttpMethod.PATCH && property.isCollection()) { throw new UriValidationException("Attempt to patch collection property.", UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, method.toString()); } if (method == HttpMethod.DELETE && !property.isNullable()) { throw new UriValidationException("Attempt to delete non-nullable property.", UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, method.toString()); } } } }
@Override public void visit(PropertyResponse response) throws ODataLibraryException, ODataApplicationException { EdmProperty edmProperty = request.getUriResourceProperty().getProperty(); if (edmProperty.isPrimitive()) { if(edmProperty.isCollection()) { selectProcessor(PrimitiveCollectionProcessor.class).readPrimitiveCollection( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getResponseContentType()); } else { selectProcessor(PrimitiveProcessor.class).readPrimitive( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getResponseContentType()); } } else { if(edmProperty.isCollection()) { selectProcessor(ComplexCollectionProcessor.class).readComplexCollection( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getResponseContentType()); } else { selectProcessor(ComplexProcessor.class).readComplex( request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getResponseContentType()); } } }
public Integer getPrecision() { if (property == null) { return null; } return property.getPrecision(); }
public Integer getScale() { if (property == null) { return null; } return property.getScale(); }
@Override public boolean isCollection() { return property.isCollection(); }
@Override public String getSegmentValue() { return property.getName(); } }
@Override public EdmType getType() { return property.getType(); }
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; } }