Java Code Examples for org.apache.olingo.commons.api.edm.EdmEntityType#hasStream()
The following examples show how to use
org.apache.olingo.commons.api.edm.EdmEntityType#hasStream() .
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: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void appendEntityTypes(JsonGenerator json, List<EdmEntityType> entityTypes) throws SerializerException, IOException { for (EdmEntityType entityType : entityTypes) { json.writeObjectFieldStart(entityType.getName()); json.writeStringField(KIND, Kind.EntityType.name()); if (entityType.hasStream()) { json.writeBooleanField(HAS_STREAM, entityType.hasStream()); } if (entityType.getBaseType() != null) { json.writeStringField(BASE_TYPE, getAliasedFullQualifiedName(entityType.getBaseType())); } if (entityType.isAbstract()) { json.writeBooleanField(ABSTRACT, entityType.isAbstract()); } appendKey(json, entityType); appendProperties(json, entityType); appendNavigationProperties(json, entityType); appendAnnotations(json, entityType, null); json.writeEndObject(); } }
Example 2
Source File: MetadataDocumentXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void appendEntityTypes(final XMLStreamWriter writer, final List<EdmEntityType> entityTypes) throws XMLStreamException { for (EdmEntityType entityType : entityTypes) { writer.writeStartElement(XML_ENTITY_TYPE); writer.writeAttribute(XML_NAME, entityType.getName()); if (entityType.hasStream()) { writer.writeAttribute(XML_HAS_STREAM, "" + entityType.hasStream()); } if (entityType.getBaseType() != null) { writer.writeAttribute(XML_BASE_TYPE, getAliasedFullQualifiedName(entityType.getBaseType(), false)); } if (entityType.isAbstract()) { writer.writeAttribute(ABSTRACT, TRUE); } if (entityType.isOpenType()) { writer.writeAttribute(OPEN_TYPE, TRUE); } appendKey(writer, entityType); appendProperties(writer, entityType); appendNavigationProperties(writer, entityType); appendAnnotations(writer, entityType); writer.writeEndElement(); } }
Example 3
Source File: TripPinDataModel.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void checkForMedia(Entity entity) throws ODataApplicationException { EdmEntityType type = this.metadata.getEdm().getEntityType( new FullQualifiedName(entity.getType())); if (!type.hasStream()) { throw new ODataApplicationException("No Media proeprty on the entity", 500, Locale.getDefault()); } }
Example 4
Source File: ODataJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
protected void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity, final ContextURL contextURL, final ExpandOption expand, Integer toDepth, final SelectOption select, final boolean onlyReference, Set<String> ancestors, String name, final JsonGenerator json) throws IOException, SerializerException, DecoderException { boolean cycle = false; if (expand != null) { if (ancestors == null) { ancestors = new HashSet<>(); } cycle = !ancestors.add(getEntityId(entity, entityType, name)); } try { json.writeStartObject(); if (!isODataMetadataNone) { // top-level entity if (contextURL != null) { writeContextURL(contextURL, json); writeMetadataETag(metadata, json); } if (entity.getETag() != null) { json.writeStringField(constants.getEtag(), entity.getETag()); } if (entityType.hasStream()) { if (entity.getMediaETag() != null) { json.writeStringField(constants.getMediaEtag(), entity.getMediaETag()); } if (entity.getMediaContentType() != null) { json.writeStringField(constants.getMediaContentType(), entity.getMediaContentType()); } if (entity.getMediaContentSource() != null) { json.writeStringField(constants.getMediaReadLink(), entity.getMediaContentSource().toString()); } if (entity.getMediaEditLinks() != null && !entity.getMediaEditLinks().isEmpty()) { json.writeStringField(constants.getMediaEditLink(), entity.getMediaEditLinks().get(0).getHref()); } } } if (cycle || onlyReference) { json.writeStringField(constants.getId(), getEntityId(entity, entityType, name)); } else { final EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType()); if ((!isODataMetadataNone && !resolvedType.equals(entityType)) || isODataMetadataFull) { json.writeStringField(constants.getType(), "#" + entity.getType()); } if ((!isODataMetadataNone && !areKeyPredicateNamesSelected(select, resolvedType)) || isODataMetadataFull) { json.writeStringField(constants.getId(), getEntityId(entity, resolvedType, name)); } if (isODataMetadataFull) { if (entity.getSelfLink() != null) { json.writeStringField(constants.getReadLink(), entity.getSelfLink().getHref()); } if (entity.getEditLink() != null) { json.writeStringField(constants.getEditLink(), entity.getEditLink().getHref()); } } writeProperties(metadata, resolvedType, entity.getProperties(), select, json, entity, expand); writeNavigationProperties(metadata, resolvedType, entity, expand, toDepth, ancestors, name, json); writeOperations(entity.getOperations(), json); } json.writeEndObject(); } finally { if (expand != null && !cycle && ancestors != null) { ancestors.remove(getEntityId(entity, entityType, name)); } } }
Example 5
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
protected void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity, final ContextURL contextURL, final ExpandOption expand, final Integer toDepth, final SelectOption select, final String xml10InvalidCharReplacement, final XMLStreamWriter writer, final boolean top, final boolean writeOnlyRef,String name, Set<String> ancestors) throws XMLStreamException, SerializerException { boolean cycle = false; if (expand != null) { if (ancestors == null) { ancestors = new HashSet<String>(); } cycle = !ancestors.add(getEntityId(entity, entityType, name)); } if (cycle || writeOnlyRef) { writeReference(entity, contextURL, writer, top); return; } try { writer.writeStartElement(ATOM, Constants.ATOM_ELEM_ENTRY, NS_ATOM); if (top) { writer.writeNamespace(ATOM, NS_ATOM); writer.writeNamespace(METADATA, NS_METADATA); writer.writeNamespace(DATA, NS_DATA); if (contextURL != null) { // top-level entity writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString()); writeMetadataETag(metadata, writer); } } if (entity.getETag() != null) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_ETAG, entity.getETag()); } if (entity.getId() != null) { writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_ID); writer.writeCharacters(entity.getId().toASCIIString()); writer.writeEndElement(); } writerAuthorInfo(entity.getTitle(), writer); if (entity.getId() != null) { writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_LINK); writer.writeAttribute(Constants.ATTR_REL, Constants.EDIT_LINK_REL); writer.writeAttribute(Constants.ATTR_HREF, entity.getId().toASCIIString()); writer.writeEndElement(); } if (entityType.hasStream()) { writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_CONTENT); writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType()); if (entity.getMediaContentSource() != null) { writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toString()); } else { String id = entity.getId().toASCIIString(); writer.writeAttribute(Constants.ATOM_ATTR_SRC, id + (id.endsWith("/") ? "" : "/") + "$value"); } writer.writeEndElement(); } // write media links for (Link link : entity.getMediaEditLinks()) { writeLink(writer, link); } EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType()); writeNavigationProperties(metadata, resolvedType, entity, expand, toDepth, xml10InvalidCharReplacement, ancestors, name, writer); writer.writeStartElement(ATOM, Constants.ATOM_ELEM_CATEGORY, NS_ATOM); writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, Constants.NS_SCHEME); writer.writeAttribute(Constants.ATOM_ATTR_TERM, "#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString()); writer.writeEndElement(); // In the case media, content is sibiling if (!entityType.hasStream()) { writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_CONTENT); writer.writeAttribute(Constants.ATTR_TYPE, "application/xml"); } writer.writeStartElement(METADATA, Constants.PROPERTIES, NS_METADATA); writeProperties(metadata, resolvedType, entity.getProperties(), select, xml10InvalidCharReplacement, writer, entity, expand); writer.writeEndElement(); // properties if (!entityType.hasStream()) { // content writer.writeEndElement(); } writeOperations(entity.getOperations(), writer); writer.writeEndElement(); // entry } finally { if (!cycle && ancestors != null) { ancestors.remove(getEntityId(entity, entityType, name)); } } }