Class EntityProvider

java.lang.Object
org.apache.olingo.odata2.api.ep.EntityProvider

public final class EntityProvider extends Object

Entity Provider

An EntityProvider provides all necessary read and write methods for accessing the entities defined in an Entity Data Model. Therefore this library provides (in its core packages) as convenience basic entity providers for accessing entities in the XML and JSON formats.

  • Constructor Details

    • EntityProvider

      public EntityProvider()
  • Method Details

    • writeErrorDocument

      public static ODataResponse writeErrorDocument(ODataErrorContext context)

      Serializes an error message according to the OData standard.

      An exception is not thrown because this method is used in exception handling.

      Parameters:
      context - contains error details see ODataErrorContext
      Returns:
      an ODataResponse containing the serialized error message
    • writeMetadata

      public static ODataResponse writeMetadata(List<Schema> schemas, Map<String,String> predefinedNamespaces) throws EntityProviderException
      Write metadata document in XML format for the given schemas and the provided predefined namespaces at the EDMX element. PredefinedNamespaces is of type Map<prefix,namespace> and may be null or an empty Map.
      Parameters:
      schemas - all XML schemas which will be written
      predefinedNamespaces - type of Map<prefix,namespace> and may be null or an empty Map
      Returns:
      resulting ODataResponse with written metadata content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeMetadata

      public static ODataResponse writeMetadata(DataServices serviceMetadata, Map<String,String> predefinedNamespaces) throws EntityProviderException
      Write metadata document in XML format for the given schemas and the provided predefined namespaces at the EDMX element. PredefinedNamespaces is of type Map<prefix,namespace> and may be null or an empty Map.
      Parameters:
      serviceMetadata -
      predefinedNamespaces - type of Map<prefix,namespace> and may be null or an empty Map
      Returns:
      resulting ODataResponse with written metadata content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeServiceDocument

      public static ODataResponse writeServiceDocument(String contentType, Edm edm, String serviceRoot) throws EntityProviderException
      Write service document based on given Edm and service root as given content type.
      Parameters:
      contentType - format in which service document should be written
      edm - entity data model to be written
      serviceRoot - service root for the written service document
      Returns:
      resulting ODataResponse with written service document content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writePropertyValue

      public static ODataResponse writePropertyValue(EdmProperty edmProperty, Object value) throws EntityProviderException
      Write property as content type application/octet-stream or text/plain.
      Parameters:
      edmProperty - entity data model for to be written property
      value - property which will be written
      Returns:
      resulting ODataResponse with written property value content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeText

      public static ODataResponse writeText(String value) throws EntityProviderException
      Write text value as content type text/plain.
      Parameters:
      value - text value which will be written
      Returns:
      resulting ODataResponse with written text/plain content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeBinary

      public static ODataResponse writeBinary(String mimeType, byte[] data) throws EntityProviderException
      Write binary content with content type header set to given mime type parameter.
      Parameters:
      mimeType - mime type which is written and used as content type header information.
      data - which is written to ODataResponse.
      Returns:
      response object resulting ODataResponse with written binary content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeFeed

      public static ODataResponse writeFeed(String contentType, EdmEntitySet entitySet, List<Map<String,Object>> data, EntityProviderWriteProperties properties) throws EntityProviderException
      Write given data (which is given in form of a List with a Map for each entity. Such a Map contains all properties [as property name to property value mapping] for the entry) in the specified format (given as contentType) based on given entity data model for an entity set (given as EdmEntitySet) and properties for this entity provider (given as EntityProviderWriteProperties).
      Parameters:
      contentType - format in which the feed should be written
      entitySet - entity data model for given entity data set
      data - set of entries in form of a List with a Map for each entity (such a Map contains all properties [as property name to property value mapping).
      properties - additional properties necessary for writing of data
      Returns:
      resulting ODataResponse with written feed content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeEntry

      public static ODataResponse writeEntry(String contentType, EdmEntitySet entitySet, Map<String,Object> data, EntityProviderWriteProperties properties) throws EntityProviderException
      Write given data (which is given in form of a Map for which contains all properties as property name to property value mapping) for the entry in the specified format (given as contentType) based on entity data model for an entity set (given as EdmEntitySet) and properties for this entity provider (given as EntityProviderWriteProperties).
      Parameters:
      contentType - format in which the entry should be written
      entitySet - entity data model for given entity data set
      data - which contains all properties as property name to property value mapping for the entry
      properties - additional properties necessary for writing of data
      Returns:
      resulting ODataResponse with written entry content
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeProperty

      public static ODataResponse writeProperty(String contentType, EdmProperty edmProperty, Object value) throws EntityProviderException
      Write given value (which is given in form of an Object) for the property in the specified format (given as contentType) based on given entity data model for an entity property (given as EdmProperty).
      Parameters:
      contentType - format in which the property should be written
      edmProperty - entity data model for given property
      value - data which is written
      Returns:
      resulting ODataResponse with written property content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeLink

      public static ODataResponse writeLink(String contentType, EdmEntitySet entitySet, Map<String,Object> data, EntityProviderWriteProperties properties) throws EntityProviderException
      Write link for key property based on entity data model for an entity set (given as EdmEntitySet) in the specified format (given as contentType). The necessary key property values must be provided within the data (in the form of property name to property value mapping) and properties for this entity provider must be set (given as EntityProviderWriteProperties).
      Parameters:
      contentType - format in which the entry should be written
      entitySet - entity data model for given entity data set
      data - which contains all key properties as property name to property value mapping for the entry
      properties - additional properties necessary for writing of data
      Returns:
      resulting ODataResponse with written link content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeLinks

      public static ODataResponse writeLinks(String contentType, EdmEntitySet entitySet, List<Map<String,Object>> data, EntityProviderWriteProperties properties) throws EntityProviderException
      Write all links for key property based on entity data model for an entity set (given as EdmEntitySet) in the specified format (given as contentType) for a set of entries. The necessary key property values must be provided within the data (in form of a List with a Map for each entry. Such a Map contains all key properties [as property name to property value mapping] for the entry) and properties for this entity provider must be set (given as EntityProviderWriteProperties).
      Parameters:
      contentType - format in which the entry should be written
      entitySet - entity data model for given entity data set
      data - set of entries in form of a List with a Map for each entry (such a Map contains all key properties [as property name to property value mapping).
      properties - additional properties necessary for writing of data
      Returns:
      resulting ODataResponse with written links content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • writeFunctionImport

      public static ODataResponse writeFunctionImport(String contentType, EdmFunctionImport functionImport, Object data, EntityProviderWriteProperties properties) throws EntityProviderException
      Write data result (given as Object) of function import based on return type of EdmFunctionImport in specified format (given as contentType). Additional properties for this entity provider must be set (given as EntityProviderWriteProperties).
      Parameters:
      contentType - format in which the entry should be written
      functionImport - entity data model for executed function import
      data - result of function import
      properties - additional properties necessary for writing of data
      Returns:
      resulting ODataResponse with written function import result content.
      Throws:
      EntityProviderException - if writing of data (serialization) fails
    • readFeed

      public static ODataFeed readFeed(String contentType, EdmEntitySet entitySet, InputStream content, EntityProviderReadProperties properties) throws EntityProviderException
      Read (de-serialize) a data feed from content (as InputStream) in specified format (given as contentType) based on entity data model (given as EdmEntitySet) and provide this data as ODataEntry .
      Parameters:
      contentType - format of content in the given input stream.
      entitySet - entity data model for entity set to be read
      content - feed data in form of an InputStream which contains the data in specified format
      properties - additional properties necessary for reading content from InputStream into Map. Must not be null.
      Returns:
      an ODataFeed object
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readDeltaFeed

      public static ODataDeltaFeed readDeltaFeed(String contentType, EdmEntitySet entitySet, InputStream content, EntityProviderReadProperties properties) throws EntityProviderException
      Read (de-serialize) a delta data feed from content (as InputStream) in specified format (given as contentType) based on entity data model (given as EdmEntitySet) and provide this data as ODataEntry .
      Parameters:
      contentType - format of content in the given input stream.
      entitySet - entity data model for entity set to be read
      content - feed data in form of an InputStream which contains the data in specified format
      properties - additional properties necessary for reading content from InputStream into Map. Must not be null.
      Returns:
      an ODataDeltaFeed object
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readEntry

      public static ODataEntry readEntry(String contentType, EdmEntitySet entitySet, InputStream content, EntityProviderReadProperties properties) throws EntityProviderException
      Read (de-serialize) data from content (as InputStream) in specified format (given as contentType) based on entity data model (given as EdmEntitySet) and provide this data as ODataEntry .
      Parameters:
      contentType - format of content in the given input stream.
      entitySet - entity data model for entity set to be read
      content - data in form of an InputStream which contains the data in specified format
      properties - additional properties necessary for reading content from InputStream into Map. Must not be null.
      Returns:
      entry as ODataEntry
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readProperty

      public static Map<String,Object> readProperty(String contentType, EdmProperty edmProperty, InputStream content, EntityProviderReadProperties properties) throws EntityProviderException
      Read (de-serialize) properties from content (as InputStream) in specified format (given as contentType) based on entity data model (given as EdmProperty) and provide this data as Map which contains the read data in form of property name to property value mapping.
      Parameters:
      contentType - format of content in the given input stream.
      edmProperty - entity data model for entity property to be read
      content - data in form of an InputStream which contains the data in specified format
      properties - additional properties necessary for reading content from InputStream into Map. Must not be null.
      Returns:
      property as name and value in a map
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readPropertyValue

      public static Object readPropertyValue(EdmProperty edmProperty, InputStream content) throws EntityProviderException
      Read (de-serialize) a property value from content (as InputStream) in format text/plain based on entity data model (given as EdmProperty) and provide this data as Object.
      Parameters:
      edmProperty - entity data model for entity property to be read
      content - data in form of an InputStream which contains the data in format text/plain
      Returns:
      property value as object
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readPropertyValue

      public static Object readPropertyValue(EdmProperty edmProperty, InputStream content, Class<?> typeMapping) throws EntityProviderException
      Read (de-serialize) a property value from content (as InputStream) in format text/plain based on entity data model (given as EdmProperty) and provide this data as Object.
      Parameters:
      edmProperty - entity data model for entity property to be read
      content - data in form of an InputStream which contains the data in format text/plain
      typeMapping - defines the mapping for this edm property to a java class which should be used during read of the content. If according edm property can not be read into given java class an EntityProviderException is thrown. Supported mappings are documented in EdmSimpleType.
      Returns:
      property value as object
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readFunctionImport

      public static Object readFunctionImport(String contentType, EdmFunctionImport functionImport, InputStream content, EntityProviderReadProperties properties) throws EntityProviderException
      Reads (de-serializes) function-import data from content (as InputStream) in specified format (given as contentType) based on entity data model (given as EdmFunctionImport) and provide this data as Object.
      Parameters:
      contentType - format of content in the given input stream.
      functionImport - entity data model for Function Import to be read
      content - data in form of an InputStream which contains the data in specified format
      properties - additional properties necessary for reading content from InputStream into Map. Must not be null.
      Returns:
      data as Object
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readLink

      public static String readLink(String contentType, EdmEntitySet entitySet, InputStream content) throws EntityProviderException
      Read (de-serialize) a link from content (as InputStream) in specified format (given as contentType) based on entity data model (given as EdmEntitySet) and provide the link as String.
      Parameters:
      contentType - format of content in the given input stream.
      entitySet - entity data model for entity property to be read
      content - data in form of an InputStream which contains the data in specified format
      Returns:
      link as string
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readLinks

      public static List<String> readLinks(String contentType, EdmEntitySet entitySet, InputStream content) throws EntityProviderException
      Read (de-serialize) a link collection from content (as InputStream) in specified format (given as contentType) based on entity data model (given as EdmEntitySet) and provide the links as List of Strings.
      Parameters:
      contentType - format of content in the given input stream.
      entitySet - entity data model for entity property to be read
      content - data in form of an InputStream which contains the data in specified format
      Returns:
      links as List of Strings
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readBinary

      public static byte[] readBinary(InputStream content) throws EntityProviderException
      Read (de-serialize) binary data from content (as InputStream) and provide it as byte[].
      Parameters:
      content - data in form of an InputStream which contains the binary data
      Returns:
      binary data as bytes
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readMetadata

      public static Edm readMetadata(InputStream metadataXml, boolean validate) throws EntityProviderException
      Read (de-serialize) data from metadata inputStream (as InputStream) and provide Edm as Edm
      Parameters:
      metadataXml - a metadata xml input stream (means the metadata document)
      validate - has to be true if metadata should be validated
      Returns:
      Edm as Edm
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readErrorDocument

      public static ODataErrorContext readErrorDocument(InputStream errorDocument, String contentType) throws EntityProviderException
      Read (de-serialize) data from error document as InputStream and provide according ODataErrorContext .
      Parameters:
      errorDocument - error document which is read
      contentType - format of content in the given input stream
      Returns:
      read error document
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • readServiceDocument

      public static ServiceDocument readServiceDocument(InputStream serviceDocument, String contentType) throws EntityProviderException
      Read (de-serialize) data from service document inputStream (as InputStream) and provide ServiceDocument as ServiceDocument
      Parameters:
      serviceDocument - the given input stream
      contentType - format of content in the given input stream
      Returns:
      ServiceDocument as ServiceDocument
      Throws:
      EntityProviderException - if reading of data (de-serialization) fails
    • parseBatchRequest

      public static List<BatchRequestPart> parseBatchRequest(String contentType, InputStream content, EntityProviderBatchProperties properties) throws BatchException
      Parse Batch Request body inputStream (as InputStream) and provide a list of Batch Request parts as BatchRequestPart
      Parameters:
      contentType - format of content in the given input stream
      content - request body
      properties - additional properties necessary for parsing. Must not be null.
      Returns:
      list of BatchRequestPart
      Throws:
      BatchException - if parsing fails
    • writeBatchResponse

      public static ODataResponse writeBatchResponse(List<BatchResponsePart> batchResponseParts) throws BatchException
      Write responses of Batch Response Parts in Batch Response as ODataResponse. Batch Response body matches one-to-one with the corresponding Batch Request body
      Parameters:
      batchResponseParts - a list of BatchResponsePart
      Returns:
      Batch Response as ODataResponse
      Throws:
      BatchException
    • writeBatchRequest

      public static InputStream writeBatchRequest(List<BatchPart> batchParts, String boundary)
      Create Batch Request body as InputStream.
      Parameters:
      batchParts - a list of BatchPartRequests BatchPart
      boundary -
      Returns:
      Batch Request as InputStream
    • parseBatchResponse

      public static List<BatchSingleResponse> parseBatchResponse(InputStream content, String contentType) throws BatchException
      Parse Batch Response body (as InputStream) and provide a list of single responses as BatchSingleResponse
      Parameters:
      content - response body
      contentType - format of content in the given input stream (inclusive boundary parameter)
      Returns:
      list of BatchSingleResponse
      Throws:
      BatchException