Class EthosResponseConverter
- java.lang.Object
-
- com.ellucian.ethos.integration.client.EthosResponseBuilder
-
- com.ellucian.ethos.integration.client.EthosResponseConverter
-
public class EthosResponseConverter extends EthosResponseBuilder
Converter class extending theEthosResponseBuilder, 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 anEthosResponsetoStringorcom.fasterxml.jackson.databind.JsonNodeformats.
-
-
Field Summary
Fields Modifier and Type Field Description protected com.fasterxml.jackson.databind.ObjectMapperobjectMapperA 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 Summary
Constructors Constructor Description EthosResponseConverter()No-arg constructor which also builds the objectMapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<ChangeNotification>toChangeNotificationList(EthosResponse ethosResponse)Converts the given ethosResponse to a list of ChangeNotification objects.StringtoContentString(EthosResponse ethosResponse)Returns the content body of the givenEthosResponse, or null if theEthosResponseis null.List<EthosError>toEthosErrorList(EthosResponse ethosResponse)Converts an ethosResponse to a list of EthosError objects.com.fasterxml.jackson.databind.JsonNodetoJsonNode(EthosResponse ethosResponse)Returns acom.fasterxml.jackson.databind.JsonNoderepresentation of the content body of the givenEthosResponse.List<com.fasterxml.jackson.databind.JsonNode>toPageBasedJsonNodeList(List<EthosResponse> ethosResponseList)Converts the given list ofEthosResponseobjects into a list ofJsonNodes, where eachJsonNodein the list contains the content body of the givenEthosResponsein theethosResponseList.List<String>toPageBasedStringList(List<EthosResponse> ethosResponseList)Converts the given list ofEthosResponseobjects into a list ofStrings, where eachStringin the list is the content body of the givenEthosResponsein theethosResponseList.List<com.fasterxml.jackson.databind.JsonNode>toRowBasedJsonNodeList(List<EthosResponse> ethosResponseList)Converts the given list ofEthosResponseobjects into a list ofJsonNodes, where eachJsonNodein the list is an individual row (instance) of a resource.List<String>toRowBasedStringList(List<EthosResponse> ethosResponseList)Converts the given list ofEthosResponseobjects into a list ofStrings, where eachStringin the list is an individual row (instance) of a resource.EthosErrortoSingleEthosError(EthosResponse ethosResponse)Converts an ethosResponse to an EthosError object.<T> TtoTyped(EthosResponse ethosResponse, Class classType)Converts the EthosResponse content into a generic typed object based on the given class.<T> TtoTypedList(EthosResponse ethosResponse, Class classType)Converts the EthosResponse content into a list of generic typed objects based on the given class.EthosResponsetrimContentForNumRows(EthosResponse sourceResponse, int numRows)Takes the givenEthosResponseand trims it's content for the given number of rows.EthosResponsetrimContentFromOffset(EthosResponse sourceResponse, int offset)Takes the givenEthosResponseand trims it's content from the given offset.EthosResponsetrimContentFromOffsetForNumRows(EthosResponse sourceResponse, int offset, int numRows)Takes the givenEthosResponseand trims it's content from the given offset for the given number of rows.-
Methods inherited from class com.ellucian.ethos.integration.client.EthosResponseBuilder
buildEthosResponse
-
-
-
-
Method Detail
-
trimContentFromOffset
public EthosResponse trimContentFromOffset(EthosResponse sourceResponse, int offset) throws com.fasterxml.jackson.core.JsonProcessingException
Takes the givenEthosResponseand trims it's content from the given offset. For example, if the given content contains 10 rows, and the offset is 3, the returnedEthosResponsecontent will contain rows 3 through the end of thesourceResponsecontent. The returnedEthosResponsewill also contain the headers and Http status code from the givensourceResponse.- Parameters:
sourceResponse- TheEthosResponseto trim content for.offset- The offset (row num) from which to begin trimming content.- Returns:
- An
EthosResponsecontaining the same content as thesourceResponse, minus the rows in thesourceResponsewhich occurred before the given offset. The returnedEthosResponsewill also contain the headers and Http status code from the givensourceResponse. If thesourceResponseis null, if thesourceResponsecontent is null or empty, or if the offset is negative, the originalsourceResponsewill be returned unchanged. - Throws:
com.fasterxml.jackson.core.JsonProcessingException- Thrown if the Jackson objectMapper cannot read the response content body from thesourceResponse.
-
trimContentForNumRows
public EthosResponse trimContentForNumRows(EthosResponse sourceResponse, int numRows) throws com.fasterxml.jackson.core.JsonProcessingException
Takes the givenEthosResponseand trims it's content for the given number of rows. For example, if the given content contains 10 rows, and numRows is 7, the returnedEthosResponsecontent will contain rows 0 through 6 (for a total of 7) of thesourceResponsecontent. The returnedEthosResponsewill also contain the headers and Http status code from the givensourceResponse.- Parameters:
sourceResponse- TheEthosResponseto trim content for.numRows- The number of rows to trim the content for.- Returns:
- An
EthosResponsecontaining the same content as thesourceResponse, minus the rows in thesourceResponsewhich occur after numRows - 1. The returnedEthosResponsewill also contain the headers and Http status code from the givensourceResponse. If thesourceResponseis null, if thesourceResponsecontent is null or empty, or if the numRows is negative, the originalsourceResponsewill be returned unchanged. - Throws:
com.fasterxml.jackson.core.JsonProcessingException- Thrown if the Jackson objectMapper cannot read the response content body from thesourceResponse.
-
trimContentFromOffsetForNumRows
public EthosResponse trimContentFromOffsetForNumRows(EthosResponse sourceResponse, int offset, int numRows) throws com.fasterxml.jackson.core.JsonProcessingException
Takes the givenEthosResponseand 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 returnedEthosResponsecontent will contain rows 3 through 6 (for a total of 4) of thesourceResponsecontent. The returnedEthosResponsewill also contain the headers and Http status code from the givensourceResponse.- Parameters:
sourceResponse- TheEthosResponseto 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
EthosResponsecontaining the same content as thesourceResponse, minus the rows in thesourceResponsewhich occur before the offset and after numRows - 1. The returnedEthosResponsewill also contain the headers and Http status code from the givensourceResponse. If thesourceResponseis null, if thesourceResponsecontent is null or empty, or if the offset is negative, the originalsourceResponsewill be returned unchanged. If the offset is positive but the numRows is negative, then theEthosResponsewill contain the same content as thesourceResponse, minus the rows in thesourceResponsewhich occur before the offset, just as whattrimContentFromOffset()returns. - Throws:
com.fasterxml.jackson.core.JsonProcessingException- Propagates this exception if thrown from thetrimContentFromOffset()ortrimContentForNumRows()methods.
-
toContentString
public String toContentString(EthosResponse ethosResponse)
Returns the content body of the givenEthosResponse, or null if theEthosResponseis null.- Parameters:
ethosResponse- theEthosResponseto 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 acom.fasterxml.jackson.databind.JsonNoderepresentation of the content body of the givenEthosResponse.- Parameters:
ethosResponse- The givenEthosResponseto convert to aJsonNode.- Returns:
- A
JsonNodecontaining the content body of the givenEthosResponse - Throws:
com.fasterxml.jackson.core.JsonProcessingException- Thrown if the JacksonobjectMappercannot read theEthosResponsecontent body.
-
toPageBasedStringList
public List<String> toPageBasedStringList(List<EthosResponse> ethosResponseList)
Converts the given list ofEthosResponseobjects into a list ofStrings, where eachStringin the list is the content body of the givenEthosResponsein theethosResponseList. 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 ofEthosResponseobjects to convert to a list ofStrings.- Returns:
- a list of
Strings where eachStringin the list is the content body of the correspondingEthosResponseobject in theethosResponseList, or an empty list if the givenethosResponseListis 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 ofEthosResponseobjects into a list ofStrings, where eachStringin 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 ofEthosResponseobjects to convert to a list ofStrings.- Returns:
- a list of
Strings where each JSON formattedStringin 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 JacksonobjectMappercannot read theEthosResponsecontent body.
-
toPageBasedJsonNodeList
public List<com.fasterxml.jackson.databind.JsonNode> toPageBasedJsonNodeList(List<EthosResponse> ethosResponseList) throws com.fasterxml.jackson.core.JsonProcessingException
Converts the given list ofEthosResponseobjects into a list ofJsonNodes, where eachJsonNodein the list contains the content body of the givenEthosResponsein theethosResponseList. 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 ofEthosResponseobjects to convert to a list ofJsonNodes.- Returns:
- A list of
JsonNodes where eachJsonNodein the list contains the content body of the correspondingEthosResponseobject in theethosResponseList, or an empty list if the givenethosResponseListis 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 JacksonobjectMappercannot read theEthosResponsecontent body.
-
toRowBasedJsonNodeList
public List<com.fasterxml.jackson.databind.JsonNode> toRowBasedJsonNodeList(List<EthosResponse> ethosResponseList) throws com.fasterxml.jackson.core.JsonProcessingException
Converts the given list ofEthosResponseobjects into a list ofJsonNodes, where eachJsonNodein 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 ofEthosResponseobjects to convert to a list of row-basedJsonNodes.- Returns:
- a list of
JsonNodes where eachJsonNodein 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 JacksonobjectMappercannot read theEthosResponsecontent 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.
-
-