Class FluentHelperFunction<FluentHelperT,ObjectT,ResultT>

java.lang.Object
com.sap.cloud.sdk.datamodel.odata.helper.FluentHelperBasic<FluentHelperT,ObjectT,ResultT>
com.sap.cloud.sdk.datamodel.odata.helper.FluentHelperFunction<FluentHelperT,ObjectT,ResultT>
Type Parameters:
FluentHelperT - The fluent helper type.
ObjectT - The type of the object this OData request operates on, if any.
ResultT - The type of the result entity, if any.
All Implemented Interfaces:
FluentHelperExecutable<Object>
Direct Known Subclasses:
CollectionValuedFluentHelperFunction, SingleValuedFluentHelperFunction

public abstract class FluentHelperFunction<FluentHelperT,ObjectT,ResultT> extends FluentHelperBasic<FluentHelperT,ObjectT,ResultT>
Representation of any OData function import as a fluent interface for further configuring the request and executing it.
  • Constructor Details

    • FluentHelperFunction

      public FluentHelperFunction(@Nonnull String servicePath)
      Instantiates this fluent helper using the given service path to send the requests.
      Parameters:
      servicePath - The service path to direct the requests to.
  • Method Details

    • getCsrfTokenRetriever

      @Nonnull protected CsrfTokenRetriever getCsrfTokenRetriever()
      Description copied from class: FluentHelperBasic
      The CSRF token retriever to be used for all explicit and implicit requests that are part of this FluentHelper implementation.
      Overrides:
      getCsrfTokenRetriever in class FluentHelperBasic<FluentHelperT,ObjectT,ResultT>
    • getParameters

      @Nonnull protected abstract Map<String,Object> getParameters()
      Getter for the map of parameters to be used in the function call.

      The map maps the ODataName of a parameter to the corresponding unserialized value.

      Only literal values are allowed as value. No complex or entity objects.

      Returns:
      A map containing the parameter for the function call.
    • getFunctionName

      @Nonnull protected abstract String getFunctionName()
      The exact name of the function to be called on the OData Endpoint.
      Returns:
      The function name on the endpoint.
    • createRequest

      @Nonnull protected abstract org.apache.http.client.methods.HttpUriRequest createRequest(@Nonnull URI uri)
      Creates a request for this function based on the given URI.

      Examples for such requests are HttpGet and HttpPost.

      Parameters:
      uri - The URI the request should target.
      Returns:
      The instantiated request.
    • toRequest

      @Nonnull public ODataRequestGeneric toRequest()
      Translate this OData v2 request into a OData request object extending ODataRequestGeneric.

      The function import arguments are encoded as HTTP query expressions.

      Specified by:
      toRequest in class FluentHelperBasic<FluentHelperT,ObjectT,ResultT>
      Returns:
      A protocol agnostic OData request instance.
    • executeSingle

      @Nullable protected ObjectT executeSingle(@Nonnull Destination destination) throws ODataException
      Default implementation for the case that this function returns a single type.

      This method can be used in subclasses to implement the FluentHelperBasic.executeRequest(Destination) method.

      Parameters:
      destination - The destination to run the function against.
      Returns:
      The single object returned by the function call. Returns null if the function did not return a result.
      Throws:
      ODataException - If the execution of the function failed.
    • executeMultiple

      @Nonnull protected List<ObjectT> executeMultiple(@Nonnull Destination destination) throws ODataException
      Default implementation for the case that this function returns a collection of entries.

      This method can be used in subclasses to implement the FluentHelperBasic.executeRequest(Destination) method.

      Parameters:
      destination - The destination to run the function against.
      Returns:
      A list of the objects returned by the function call. Returns an empty list if the function did not return a result.
      Throws:
      ODataException - If the execution of the function failed.
    • refineJsonResponse

      @Nullable protected com.google.gson.JsonElement refineJsonResponse(@Nullable com.google.gson.JsonElement jsonElement)
      Transform the JSON element from the response to extract a result entity. By default this method returns the original object.
      Parameters:
      jsonElement - The optional response JSON element
      Returns:
      The refined JSON element
    • withCsrfToken

      @Nonnull public FluentHelperT withCsrfToken()
      Activates the CSRF token retrieval for this OData request. This is useful if the server does require CSRF tokens as part of the request.
      Returns:
      The same builder
    • withoutCsrfToken

      @Nonnull public FluentHelperT withoutCsrfToken()
      Deactivates the CSRF token retrieval for this OData request. This is useful if the server does not support or require CSRF tokens as part of the request.
      Returns:
      The same builder