Class ConnectorResponse


  • public class ConnectorResponse
    extends Object
    A standard response format used by the connectors sdk, consisting of a response code, a message, and a custom additional payload.

    The message is optional in case of a successful response, otherwise it is obligatory.

    • Constructor Detail

      • ConnectorResponse

        public ConnectorResponse​(String responseCode,
                                 String message)
        Creates a new ConnectorResponse, with the provided response code, message, and no additional response payload.
        Parameters:
        responseCode - response code
        message - response message
      • ConnectorResponse

        public ConnectorResponse​(String responseCode,
                                 String message,
                                 Map<String,​Variant> additionalPayload)
        Creates a new ConnectorResponse, with the provided response code, message, and additional response payload.
        Parameters:
        responseCode - response code
        message - response message
        additionalPayload - additional response payload
    • Method Detail

      • success

        public static ConnectorResponse success()
        Creates a new connector response instance, with response code of OK, no message, and no additional payload.
        Returns:
        new successful connector response instance
      • success

        public static ConnectorResponse success​(String message)
        Creates a new response instance, with response code of OK, provided message, and no additional payload.
        Parameters:
        message - response message
        Returns:
        new successful response instance
      • success

        public static ConnectorResponse success​(String message,
                                                Map<String,​Variant> additionalPayload)
        Creates a new response instance, with response code of OK, provided message, and additional payload.
        Parameters:
        message - response message
        additionalPayload - additional response payload
        Returns:
        new successful response instance
      • error

        public static ConnectorResponse error​(String errorCode,
                                              String errorMessage)
        Creates a new error response instance, with provided response code, message, and no additional payload.
        Parameters:
        errorCode - response code
        errorMessage - response message
        Returns:
        new error response instance
      • error

        public static ConnectorResponse error​(String errorCode,
                                              String errorMessage,
                                              Map<String,​Variant> additionalPayload)
        Creates a new error response instance, with provided response code, message, and additional payload.
        Parameters:
        errorCode - response code
        errorMessage - response message
        additionalPayload - additional response payload
        Returns:
        new error response instance
      • fromException

        public static ConnectorResponse fromException​(String exceptionBody)
        Creates a new error response instance by parsing the provided exception body.

        Provided exception body must be a valid connector response, written as a JSON String.

        Parameters:
        exceptionBody - exception body
        Returns:
        new error response instance
        Throws:
        InvalidConnectorResponseException - if the provided String is not a valid response JSON String
      • fromVariant

        public static ConnectorResponse fromVariant​(Variant variant)
        Creates a new error response instance from the provided Variant.

        Provided Variant must be a valid connector response, containing all the necessary properties.

        Parameters:
        variant - variant with the response
        Returns:
        new error response instance
        Throws:
        InvalidConnectorResponseException - if the provided Variant is not a valid response
      • getResponseCode

        public String getResponseCode()
        Returns the response code.
        Returns:
        response code
      • getMessage

        public String getMessage()
        Returns the response message.
        Returns:
        response message
      • getAdditionalPayload

        public Map<String,​Variant> getAdditionalPayload()
        Returns the additional response payload.
        Returns:
        additional response payload
      • withAdditionalPayload

        public ConnectorResponse withAdditionalPayload​(String key,
                                                       Variant value)
        Adds a new key-value pair to additional payload
        Returns:
        this ConnectorResponse instance
      • toMap

        public Map<String,​Variant> toMap()
        Returns the properties of this response in a Map.
        Returns:
        properties of this response in a Map
      • toVariant

        public Variant toVariant()
        Returns the properties of this response in a Variant.
        Returns:
        properties of this response in a Variant
      • toVariant

        public Variant toVariant​(Variant baseVariant)
        Returns the properties of this response appended to the provided Variant.
        Parameters:
        baseVariant - base Variant to which the properties of this response should be appended
        Returns:
        properties of this response appended to the provided Variant
      • toJson

        public String toJson()
        Returns the properties of this response in a JSON String.
        Returns:
        properties of this response in a JSON String
      • is

        public boolean is​(String code)
        Returns whether the code of this response is equal to the provided code.
        Parameters:
        code - response code
        Returns:
        whether the code of this response is equal to the provided code
      • isOk

        public boolean isOk()
        Returns whether the code of this response is equal to OK.
        Returns:
        whether the code of this response is equal to OK
      • isNotOk

        public boolean isNotOk()
        Returns whether the code of this response is not equal to OK.
        Returns:
        whether the code of this response is not equal to OK
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object