Class EthosResponseConverter


  • public class EthosResponseConverter
    extends EthosResponseBuilder
    Converter class extending the EthosResponseBuilder, the primary purpose of which is to handle manipulation of the response body content for paging calculations, such as trimming the response body content for a given offset or number of rows. Also converts an EthosResponse to String or com.fasterxml.jackson.databind.JsonNode formats.
    • Field Detail

      • objectMapper

        protected com.fasterxml.jackson.databind.ObjectMapper objectMapper
        A Jackson objectMapper to count the number of rows in the response body content, and to convert to the response body to a generic type object.
    • Constructor Detail

      • EthosResponseConverter

        public EthosResponseConverter()
        No-arg constructor which also builds the objectMapper.
    • Method Detail

      • trimContentFromOffset

        public EthosResponse trimContentFromOffset​(EthosResponse sourceResponse,
                                                   int offset)
                                            throws com.fasterxml.jackson.core.JsonProcessingException
        Takes the given EthosResponse and trims it's content from the given offset. For example, if the given content contains 10 rows, and the offset is 3, the returned EthosResponse content will contain rows 3 through the end of the sourceResponse content. The returned EthosResponse will also contain the headers and Http status code from the given sourceResponse.
        Parameters:
        sourceResponse - The EthosResponse to trim content for.
        offset - The offset (row num) from which to begin trimming content.
        Returns:
        An EthosResponse containing the same content as the sourceResponse, minus the rows in the sourceResponse which occurred before the given offset. The returned EthosResponse will also contain the headers and Http status code from the given sourceResponse. If the sourceResponse is null, if the sourceResponse content is null or empty, or if the offset is negative, the original sourceResponse will be returned unchanged.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the Jackson objectMapper cannot read the response content body from the sourceResponse.
      • trimContentForNumRows

        public EthosResponse trimContentForNumRows​(EthosResponse sourceResponse,
                                                   int numRows)
                                            throws com.fasterxml.jackson.core.JsonProcessingException
        Takes the given EthosResponse and trims it's content for the given number of rows. For example, if the given content contains 10 rows, and numRows is 7, the returned EthosResponse content will contain rows 0 through 6 (for a total of 7) of the sourceResponse content. The returned EthosResponse will also contain the headers and Http status code from the given sourceResponse.
        Parameters:
        sourceResponse - The EthosResponse to trim content for.
        numRows - The number of rows to trim the content for.
        Returns:
        An EthosResponse containing the same content as the sourceResponse, minus the rows in the sourceResponse which occur after numRows - 1. The returned EthosResponse will also contain the headers and Http status code from the given sourceResponse. If the sourceResponse is null, if the sourceResponse content is null or empty, or if the numRows is negative, the original sourceResponse will be returned unchanged.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the Jackson objectMapper cannot read the response content body from the sourceResponse.
      • trimContentFromOffsetForNumRows

        public EthosResponse trimContentFromOffsetForNumRows​(EthosResponse sourceResponse,
                                                             int offset,
                                                             int numRows)
                                                      throws com.fasterxml.jackson.core.JsonProcessingException
        Takes the given EthosResponse and trims it's content from the given offset for the given number of rows. For example, if the given content contains 10 rows, the offset is 3, and numRows is 7, the returned EthosResponse content will contain rows 3 through 6 (for a total of 4) of the sourceResponse content. The returned EthosResponse will also contain the headers and Http status code from the given sourceResponse.
        Parameters:
        sourceResponse - The EthosResponse to trim content for.
        offset - The offset (row num) from which to begin trimming content.
        numRows - The number of rows to trim the content for.
        Returns:
        An EthosResponse containing the same content as the sourceResponse, minus the rows in the sourceResponse which occur before the offset and after numRows - 1. The returned EthosResponse will also contain the headers and Http status code from the given sourceResponse. If the sourceResponse is null, if the sourceResponse content is null or empty, or if the offset is negative, the original sourceResponse will be returned unchanged. If the offset is positive but the numRows is negative, then the EthosResponse will contain the same content as the sourceResponse, minus the rows in the sourceResponse which occur before the offset, just as what trimContentFromOffset() returns.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Propagates this exception if thrown from the trimContentFromOffset() or trimContentForNumRows() methods.
      • toContentString

        public String toContentString​(EthosResponse ethosResponse)
        Returns the content body of the given EthosResponse, or null if the EthosResponse is null.
        Parameters:
        ethosResponse - the EthosResponse to get the content body from.
        Returns:
        the content body of the given EthosResponse.
      • toJsonNode

        public com.fasterxml.jackson.databind.JsonNode toJsonNode​(EthosResponse ethosResponse)
                                                           throws com.fasterxml.jackson.core.JsonProcessingException
        Returns a com.fasterxml.jackson.databind.JsonNode representation of the content body of the given EthosResponse.
        Parameters:
        ethosResponse - The given EthosResponse to convert to a JsonNode.
        Returns:
        A JsonNode containing the content body of the given EthosResponse
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the Jackson objectMapper cannot read the EthosResponse content body.
      • toPageBasedStringList

        public List<String> toPageBasedStringList​(List<EthosResponse> ethosResponseList)
        Converts the given list of EthosResponse objects into a list of Strings, where each String in the list is the content body of the given EthosResponse in the ethosResponseList. The expectation is that each EthosResponse in the given list contains a page of resources, and therefore each String in the returned list contains that same page of resources in String format.
        Parameters:
        ethosResponseList - The list of EthosResponse objects to convert to a list of Strings.
        Returns:
        a list of Strings where each String in the list is the content body of the corresponding EthosResponse object in the ethosResponseList, or an empty list if the given ethosResponseList is null. Each String in the returned list represents a page of resources from the corresponding ethosResponseList.
      • toRowBasedStringList

        public List<String> toRowBasedStringList​(List<EthosResponse> ethosResponseList)
                                          throws com.fasterxml.jackson.core.JsonProcessingException
        Converts the given list of EthosResponse objects into a list of Strings, where each String in the list is an individual row (instance) of a resource. The expectation is that each EthosResponse in the given list contains a page of resources, where each page is broken down into rows. The rows from each page are then all returned in a single list of JSON formatted Strings.
        Parameters:
        ethosResponseList - The list of EthosResponse objects to convert to a list of Strings.
        Returns:
        a list of Strings where each JSON formatted String in the list is an individual row (instance) of a resource. The entirety of the returned list contains the same data in the given ethosResponseList, except by row instead of page, and in String format. Returns an empty list if the given ethosResponseList is null.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the Jackson objectMapper cannot read the EthosResponse content body.
      • toPageBasedJsonNodeList

        public List<com.fasterxml.jackson.databind.JsonNode> toPageBasedJsonNodeList​(List<EthosResponse> ethosResponseList)
                                                                              throws com.fasterxml.jackson.core.JsonProcessingException
        Converts the given list of EthosResponse objects into a list of JsonNodes, where each JsonNode in the list contains the content body of the given EthosResponse in the ethosResponseList. The expectation is that each EthosResponse in the given list contains a page of resources, and therefore each JsonNode in the returned list contains that same page of resources as a JsonNode.
        Parameters:
        ethosResponseList - The list of EthosResponse objects to convert to a list of JsonNodes.
        Returns:
        A list of JsonNodes where each JsonNode in the list contains the content body of the corresponding EthosResponse object in the ethosResponseList, or an empty list if the given ethosResponseList is null. Each JsonNode in the returned list represents a page of resources from the corresponding ethosResponseList.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the Jackson objectMapper cannot read the EthosResponse content body.
      • toRowBasedJsonNodeList

        public List<com.fasterxml.jackson.databind.JsonNode> toRowBasedJsonNodeList​(List<EthosResponse> ethosResponseList)
                                                                             throws com.fasterxml.jackson.core.JsonProcessingException
        Converts the given list of EthosResponse objects into a list of JsonNodes, where each JsonNode in the list is an individual row (instance) of a resource. The expectation is that each EthosResponse in the given list contains a page of resources, where each page is broken down into rows. The rows from each page are then all returned in a single list of JsonNodes.
        Parameters:
        ethosResponseList - The list of EthosResponse objects to convert to a list of row-based JsonNodes.
        Returns:
        a list of JsonNodes where each JsonNode in the list is an individual row (instance) of a resource. The entirety of the returned list contains the same data in the given ethosResponseList, except by row instead of page, and as JsonNodes. Returns an empty list if the given ethosResponseList is null.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the Jackson objectMapper cannot read the EthosResponse content body.
      • toSingleEthosError

        public EthosError toSingleEthosError​(EthosResponse ethosResponse)
                                      throws com.fasterxml.jackson.core.JsonProcessingException
        Converts an ethosResponse to an EthosError object. The given ethosResponse.getContent() should contain data for only a single error, and NOT an entire page of errors.
        Parameters:
        ethosResponse - The EthosResponse to convert containing content for an EthosError.
        Returns:
        An EthosError from the content of the given ethosResponse, or null if the ethosResponse is null or it's content is null or blank.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Propagated if thrown by the ErrorFactory.
      • toEthosErrorList

        public List<EthosError> toEthosErrorList​(EthosResponse ethosResponse)
                                          throws com.fasterxml.jackson.core.JsonProcessingException
        Converts an ethosResponse to a list of EthosError objects. The given ethosResponse.getContent() should contain an entire page of errors as an errors array in JSON format.
        Parameters:
        ethosResponse - The EthosResponse to convert containing content for a page of EthosErrors.
        Returns:
        An list of EthosErrors from the content of the given ethosResponse, or an empty list if the ethosResponse is null or it's content is null or blank.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Propagated if thrown by the ErrorFactory.
      • toChangeNotificationList

        public List<ChangeNotification> toChangeNotificationList​(EthosResponse ethosResponse)
                                                          throws com.fasterxml.jackson.core.JsonProcessingException
        Converts the given ethosResponse to a list of ChangeNotification objects.
        Parameters:
        ethosResponse - The EthosResponse to convert containing content for the ChangeNotifications.
        Returns:
        A list of ChangeNotifications from the content of the given ethosResponse, or null if the ethosResponse is null or it's content is null or blank.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Propagated if thrown by the ChangeNotificationFactory.
      • toTypedList

        public <T> T toTypedList​(EthosResponse ethosResponse,
                                 Class classType)
                          throws com.fasterxml.jackson.core.JsonProcessingException
        Converts the EthosResponse content into a list of generic typed objects based on the given class.
        Type Parameters:
        T - The generic type returned.
        Parameters:
        ethosResponse - The EthosResponse containing content to convert.
        classType - A class reference of the generic type object to convert to.
        Returns:
        A list of generic type objects from the content of the EthosResponse, according to the given class.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the object mapper cannot read the content of the EthosResponse.
      • toTyped

        public <T> T toTyped​(EthosResponse ethosResponse,
                             Class classType)
                      throws com.fasterxml.jackson.core.JsonProcessingException
        Converts the EthosResponse content into a generic typed object based on the given class.
        Type Parameters:
        T - The generic type returned.
        Parameters:
        ethosResponse - The EthosResponse containing content to convert.
        classType - A class reference of the generic type object to convert to.
        Returns:
        A generic type object from the content of the EthosResponse, according to the given class.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - Thrown if the object mapper cannot read the content of the EthosResponse.