public B addStructuralProperty(StructuralProperty structuralProperty) { this.structuralPropBuilder.put(structuralProperty.getName(), structuralProperty); return self; }
public B addStructuralProperty(StructuralProperty structuralProperty) { this.structuralPropBuilder.put(structuralProperty.getName(), structuralProperty); return self; }
private void writeCommonPropertyAttributes(StructuralProperty property) throws XMLStreamException { xmlWriter.writeAttribute(NAME, property.getName()); xmlWriter.writeAttribute(TYPE, property.getTypeName()); xmlWriter.writeAttribute(NULLABLE, Boolean.toString(property.isNullable())); } }
private void writeCommonPropertyAttributes(StructuralProperty property) throws XMLStreamException { xmlWriter.writeAttribute(NAME, property.getName()); xmlWriter.writeAttribute(TYPE, property.getTypeName()); xmlWriter.writeAttribute(NULLABLE, Boolean.toString(property.isNullable())); } }
/** * Ensure that non nullable navigation properties are present. * * @param entityType entityType * @throws ODataException If unable to ensure navigation properties are present */ public void ensureNavigationProperties(StructuredType entityType) throws ODataException { List<String> missingNavigationPropertyNames = new ArrayList<>(); entityType.getStructuralProperties().stream().filter(property -> (property instanceof NavigationProperty) && !property.isNullable()).forEach(property -> { LOG.debug("Validating non-nullable NavigationProperty property : {}", property.getName()); if (!links.containsKey(property.getName())) { missingNavigationPropertyNames.add(property.getName()); } }); if (missingNavigationPropertyNames.size() != 0) { StringJoiner joiner = new StringJoiner(","); missingNavigationPropertyNames.forEach(joiner::add); throw new ODataUnmarshallingException("The request does not specify the navigation links for '" + joiner.toString() + "."); } }
/** * Ensure that non nullable navigation properties are present. * * @param entityType entityType * @throws ODataException If unable to ensure navigation properties are present */ public void ensureNavigationProperties(StructuredType entityType) throws ODataException { List<String> missingNavigationPropertyNames = new ArrayList<>(); entityType.getStructuralProperties().stream().filter(property -> (property instanceof NavigationProperty) && !property.isNullable()).forEach(property -> { LOG.debug("Validating non-nullable NavigationProperty property : {}", property.getName()); if (!links.containsKey(property.getName())) { missingNavigationPropertyNames.add(property.getName()); } }); if (missingNavigationPropertyNames.size() != 0) { StringJoiner joiner = new StringJoiner(","); missingNavigationPropertyNames.forEach(joiner::add); throw new ODataUnmarshallingException("The request does not specify the navigation links for '" + joiner.toString() + "."); } }
private void ensureNonNullableNavigationPropertiesArePresent(Set<String> navigationPropertyNames, StructuredType entityType) throws ODataException { if (getRequest().getMethod() != ODataRequest.Method.POST) { return; } List<String> missingNavigationPropertyNames = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property instanceof NavigationProperty) && (!property.isNullable())) .forEach(property -> { LOG.debug("Validating non-nullable property : {}", property.getName()); if (!navigationPropertyNames.contains(property.getName())) { missingNavigationPropertyNames.add(property.getName()); } }); if (missingNavigationPropertyNames.size() != 0) { LOG.debug("Non-nullable navigation properties of {} are not found in the request" + missingNavigationPropertyNames); // NOTE: We are just logging if a navigation property is not present. // In future, we will impose this restriction like ODataJsonParser after // we support 8.2 of docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html } }
/** * Ensure that non nullable collection are present. * * @param entityType entityType * @throws ODataException If unable to ensure collection is present */ public void ensureCollection(StructuredType entityType) throws ODataException { List<String> missingCollectionPropertyName = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property.isCollection()) && !(property instanceof NavigationProperty) && !property.isNullable()).forEach(property -> { LOG.debug("Validating non-nullable collection property : {}", property.getName()); if (!fields.containsKey(property.getName())) { missingCollectionPropertyName.add(property.getName()); } }); if (missingCollectionPropertyName.size() != 0) { StringJoiner joiner = new StringJoiner(","); missingCollectionPropertyName.forEach(joiner::add); throw new ODataUnmarshallingException("The request does not specify the non-nullable collections: '" + joiner.toString() + "."); } }
private void ensureNonNullableNavigationPropertiesArePresent(Set<String> navigationPropertyNames, StructuredType entityType) throws ODataException { if (getRequest().getMethod() != ODataRequest.Method.POST) { return; } List<String> missingNavigationPropertyNames = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property instanceof NavigationProperty) && (!property.isNullable())) .forEach(property -> { LOG.debug("Validating non-nullable property : {}", property.getName()); if (!navigationPropertyNames.contains(property.getName())) { missingNavigationPropertyNames.add(property.getName()); } }); if (missingNavigationPropertyNames.size() != 0) { LOG.debug("Non-nullable navigation properties of {} are not found in the request" + missingNavigationPropertyNames); // NOTE: We are just logging if a navigation property is not present. // In future, we will impose this restriction like ODataJsonParser after // we support 8.2 of docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html } }
private void ensureNonNullableCollectionArePresent(StructuredType entityType) throws ODataException { if (getRequest().getMethod() != ODataRequest.Method.POST) { return; } List<String> missingCollectionPropertyName = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property.isCollection()) && !(property instanceof NavigationProperty) && (!property.isNullable())) .forEach(property -> { LOG.debug("Validating non-nullable collection property : {}", property.getName()); if (!foundCollectionProperties.contains(property.getName())) { missingCollectionPropertyName.add(property.getName()); } }); if (missingCollectionPropertyName.size() != 0) { StringJoiner joiner = new StringJoiner(","); missingCollectionPropertyName.forEach(joiner::add); LOG.debug("Non-nullable collections of {} are not found in the request" + missingCollectionPropertyName); throw new ODataUnmarshallingException("The request does not specify the non-nullable collections: '" + joiner.toString() + "."); } }
private void ensureNonNullableCollectionArePresent(StructuredType entityType) throws ODataException { if (getRequest().getMethod() != ODataRequest.Method.POST) { return; } List<String> missingCollectionPropertyName = new ArrayList<>(); entityType.getStructuralProperties().stream() .filter(property -> (property.isCollection()) && !(property instanceof NavigationProperty) && (!property.isNullable())) .forEach(property -> { LOG.debug("Validating non-nullable collection property : {}", property.getName()); if (!foundCollectionProperties.contains(property.getName())) { missingCollectionPropertyName.add(property.getName()); } }); if (missingCollectionPropertyName.size() != 0) { StringJoiner joiner = new StringJoiner(","); missingCollectionPropertyName.forEach(joiner::add); LOG.debug("Non-nullable collections of {} are not found in the request" + missingCollectionPropertyName); throw new ODataUnmarshallingException("The request does not specify the non-nullable collections: '" + joiner.toString() + "."); } }
private void handleProperty(Object data, StructuralProperty property, JsonGenerator generator) throws IllegalAccessException, IOException, ODataException { Field field = property.getJavaField(); field.setAccessible(true); Object value = field.get(data); LOG.trace("Property name is '{}' and its value is '{}'", property.getName(), value); Type type = getType(value); if (type == null) { String msg = String.format("Field type %s is not found in entity data model", field.getType()); LOG.error(msg); throw new ODataRenderException(msg); } switch (type.getMetaType()) { case PRIMITIVE: generator.writeFieldName(property.getName()); writePrimitive(value, generator); break; case COMPLEX: generator.writeArrayFieldStart(property.getName()); generateComplex(value, (StructuredType) type, true); generator.writeEndArray(); break; default: defaultHandling(type); } }
private void handleProperty(Object entity, StructuralProperty property, XMLStreamWriter writer) throws IllegalAccessException, XMLStreamException, ODataException { Field field = property.getJavaField(); field.setAccessible(true); Object value = field.get(entity); LOG.trace("Property name is '{}' and its value is '{}'", property.getName(), value); Type type = getType(value); if (type == null) { String msg = String.format("Field type %s is not found in entity data model", field.getType()); LOG.error(msg); throw new ODataRenderException(msg); } switch (type.getMetaType()) { case PRIMITIVE: handleCollectionsAndPrimitiveProperties(writer, property.getName(), value); break; case COMPLEX: writer.writeStartElement(property.getName()); handleCollectionAndComplexProperties(value, (StructuredType) type, writer); writer.writeEndElement(); break; default: defaultHandling(type); } }
private void handleProperty(Object entity, StructuralProperty property, XMLStreamWriter writer) throws IllegalAccessException, XMLStreamException, ODataException { Field field = property.getJavaField(); field.setAccessible(true); Object value = field.get(entity); LOG.trace("Property name is '{}' and its value is '{}'", property.getName(), value); Type type = getType(value); if (type == null) { String msg = String.format("Field type %s is not found in entity data model", field.getType()); LOG.error(msg); throw new ODataRenderException(msg); } switch (type.getMetaType()) { case PRIMITIVE: handleCollectionsAndPrimitiveProperties(writer, property.getName(), value); break; case COMPLEX: writer.writeStartElement(property.getName()); handleCollectionAndComplexProperties(value, (StructuredType) type, writer); writer.writeEndElement(); break; default: defaultHandling(type); } }
private void writeAllProperties(final Object data, StructuredType type) throws IOException, ODataRenderException { jsonGenerator.writeStartObject(); visitProperties(getEntityDataModel(), type, property -> { try { if (!(property instanceof NavigationProperty)) { handleProperty(data, property, jsonGenerator); } } catch (IllegalAccessException | IOException | ODataException e) { throw new ODataRenderException("Error while writing property: " + property.getName(), e); } }); jsonGenerator.writeEndObject(); }
private void writeAllProperties(final Object data, StructuredType type) throws IOException, ODataRenderException { jsonGenerator.writeStartObject(); visitProperties(getEntityDataModel(), type, property -> { try { if (!(property instanceof NavigationProperty)) { handleProperty(data, property, jsonGenerator); } } catch (IllegalAccessException | IOException | ODataException e) { throw new ODataRenderException("Error while writing property: " + property.getName(), e); } }); jsonGenerator.writeEndObject(); }
/** * Write either a {@code <Property>} or {@code <NavigationProperty>} element * for the given {@code StructuralProperty}. * * @param property The given structural property. It can not be {@code null}. * @throws javax.xml.stream.XMLStreamException If unable to write to stream */ public void write(StructuralProperty property) throws XMLStreamException { LOG.debug("Writing property {} of type {}", property.getName(), property.getTypeName()); if (property instanceof NavigationProperty) { NavigationProperty navProperty = (NavigationProperty) property; xmlWriter.writeStartElement(NAVIGATION_PROPERTY); writeCommonPropertyAttributes(property); if (!isNullOrEmpty(navProperty.getPartnerName())) { xmlWriter.writeAttribute(PARTNER, navProperty.getPartnerName()); } xmlWriter.writeEndElement(); } else { xmlWriter.writeStartElement(PROPERTY); writeCommonPropertyAttributes(property); xmlWriter.writeEndElement(); } }
/** * Write either a {@code <Property>} or {@code <NavigationProperty>} element * for the given {@code StructuralProperty}. * * @param property The given structural property. It can not be {@code null}. * @throws javax.xml.stream.XMLStreamException If unable to write to stream */ public void write(StructuralProperty property) throws XMLStreamException { LOG.debug("Writing property {} of type {}", property.getName(), property.getTypeName()); if (property instanceof NavigationProperty) { NavigationProperty navProperty = (NavigationProperty) property; xmlWriter.writeStartElement(NAVIGATION_PROPERTY); writeCommonPropertyAttributes(property); if (!isNullOrEmpty(navProperty.getPartnerName())) { xmlWriter.writeAttribute(PARTNER, navProperty.getPartnerName()); } xmlWriter.writeEndElement(); } else { xmlWriter.writeStartElement(PROPERTY); writeCommonPropertyAttributes(property); xmlWriter.writeEndElement(); } }
private void writeAllProperties(final Object entity, StructuredType type, final XMLStreamWriter writer) throws ODataRenderException { visitProperties(getEntityDataModel(), type, property -> { try { if (!(property instanceof NavigationProperty)) { handleProperty(entity, property, writer); } } catch (XMLStreamException | ODataException | IllegalAccessException e) { throw new ODataRenderException("Error while writing property: " + property.getName(), e); } }); }
private void writeAllProperties(final Object entity, StructuredType type, final XMLStreamWriter writer) throws ODataRenderException { visitProperties(getEntityDataModel(), type, property -> { try { if (!(property instanceof NavigationProperty)) { handleProperty(entity, property, writer); } } catch (XMLStreamException | ODataException | IllegalAccessException e) { throw new ODataRenderException("Error while writing property: " + property.getName(), e); } }); }