Class ODataService

java.lang.Object
com.hybris.ymkt.common.odata.ODataService

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

  • Constructor Details

    • ODataService

      public ODataService()
  • Method Details

    • bufferStream

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

      protected void checkStatus(HttpURLConnectionResponse response) throws IOException
      Throws:
      IOException
    • convertMapToJSON

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

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

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

      public Map<String,String> convertMapToURIParameters(String functionImportName, Map<String,Object> data) throws 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&gt Name and value to be converted.
      Returns:
      Map containing the <Parameter&gt Name and converted value.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
      • EdmLiteralKind.URI
    • convertObjectToJsonElement

      @Nonnull protected com.google.gson.JsonElement convertObjectToJsonElement(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(Object value, org.apache.olingo.odata2.api.edm.EdmNavigationProperty navigation) throws org.apache.olingo.odata2.api.edm.EdmException, IOException
      Throws:
      org.apache.olingo.odata2.api.edm.EdmException
      IOException
    • convertObjectToString

      @Nullable protected String convertObjectToString(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 String createResourcePath(String entitySetName, Map<String,Object> data) throws IOException
      Create $batch part URL accessing entity by keys for Addressing Entries.
      Parameters:
      entitySetName - <EntitySet Name&gt value found in the DefaultEntityContainer of the OData service.
      data - Map containing the <Property/NavigationProperty Name&gt and value to be converted.
      Returns:
      resource path
      Throws:
      IOException - if an I/O error occurs.
    • createURL

      @Nonnull public URL createURL(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 URL createURL(String resourcePath, Map<String,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 URL createURL(String resourcePath, 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 IOException
      Throws:
      IOException
    • executeWithBasicAuth

      @Nonnull protected HttpURLConnectionResponse executeWithBasicAuth(HttpURLConnectionRequest request) throws IOException
      Execute the request with Authorization : "Basic BASE64user:pass".
      Using this method will create a new http session (unnecessary cost) on the yMKT side.
      It is preferable to use executeWithRetry(HttpURLConnectionRequest) for most execution scenarios.
      Parameters:
      request - HttpURLConnectionRequest to execute.
      Returns:
      HttpURLConnectionResponse executed.
      Throws:
      IOException - If the HTTP request was not successful.
      See Also:
    • executeWithRetry

      @Nonnull public HttpURLConnectionResponse executeWithRetry(HttpURLConnectionRequest request) throws IOException
      Execute the request with "cookie" & "x-csrf-token".
      If the existing session and/or token expired, those are refreshed and the request is re-tried.
      Parameters:
      request - HttpURLConnectionRequest to execute.
      Returns:
      HttpURLConnectionResponse executed.
      Throws:
      IOException - If the HTTP request was not successful.
    • filter

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

      @Nonnull protected StringBuilder getCustomQueryOptions()
    • getEdm

      @Nonnull public org.apache.olingo.odata2.api.edm.Edm getEdm() throws 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:
      IOException - If Edm could not be returned.
    • getEntitySet

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

      @Nonnull protected ODataService.TokenCache getTokenCache() throws IOException
      Throws:
      IOException
    • refreshToken

      @Nonnull protected ODataService.TokenCache refreshToken(ODataService.TokenCache token) throws IOException
      Throws:
      IOException
    • getPassword

      public String getPassword()
      Parameters:
      password - Password used to login with setUser(String) at the setRootUrl(String) address.
    • getRootUrl

      public String getRootUrl()
      Parameters:
      rootUrl - OData service root URL.
    • getUser

      public String getUser()
      Parameters:
      user - Username used to login at the setRootUrl(String) address.
    • setHttpURLConnectionService

      public void setHttpURLConnectionService(HttpURLConnectionService httpURLConnectionService)
    • setODataConvertEdmService

      public void setODataConvertEdmService(ODataConvertEdmService oDataConvertEdmService)
    • setPassword

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

      public void setProxy(String proxy) throws MalformedURLException
      Throws:
      MalformedURLException
    • setRootUrl

      public void setRootUrl(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(String sapClient)
      Parameters:
      sapClient - the sapClient to set
    • setUser

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