Class ODataService


  • public class ODataService
    extends java.lang.Object
    This bean shall be instantiated for each OData service as separate $metadata are used by OData services.
    • Field Detail

      • edmxProvider

        protected volatile org.apache.olingo.odata2.core.edm.provider.EdmxProvider edmxProvider
      • password

        protected java.lang.String password
      • proxy

        protected java.net.Proxy proxy
      • rootUrl

        protected java.lang.String rootUrl
      • sapClient

        protected java.lang.String sapClient
      • user

        protected java.lang.String user
    • Constructor Detail

      • ODataService

        public ODataService()
    • Method Detail

      • bufferStream

        @Nonnull
        public byte[] bufferStream​(java.io.InputStream stream)
                            throws java.io.IOException
        Read InputStream and return a byte array.
        Parameters:
        stream - InputStream to read.
        Returns:
        All bytes that could be read from the InputStream
        Throws:
        java.io.IOException - from InputStream.read(byte[])
        See Also:
        HttpURLConnectionService.bufferStream(InputStream)
      • checkStatus

        protected void checkStatus​(HttpURLConnectionResponse response)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • convertMapToJSON

        @Nonnull
        protected com.google.gson.JsonObject convertMapToJSON​(org.apache.olingo.odata2.api.edm.EdmEntityType entityType,
                                                              java.util.Map<?,​?> data)
                                                       throws java.io.IOException,
                                                              org.apache.olingo.odata2.api.edm.EdmException
        Throws:
        java.io.IOException
        org.apache.olingo.odata2.api.edm.EdmException
      • convertMapToJSONPayload

        @Nonnull
        public byte[] convertMapToJSONPayload​(java.lang.String entitySetName,
                                              java.util.Map<java.lang.String,​java.lang.Object> data)
                                       throws java.io.IOException
        Convert an entity map into a JSON payload reading to be transfered.
        Parameters:
        entitySetName - <EntitySet Name> value found in the DefaultEntityContainer of the OData service.
        data - Map containing the <Property/NavigationProperty Name> and value to be converted.
        Returns:
        byte array of the JSON payload.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        EdmLiteralKind.JSON
      • convertMapToJSONString

        @Nonnull
        public java.lang.String convertMapToJSONString​(org.apache.olingo.odata2.api.edm.EdmEntityType entityType,
                                                       java.util.Map<java.lang.String,​java.lang.Object> data)
                                                throws java.io.IOException
        Convert an entity map into a JSON String.
        Parameters:
        entityType - EdmEntityType of the OData entity to be converted.
        data - Map containing the <Parameter> Name and value to be converted.
        Returns:
        String of the JSON payload.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        EdmLiteralKind.JSON
      • convertMapToURIParameters

        public java.util.Map<java.lang.String,​java.lang.String> convertMapToURIParameters​(java.lang.String functionImportName,
                                                                                                java.util.Map<java.lang.String,​java.lang.Object> data)
                                                                                         throws java.io.IOException
        Build properly formated String value arguments for OData Function Import.
        Parameters:
        functionImportName - Attribute Name value found in the <FunctionImport> of the OData service.
        data - Map containing the <Parameter> Name and value to be converted.
        Returns:
        Map containing the <Parameter> Name and converted value.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        EdmLiteralKind.URI
      • convertObjectToJsonElement

        @Nonnull
        protected com.google.gson.JsonElement convertObjectToJsonElement​(java.lang.Object value,
                                                                         org.apache.olingo.odata2.api.edm.EdmElement element)
                                                                  throws org.apache.olingo.odata2.api.edm.EdmException
        Throws:
        org.apache.olingo.odata2.api.edm.EdmException
      • convertObjectToJsonElement

        protected com.google.gson.JsonElement convertObjectToJsonElement​(java.lang.Object value,
                                                                         org.apache.olingo.odata2.api.edm.EdmNavigationProperty navigation)
                                                                  throws org.apache.olingo.odata2.api.edm.EdmException,
                                                                         java.io.IOException
        Throws:
        org.apache.olingo.odata2.api.edm.EdmException
        java.io.IOException
      • convertObjectToString

        @Nullable
        protected java.lang.String convertObjectToString​(java.lang.Object value,
                                                         org.apache.olingo.odata2.api.edm.EdmLiteralKind literalKind,
                                                         org.apache.olingo.odata2.api.edm.EdmElement element)
                                                  throws org.apache.olingo.odata2.api.edm.EdmException
        Throws:
        org.apache.olingo.odata2.api.edm.EdmException
      • createResourcePath

        public java.lang.String createResourcePath​(java.lang.String entitySetName,
                                                   java.util.Map<java.lang.String,​java.lang.Object> data)
                                            throws java.io.IOException
        Create $batch part URL accessing entity by keys for Addressing Entries.
        Parameters:
        entitySetName - <EntitySet Name> value found in the DefaultEntityContainer of the OData service.
        data - Map containing the <Property/NavigationProperty Name> and value to be converted.
        Returns:
        resource path
        Throws:
        java.io.IOException - if an I/O error occurs.
      • createURL

        @Nonnull
        public java.net.URL createURL​(java.lang.String resourcePath)
        Create an absolute URL accessing the OData service at the resource path provided.
        Parameters:
        resourcePath - Resource path of the OData service.
        Returns:
        URL
      • createURL

        @Nonnull
        public java.net.URL createURL​(java.lang.String resourcePath,
                                      java.util.Map<java.lang.String,​java.lang.String> queryOptions)
        Create an absolute URL accessing the OData service at the resourcePath provided using OData query options.
        Parameters:
        resourcePath - Resource path of the OData service.
        queryOptions - OData Query String Options.
        Returns:
        URL
      • createURL

        @Nonnull
        public java.net.URL createURL​(java.lang.String resourcePath,
                                      java.lang.String... queryOptions)
        Create an absolute URL accessing the OData service at the resourcePath provided using OData query options.
        Parameters:
        resourcePath - Resource path of the OData service.
        queryOptions - OData Query String Options.
        Returns:
        URL
      • decompressIfGZIP

        @Nonnull
        protected byte[] decompressIfGZIP​(byte[] payload)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • filter

        public ODataFilterBuilder filter​(java.lang.String entitySetName)
                                  throws java.io.IOException
        Create an ODataFilterBuilder starting on the entitySetName provided.
        Parameters:
        entitySetName - <EntitySet Name> value found in the DefaultEntityContainer of the OData service.
        Returns:
        ODataFilterBuilder
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getCustomQueryOptions

        @Nonnull
        protected java.lang.StringBuilder getCustomQueryOptions()
      • getEdm

        @Nonnull
        public org.apache.olingo.odata2.api.edm.Edm getEdm()
                                                    throws java.io.IOException
        Provide buffered olingo's Edm of the OData service.
        Returns:
        And instance of Edm $metadata for the service end point set by setRootUrl(String).
        This resource is requested once for the entire lifecycle of the bean. This resource is also synchronized.
        Each Thread has its own instance of Edm.
        Throws:
        java.io.IOException - If Edm could not be returned.
      • getEntitySet

        public org.apache.olingo.odata2.api.edm.EdmEntitySet getEntitySet​(java.lang.String entitySetName)
                                                                   throws java.io.IOException
        Simple wrapping with improved error handling of :
        this.getEdm().getDefaultEntityContainer().getEntitySet(entitySetName);
        Parameters:
        entitySetName - <EntitySet Name> value found in the DefaultEntityContainer of the OData service.
        Returns:
        EdmEntitySet
        Throws:
        java.io.IOException - In case of communication errors.
      • getTokenCache

        @Nonnull
        protected ODataService.TokenCache getTokenCache()
                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • setHttpURLConnectionService

        public void setHttpURLConnectionService​(HttpURLConnectionService httpURLConnectionService)
      • setODataConvertEdmService

        public void setODataConvertEdmService​(ODataConvertEdmService oDataConvertEdmService)
      • setPassword

        public void setPassword​(java.lang.String password)
        Parameters:
        password - Password used to login with setUser(String) at the setRootUrl(String) address.
      • setProxy

        public void setProxy​(java.lang.String proxy)
                      throws java.net.MalformedURLException
        Throws:
        java.net.MalformedURLException
      • setRootUrl

        public void setRootUrl​(java.lang.String rootUrl)
        Parameters:
        rootUrl - OData service root URL.
        Sample : https://localhost:50100/sap/opu/odata/sap/PROD_RECO_RUNTIME_SRV/
        localhost should be replaced with the proper SAP Marketing server host name.
      • setSapClient

        public void setSapClient​(java.lang.String sapClient)
        Parameters:
        sapClient - the sapClient to set
      • setUser

        public void setUser​(java.lang.String user)
        Parameters:
        user - Username used to login at the setRootUrl(String) address.