Java Code Examples for org.apache.olingo.commons.api.edm.EdmProperty#isPrimitive()
The following examples show how to use
org.apache.olingo.commons.api.edm.EdmProperty#isPrimitive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataProvider.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private Property createProperty(final EdmProperty edmProperty, final String propertyName) throws DataProviderException { final EdmType type = edmProperty.getType(); Property newProperty; if (edmProperty.isPrimitive() || type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) { newProperty = edmProperty.isCollection() ? DataCreator.createPrimitiveCollection(propertyName) : DataCreator.createPrimitive(propertyName, null); } else { if (edmProperty.isCollection()) { @SuppressWarnings("unchecked") Property newProperty2 = DataCreator.createComplexCollection(propertyName, edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString()); newProperty = newProperty2; } else { newProperty = DataCreator.createComplex(propertyName, edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString()); createProperties((EdmComplexType) type, newProperty.asComplex().getValue()); } } return newProperty; }
Example 2
Source File: ODataJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected void writeProperties(final ServiceMetadata metadata, final EdmStructuredType type, final List<Property> properties, final SelectOption select, final JsonGenerator json, Linked linked, ExpandOption expand) throws IOException, SerializerException { final boolean all = ExpandSelectHelper.isAll(select); final Set<String> selected = all ? new HashSet<>() : ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems()); addKeyPropertiesToSelected(selected, type); Set<List<String>> expandedPaths = ExpandSelectHelper.getExpandedItemsPath(expand); for (final String propertyName : type.getPropertyNames()) { if (all || selected.contains(propertyName)) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); final Property property = findProperty(propertyName, properties); final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null : ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName); writeProperty(metadata, edmProperty, property, selectedPaths, json, expandedPaths, linked, expand); } } }
Example 3
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected void writeProperties(final ServiceMetadata metadata, final EdmStructuredType type, final List<Property> properties, final SelectOption select, final JsonGenerator json) throws IOException, SerializerException { final boolean all = ExpandSelectHelper.isAll(select); final Set<String> selected = all ? new HashSet<>() : ExpandSelectHelper.getSelectedPropertyNames(select .getSelectItems()); for (final String propertyName : type.getPropertyNames()) { if ((all || selected.contains(propertyName)) && !properties.isEmpty()) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); final Property property = findProperty(propertyName, properties); final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null : ExpandSelectHelper .getSelectedPaths(select.getSelectItems(), propertyName); writeProperty(metadata, edmProperty, property, selectedPaths, json); } } }
Example 4
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected void writeProperties(final ServiceMetadata metadata, final EdmStructuredType type, final List<Property> properties, final SelectOption select, final JsonGenerator json) throws IOException, SerializerException { final boolean all = ExpandSelectHelper.isAll(select); final Set<String> selected = all ? new HashSet<>() : ExpandSelectHelper.getSelectedPropertyNames(select .getSelectItems()); for (final String propertyName : type.getPropertyNames()) { if (all || selected.contains(propertyName)) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); final Property property = findProperty(propertyName, properties); final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null : ExpandSelectHelper .getSelectedPaths(select.getSelectItems(), propertyName); writeProperty(metadata, edmProperty, property, selectedPaths, json); } } }
Example 5
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected void writeProperties(final ServiceMetadata metadata, final EdmStructuredType type, final List<Property> properties, final SelectOption select, final String xml10InvalidCharReplacement, final XMLStreamWriter writer, Linked linked, ExpandOption expand) throws XMLStreamException, SerializerException { final boolean all = ExpandSelectHelper.isAll(select); final Set<String> selected = all ? new HashSet<String>() : ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems()); addKeyPropertiesToSelected(selected, type); Set<List<String>> expandedPaths = ExpandSelectHelper.getExpandedItemsPath(expand); for (final String propertyName : type.getPropertyNames()) { if (all || selected.contains(propertyName)) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); final Property property = findProperty(propertyName, properties); final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null : ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName); writeProperty(metadata, edmProperty, property, selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand); } } }
Example 6
Source File: ODataJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void writePropertyType(final EdmProperty edmProperty, JsonGenerator json) throws SerializerException, IOException { if (!isODataMetadataFull) { return; } String typeName = edmProperty.getName() + constants.getType(); final EdmType type = edmProperty.getType(); if (type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) { if (edmProperty.isCollection()) { json.writeStringField(typeName, "#Collection(" + type.getFullQualifiedName().getFullQualifiedNameAsString() + ")"); } else { json.writeStringField(typeName, "#" + type.getFullQualifiedName().getFullQualifiedNameAsString()); } } else if (edmProperty.isPrimitive()) { if (edmProperty.isCollection()) { json.writeStringField(typeName, "#Collection(" + type.getFullQualifiedName().getName() + ")"); } else { // exclude the properties that can be heuristically determined if (type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean) && type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double) && type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)) { json.writeStringField(typeName, "#" + type.getFullQualifiedName().getName()); } } } else if (type.getKind() == EdmTypeKind.COMPLEX) { // non-collection case written in writeComplex method directly. if (edmProperty.isCollection()) { json.writeStringField(typeName, "#Collection(" + type.getFullQualifiedName().getFullQualifiedNameAsString() + ")"); } } else { throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName()); } }
Example 7
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void writePropertyValue(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException { final EdmType type = edmProperty.getType(); try { if (edmProperty.isPrimitive() || type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) { if (edmProperty.isCollection()) { writePrimitiveCollection((EdmPrimitiveType) type, property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json); } else { writePrimitive((EdmPrimitiveType) type, property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json); } } else if (property.isComplex()) { if (edmProperty.isCollection()) { writeComplexCollection(metadata, (EdmComplexType) type, property, selectedPaths, json); } else { writeComplex(metadata, (EdmComplexType) type, property, selectedPaths, json); } } else { throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName()); } } catch (final EdmPrimitiveTypeException e) { throw new SerializerException("Wrong value for property!", e, SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), property.getValue().toString()); } }
Example 8
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void writePropertyValue(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException { final EdmType type = edmProperty.getType(); try { if (edmProperty.isPrimitive() || type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) { if (edmProperty.isCollection()) { writePrimitiveCollection((EdmPrimitiveType) type, property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json); } else { writePrimitive((EdmPrimitiveType) type, property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json); } } else if (property.isComplex()) { if (edmProperty.isCollection()) { writeComplexCollection(metadata, (EdmComplexType) type, property, selectedPaths, json); } else { writeComplex(metadata, (EdmComplexType) type, property, selectedPaths, json); } } else { throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName()); } } catch (final EdmPrimitiveTypeException e) { throw new SerializerException("Wrong value for property!", e, SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), property.getValue().toString()); } }
Example 9
Source File: ResourcePathParser.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private UriResource navigationOrProperty(final UriResource previous) throws UriParserException, UriValidationException { final String name = tokenizer.getText(); UriResourcePartTyped previousTyped = null; EdmStructuredType structType = null; requireTyped(previous, name); if (((UriResourcePartTyped) previous).getType() instanceof EdmStructuredType) { previousTyped = (UriResourcePartTyped) previous; final EdmType previousTypeFilter = getPreviousTypeFilter(previousTyped); structType = (EdmStructuredType) (previousTypeFilter == null ? previousTyped.getType() : previousTypeFilter); } else { throw new UriParserSemanticException( "Cannot parse '" + name + "'; previous path segment is not a structural type.", UriParserSemanticException.MessageKeys.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE, name); } if (previousTyped.isCollection()) { throw new UriParserSemanticException("Property '" + name + "' is not allowed after collection.", UriParserSemanticException.MessageKeys.PROPERTY_AFTER_COLLECTION, name); } final EdmProperty property = structType.getStructuralProperty(name); if (property != null) { return property.isPrimitive() || property.getType().getKind() == EdmTypeKind.ENUM || property.getType().getKind() == EdmTypeKind.DEFINITION ? new UriResourcePrimitivePropertyImpl(property) : new UriResourceComplexPropertyImpl(property); } final EdmNavigationProperty navigationProperty = structType.getNavigationProperty(name); if (navigationProperty == null) { throw new UriParserSemanticException("Property '" + name + "' not found in type '" + structType.getFullQualifiedName().getFullQualifiedNameAsString() + "'", UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE, structType.getFullQualifiedName().getFullQualifiedNameAsString(), name); } List<UriParameter> keyPredicate = ParserHelper.parseNavigationKeyPredicate(tokenizer, navigationProperty, edm, null, aliases); ParserHelper.requireTokenEnd(tokenizer); return new UriResourceNavigationPropertyImpl(navigationProperty) .setKeyPredicates(keyPredicate); }
Example 10
Source File: SelectParser.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void addSelectPath(UriTokenizer tokenizer, final EdmStructuredType referencedType, UriInfoImpl resource) throws UriParserException { final String name = tokenizer.getText(); final EdmProperty property = referencedType.getStructuralProperty(name); if (property == null) { final EdmNavigationProperty navigationProperty = referencedType.getNavigationProperty(name); if (navigationProperty == null) { throw new UriParserSemanticException("Selected property not found.", UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE, referencedType.getName(), name); } else { resource.addResourcePart(new UriResourceNavigationPropertyImpl(navigationProperty)); } } else if (property.isPrimitive() || property.getType().getKind() == EdmTypeKind.ENUM || property.getType().getKind() == EdmTypeKind.DEFINITION) { resource.addResourcePart(new UriResourcePrimitivePropertyImpl(property)); } else { UriResourceComplexPropertyImpl complexPart = new UriResourceComplexPropertyImpl(property); resource.addResourcePart(complexPart); if (tokenizer.next(TokenKind.SLASH)) { if (tokenizer.next(TokenKind.QualifiedName)) { final FullQualifiedName qualifiedName = new FullQualifiedName(tokenizer.getText()); final EdmComplexType type = edm.getComplexType(qualifiedName); if (type == null) { throw new UriParserSemanticException("Type not found.", UriParserSemanticException.MessageKeys.UNKNOWN_TYPE, qualifiedName.getFullQualifiedNameAsString()); } else if (type.compatibleTo(property.getType())) { complexPart.setTypeFilter(type); if (tokenizer.next(TokenKind.SLASH)) { if (tokenizer.next(TokenKind.ODataIdentifier)) { addSelectPath(tokenizer, type, resource); } else { throw new UriParserSemanticException("Unknown part after '/'.", UriParserSemanticException.MessageKeys.UNKNOWN_PART, ""); } } } else { throw new UriParserSemanticException("The type cast is not compatible.", UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, type.getName()); } } else if (tokenizer.next(TokenKind.ODataIdentifier)) { addSelectPath(tokenizer, (EdmStructuredType) property.getType(), resource); } else if (tokenizer.next(TokenKind.SLASH)) { throw new UriParserSyntaxException("Illegal $select expression.", UriParserSyntaxException.MessageKeys.SYNTAX); } else { throw new UriParserSemanticException("Unknown part after '/'.", UriParserSemanticException.MessageKeys.UNKNOWN_PART, ""); } } } }
Example 11
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void appendProperties(final JsonGenerator json, final EdmStructuredType type) throws SerializerException, IOException { List<String> propertyNames = new ArrayList<>(type.getPropertyNames()); if (type.getBaseType() != null) { propertyNames.removeAll(type.getBaseType().getPropertyNames()); } for (String propertyName : propertyNames) { EdmProperty property = type.getStructuralProperty(propertyName); json.writeObjectFieldStart(propertyName); String fqnString; if (property.isPrimitive()) { fqnString = getFullQualifiedName(property.getType()); } else { fqnString = getAliasedFullQualifiedName(property.getType()); } json.writeStringField(TYPE, fqnString); if (property.isCollection()) { json.writeBooleanField(COLLECTION, property.isCollection()); } // Facets if (!property.isNullable()) { json.writeBooleanField(NULLABLE, property.isNullable()); } if (!property.isUnicode()) { json.writeBooleanField(UNICODE, property.isUnicode()); } if (property.getDefaultValue() != null) { json.writeStringField(DEFAULT_VALUE, property.getDefaultValue()); } if (property.getMaxLength() != null) { json.writeNumberField(MAX_LENGTH, property.getMaxLength()); } if (property.getPrecision() != null) { json.writeNumberField(PRECISION, property.getPrecision()); } if (property.getScale() != null) { json.writeNumberField(SCALE, property.getScale()); } if (property.getSrid() != null) { json.writeStringField(SRID, "" + property.getSrid()); } appendAnnotations(json, property, null); json.writeEndObject(); } }
Example 12
Source File: ODataJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private boolean isStreamProperty(EdmProperty edmProperty) { final EdmType type = edmProperty.getType(); return (edmProperty.isPrimitive() && type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Stream)); }
Example 13
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private boolean isStreamProperty(EdmProperty edmProperty) { final EdmType type = edmProperty.getType(); return (edmProperty.isPrimitive() && type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Stream)); }
Example 14
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private boolean isStreamProperty(EdmProperty edmProperty) { final EdmType type = edmProperty.getType(); return (edmProperty.isPrimitive() && type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Stream)); }
Example 15
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void writePropertyValue(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 { try { if (edmProperty.isPrimitive() || edmProperty.getType().getKind() == EdmTypeKind.ENUM || edmProperty.getType().getKind() == EdmTypeKind.DEFINITION) { if (edmProperty.isCollection()) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, edmProperty.isPrimitive() ? "#Collection(" + edmProperty.getType().getName() + ")" : collectionType(edmProperty.getType())); writePrimitiveCollection((EdmPrimitiveType) edmProperty.getType(), property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), xml10InvalidCharReplacement,writer); } else { writePrimitive((EdmPrimitiveType) edmProperty.getType(), property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), xml10InvalidCharReplacement, writer); } } else if (property.isComplex()) { if (edmProperty.isCollection()) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, collectionType(edmProperty.getType())); writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand); } else { writeComplex(metadata, edmProperty, property, selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand); } } else { throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName()); } } catch (final EdmPrimitiveTypeException e) { throw new SerializerException("Wrong value for property!", e, SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), property.getValue().toString()); } }
Example 16
Source File: MetadataDocumentXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void appendProperties(final XMLStreamWriter writer, final EdmStructuredType type) throws XMLStreamException { List<String> propertyNames = new ArrayList<>(type.getPropertyNames()); if (type.getBaseType() != null) { propertyNames.removeAll(type.getBaseType().getPropertyNames()); } for (String propertyName : propertyNames) { EdmProperty property = type.getStructuralProperty(propertyName); writer.writeStartElement(XML_PROPERTY); writer.writeAttribute(XML_NAME, propertyName); String fqnString; if (property.isPrimitive()) { fqnString = getFullQualifiedName(property.getType(), property.isCollection()); } else { fqnString = getAliasedFullQualifiedName(property.getType(), property.isCollection()); } writer.writeAttribute(XML_TYPE, fqnString); // Facets if (!property.isNullable()) { writer.writeAttribute(XML_NULLABLE, "" + property.isNullable()); } if (!property.isUnicode()) { writer.writeAttribute(XML_UNICODE, "" + property.isUnicode()); } if (property.getDefaultValue() != null) { writer.writeAttribute(XML_DEFAULT_VALUE, property.getDefaultValue()); } if (property.getMaxLength() != null) { writer.writeAttribute(XML_MAX_LENGTH, "" + property.getMaxLength()); } if (property.getPrecision() != null) { writer.writeAttribute(XML_PRECISION, "" + property.getPrecision()); } if (property.getScale() != null) { writer.writeAttribute(XML_SCALE, "" + property.getScale()); } if (property.getSrid() != null) { writer.writeAttribute(XML_SRID, "" + property.getSrid()); } appendAnnotations(writer, property); writer.writeEndElement(); } }