Package org.apache.olingo.odata2.api.ep
Class EntityProvider
- java.lang.Object
-
- org.apache.olingo.odata2.api.ep.EntityProvider
-
public final class EntityProvider extends Object
Entity Provider
An
EntityProviderprovides all necessary read and write methods for accessing the entities defined in anEntity Data Model. Therefore this library provides (in itscorepackages) as convenience basic entity providers for accessing entities in the XML and JSON formats.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceEntityProvider.EntityProviderInterface(Internal) interface for allEntityProvidernecessary read and write methods for accessing entities defined in anEntity Data Model.
-
Constructor Summary
Constructors Constructor Description EntityProvider()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<BatchRequestPart>parseBatchRequest(String contentType, InputStream content, EntityProviderBatchProperties properties)Parse Batch Request bodyinputStream(asInputStream) and provide a list of Batch Request parts asBatchRequestPartstatic List<BatchSingleResponse>parseBatchResponse(InputStream content, String contentType)Parse Batch Response body (asInputStream) and provide a list of single responses asBatchSingleResponsestatic byte[]readBinary(InputStream content)static ODataDeltaFeedreadDeltaFeed(String contentType, EdmEntitySet entitySet, InputStream content, EntityProviderReadProperties properties)Read (de-serialize) a delta data feed fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide this data asODataEntry.static ODataEntryreadEntry(String contentType, EdmEntitySet entitySet, InputStream content, EntityProviderReadProperties properties)Read (de-serialize) data fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide this data asODataEntry.static ODataErrorContextreadErrorDocument(InputStream errorDocument, String contentType)Read (de-serialize) data from error document asInputStreamand provide accordingODataErrorContext.static ODataFeedreadFeed(String contentType, EdmEntitySet entitySet, InputStream content, EntityProviderReadProperties properties)Read (de-serialize) a data feed fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide this data asODataEntry.static ObjectreadFunctionImport(String contentType, EdmFunctionImport functionImport, InputStream content, EntityProviderReadProperties properties)Reads (de-serializes) function-import data fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmFunctionImport) and provide this data asObject.static StringreadLink(String contentType, EdmEntitySet entitySet, InputStream content)Read (de-serialize) a link fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide the link asString.static List<String>readLinks(String contentType, EdmEntitySet entitySet, InputStream content)Read (de-serialize) a link collection fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide the links as List of Strings.static EdmreadMetadata(InputStream metadataXml, boolean validate)static Map<String,Object>readProperty(String contentType, EdmProperty edmProperty, InputStream content, EntityProviderReadProperties properties)Read (de-serialize) properties fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmProperty) and provide this data asMapwhich contains the read data in form ofproperty nametoproperty valuemapping.static ObjectreadPropertyValue(EdmProperty edmProperty, InputStream content)Read (de-serialize) a property value fromcontent(asInputStream) in formattext/plainbased onentity data model(given asEdmProperty) and provide this data asObject.static ObjectreadPropertyValue(EdmProperty edmProperty, InputStream content, Class<?> typeMapping)Read (de-serialize) a property value fromcontent(asInputStream) in formattext/plainbased onentity data model(given asEdmProperty) and provide this data asObject.static ServiceDocumentreadServiceDocument(InputStream serviceDocument, String contentType)Read (de-serialize) data from service documentinputStream(asInputStream) and provide ServiceDocument asServiceDocumentstatic InputStreamwriteBatchRequest(List<BatchPart> batchParts, String boundary)Create Batch Request body as InputStream.static ODataResponsewriteBatchResponse(List<BatchResponsePart> batchResponseParts)Write responses of Batch Response Parts in Batch Response asODataResponse.static ODataResponsewriteBinary(String mimeType, byte[] data)Write binary content with content type header set to givenmime typeparameter.static ODataResponsewriteEntry(String contentType, EdmEntitySet entitySet, Map<String,Object> data, EntityProviderWriteProperties properties)Write givendata(which is given in form of aMapfor which contains all properties asproperty nametoproperty valuemapping) for the entry in the specified format (given ascontentType) based onentity data model for an entity set(given asEdmEntitySet) andpropertiesfor this entity provider (given asEntityProviderWriteProperties).static ODataResponsewriteErrorDocument(ODataErrorContext context)Serializes an error message according to the OData standard.static ODataResponsewriteFeed(String contentType, EdmEntitySet entitySet, List<Map<String,Object>> data, EntityProviderWriteProperties properties)static ODataResponsewriteFunctionImport(String contentType, EdmFunctionImport functionImport, Object data, EntityProviderWriteProperties properties)Writedataresult (given asObject) of function import based onreturn typeofEdmFunctionImportin specified format (given ascontentType).static ODataResponsewriteLink(String contentType, EdmEntitySet entitySet, Map<String,Object> data, EntityProviderWriteProperties properties)Write link for key property based onentity data model for an entity set(given asEdmEntitySet) in the specified format (given ascontentType).static ODataResponsewriteLinks(String contentType, EdmEntitySet entitySet, List<Map<String,Object>> data, EntityProviderWriteProperties properties)Write all links for key property based onentity data model for an entity set(given asEdmEntitySet) in the specified format (given ascontentType) for a set of entries.static ODataResponsewriteMetadata(List<Schema> schemas, Map<String,String> predefinedNamespaces)Write metadata document in XML format for the given schemas and the provided predefined namespaces at the EDMX element.static ODataResponsewriteMetadata(DataServices serviceMetadata, Map<String,String> predefinedNamespaces)Write metadata document in XML format for the given schemas and the provided predefined namespaces at the EDMX element.static ODataResponsewriteProperty(String contentType, EdmProperty edmProperty, Object value)Write givenvalue(which is given in form of anObject) for the property in the specified format (given ascontentType) based on givenentity data model for an entity property(given asEdmProperty).static ODataResponsewritePropertyValue(EdmProperty edmProperty, Object value)Write property as content typeapplication/octet-streamortext/plain.static ODataResponsewriteServiceDocument(String contentType, Edm edm, String serviceRoot)Write service document based on givenEdmandservice rootas given content type.static ODataResponsewriteText(String value)Write text value as content typetext/plain.
-
-
-
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 seeODataErrorContext- Returns:
- an
ODataResponsecontaining 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 writtenpredefinedNamespaces- type of Map<prefix,namespace> and may be null or an empty Map- Returns:
- resulting
ODataResponsewith 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- MetadatapredefinedNamespaces- type of Map<prefix,namespace> and may be null or an empty Map- Returns:
- resulting
ODataResponsewith 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 givenEdmandservice rootas given content type.- Parameters:
contentType- format in which service document should be writtenedm- entity data model to be writtenserviceRoot- service root for the written service document- Returns:
- resulting
ODataResponsewith 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 typeapplication/octet-streamortext/plain.- Parameters:
edmProperty- entity data model for to be written propertyvalue- property which will be written- Returns:
- resulting
ODataResponsewith 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 typetext/plain.- Parameters:
value- text value which will be written- Returns:
- resulting
ODataResponsewith 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 givenmime typeparameter.- Parameters:
mimeType- mime type which is written and used as content type header information.data- which is written toODataResponse.- Returns:
- response object resulting
ODataResponsewith 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 givendata(which is given in form of aListwith aMapfor each entity. Such aMapcontains all properties [asproperty nametoproperty valuemapping] for the entry) in the specified format (given ascontentType) based on givenentity data model for an entity set(given asEdmEntitySet) andpropertiesfor this entity provider (given asEntityProviderWriteProperties).- Parameters:
contentType- format in which the feed should be writtenentitySet- entity data model for given entity data setdata- set of entries in form of aListwith aMapfor each entity (such aMapcontains all properties [asproperty nametoproperty valuemapping).properties- additional properties necessary for writing of data- Returns:
- resulting
ODataResponsewith 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 givendata(which is given in form of aMapfor which contains all properties asproperty nametoproperty valuemapping) for the entry in the specified format (given ascontentType) based onentity data model for an entity set(given asEdmEntitySet) andpropertiesfor this entity provider (given asEntityProviderWriteProperties).- Parameters:
contentType- format in which the entry should be writtenentitySet- entity data model for given entity data setdata- which contains all properties asproperty nametoproperty valuemapping for the entryproperties- additional properties necessary for writing of data- Returns:
- resulting
ODataResponsewith 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 givenvalue(which is given in form of anObject) for the property in the specified format (given ascontentType) based on givenentity data model for an entity property(given asEdmProperty).- Parameters:
contentType- format in which the property should be writtenedmProperty- entity data model for given propertyvalue- data which is written- Returns:
- resulting
ODataResponsewith 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 onentity data model for an entity set(given asEdmEntitySet) in the specified format (given ascontentType). The necessary key property values must be provided within thedata(in the form ofproperty nametoproperty valuemapping) andpropertiesfor this entity provider must be set (given asEntityProviderWriteProperties).- Parameters:
contentType- format in which the entry should be writtenentitySet- entity data model for given entity data setdata- which contains all key properties asproperty nametoproperty valuemapping for the entryproperties- additional properties necessary for writing of data- Returns:
- resulting
ODataResponsewith 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 onentity data model for an entity set(given asEdmEntitySet) in the specified format (given ascontentType) for a set of entries. The necessary key property values must be provided within thedata(in form of aListwith aMapfor each entry. Such aMapcontains all key properties [asproperty nametoproperty valuemapping] for the entry) andpropertiesfor this entity provider must be set (given asEntityProviderWriteProperties).- Parameters:
contentType- format in which the entry should be writtenentitySet- entity data model for given entity data setdata- set of entries in form of aListwith aMapfor each entry (such aMapcontains all key properties [asproperty nametoproperty valuemapping).properties- additional properties necessary for writing of data- Returns:
- resulting
ODataResponsewith 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
Writedataresult (given asObject) of function import based onreturn typeofEdmFunctionImportin specified format (given ascontentType). Additionalpropertiesfor this entity provider must be set (given asEntityProviderWriteProperties).- Parameters:
contentType- format in which the entry should be writtenfunctionImport- entity data model for executed function importdata- result of function importproperties- additional properties necessary for writing of data- Returns:
- resulting
ODataResponsewith 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 fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide this data asODataEntry.- Parameters:
contentType- format of content in the given input stream.entitySet- entity data model for entity set to be readcontent- feed data in form of anInputStreamwhich contains the data in specified formatproperties- additional properties necessary for reading content fromInputStreamintoMap. Must not be null.- Returns:
- an
ODataFeedobject - 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 fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide this data asODataEntry.- Parameters:
contentType- format of content in the given input stream.entitySet- entity data model for entity set to be readcontent- feed data in form of anInputStreamwhich contains the data in specified formatproperties- additional properties necessary for reading content fromInputStreamintoMap. Must not be null.- Returns:
- an
ODataDeltaFeedobject - 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 fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide this data asODataEntry.- Parameters:
contentType- format of content in the given input stream.entitySet- entity data model for entity set to be readcontent- data in form of anInputStreamwhich contains the data in specified formatproperties- additional properties necessary for reading content fromInputStreamintoMap. 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 fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmProperty) and provide this data asMapwhich contains the read data in form ofproperty nametoproperty valuemapping.- Parameters:
contentType- format of content in the given input stream.edmProperty- entity data model for entity property to be readcontent- data in form of anInputStreamwhich contains the data in specified formatproperties- additional properties necessary for reading content fromInputStreamintoMap. 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 fromcontent(asInputStream) in formattext/plainbased onentity data model(given asEdmProperty) and provide this data asObject.- Parameters:
edmProperty- entity data model for entity property to be readcontent- data in form of anInputStreamwhich contains the data in formattext/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 fromcontent(asInputStream) in formattext/plainbased onentity data model(given asEdmProperty) and provide this data asObject.- Parameters:
edmProperty- entity data model for entity property to be readcontent- data in form of anInputStreamwhich contains the data in formattext/plaintypeMapping- defines the mapping for thisedm propertyto ajava classwhich should be used during read of the content. If accordingedm propertycan not be read into givenjava classanEntityProviderExceptionis thrown. Supported mappings are documented inEdmSimpleType.- 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 fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmFunctionImport) and provide this data asObject.- Parameters:
contentType- format of content in the given input stream.functionImport- entity data model for Function Import to be readcontent- data in form of anInputStreamwhich contains the data in specified formatproperties- additional properties necessary for reading content fromInputStreamintoMap. 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 fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) and provide the link asString.- Parameters:
contentType- format of content in the given input stream.entitySet- entity data model for entity property to be readcontent- data in form of anInputStreamwhich 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 fromcontent(asInputStream) in specified format (given ascontentType) based onentity data model(given asEdmEntitySet) 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 readcontent- data in form of anInputStreamwhich 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
- Parameters:
content- data in form of anInputStreamwhich 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
- 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 asInputStreamand provide accordingODataErrorContext.- Parameters:
errorDocument- error document which is readcontentType- 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 documentinputStream(asInputStream) and provide ServiceDocument asServiceDocument- Parameters:
serviceDocument- the given input streamcontentType- 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 bodyinputStream(asInputStream) and provide a list of Batch Request parts asBatchRequestPart- Parameters:
contentType- format of content in the given input streamcontent- request bodyproperties- 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 asODataResponse. Batch Response body matches one-to-one with the corresponding Batch Request body- Parameters:
batchResponseParts- a list ofBatchResponsePart- Returns:
- Batch Response as
ODataResponse - Throws:
BatchException- Caso ocorra exceção
-
writeBatchRequest
public static InputStream writeBatchRequest(List<BatchPart> batchParts, String boundary)
Create Batch Request body as InputStream.- Parameters:
batchParts- a list of BatchPartRequestsBatchPartboundary- Boundary- Returns:
- Batch Request as InputStream
-
parseBatchResponse
public static List<BatchSingleResponse> parseBatchResponse(InputStream content, String contentType) throws BatchException
Parse Batch Response body (asInputStream) and provide a list of single responses asBatchSingleResponse- Parameters:
content- response bodycontentType- format of content in the given input stream (inclusive boundary parameter)- Returns:
- list of
BatchSingleResponse - Throws:
BatchException- Caso ocorra exceção
-
-