Class 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 Detail

      • EntityProvider

        public EntityProvider()
    • Method Detail

      • 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 - Metadata
        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
      • 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
      • 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
      • 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
      • 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
      • writeBatchRequest

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