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 anEthosResponse
toString
orcom.fasterxml.jackson.databind.JsonNode
formats.
-
-
Field Summary
Fields Modifier and Type Field Description 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 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.String
toContentString(EthosResponse ethosResponse)
Returns the content body of the givenEthosResponse
, or null if theEthosResponse
is null.List<EthosError>
toEthosErrorList(EthosResponse ethosResponse)
Converts an ethosResponse to a list of EthosError objects.com.fasterxml.jackson.databind.JsonNode
toJsonNode(EthosResponse ethosResponse)
Returns acom.fasterxml.jackson.databind.JsonNode
representation of the content body of the givenEthosResponse
.List<com.fasterxml.jackson.databind.JsonNode>
toPageBasedJsonNodeList(List<EthosResponse> ethosResponseList)
Converts the given list ofEthosResponse
objects into a list ofJsonNode
s, where eachJsonNode
in the list contains the content body of the givenEthosResponse
in theethosResponseList
.List<String>
toPageBasedStringList(List<EthosResponse> ethosResponseList)
Converts the given list ofEthosResponse
objects into a list ofString
s, where eachString
in the list is the content body of the givenEthosResponse
in theethosResponseList
.List<com.fasterxml.jackson.databind.JsonNode>
toRowBasedJsonNodeList(List<EthosResponse> ethosResponseList)
Converts the given list ofEthosResponse
objects into a list ofJsonNode
s, where eachJsonNode
in the list is an individual row (instance) of a resource.List<String>
toRowBasedStringList(List<EthosResponse> ethosResponseList)
Converts the given list ofEthosResponse
objects into a list ofString
s, where eachString
in the list is an individual row (instance) of a resource.EthosError
toSingleEthosError(EthosResponse ethosResponse)
Converts an ethosResponse to an EthosError object.<T> T
toTyped(EthosResponse ethosResponse, Class classType)
Converts the EthosResponse content into a generic typed object based on the given class.<T> T
toTypedList(EthosResponse ethosResponse, Class classType)
Converts the EthosResponse content into a list of generic typed objects based on the given class.EthosResponse
trimContentForNumRows(EthosResponse sourceResponse, int numRows)
Takes the givenEthosResponse
and trims it's content for the given number of rows.EthosResponse
trimContentFromOffset(EthosResponse sourceResponse, int offset)
Takes the givenEthosResponse
and trims it's content from the given offset.EthosResponse
trimContentFromOffsetForNumRows(EthosResponse sourceResponse, int offset, int numRows)
Takes the givenEthosResponse
and 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 givenEthosResponse
and trims it's content from the given offset. For example, if the given content contains 10 rows, and the offset is 3, the returnedEthosResponse
content will contain rows 3 through the end of thesourceResponse
content. The returnedEthosResponse
will also contain the headers and Http status code from the givensourceResponse
.- Parameters:
sourceResponse
- TheEthosResponse
to trim content for.offset
- The offset (row num) from which to begin trimming content.- Returns:
- An
EthosResponse
containing the same content as thesourceResponse
, minus the rows in thesourceResponse
which occurred before the given offset. The returnedEthosResponse
will also contain the headers and Http status code from the givensourceResponse
. If thesourceResponse
is null, if thesourceResponse
content is null or empty, or if the offset is negative, the originalsourceResponse
will 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 givenEthosResponse
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 returnedEthosResponse
content will contain rows 0 through 6 (for a total of 7) of thesourceResponse
content. The returnedEthosResponse
will also contain the headers and Http status code from the givensourceResponse
.- Parameters:
sourceResponse
- TheEthosResponse
to trim content for.numRows
- The number of rows to trim the content for.- Returns:
- An
EthosResponse
containing the same content as thesourceResponse
, minus the rows in thesourceResponse
which occur after numRows - 1. The returnedEthosResponse
will also contain the headers and Http status code from the givensourceResponse
. If thesourceResponse
is null, if thesourceResponse
content is null or empty, or if the numRows is negative, the originalsourceResponse
will 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 givenEthosResponse
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 returnedEthosResponse
content will contain rows 3 through 6 (for a total of 4) of thesourceResponse
content. The returnedEthosResponse
will also contain the headers and Http status code from the givensourceResponse
.- Parameters:
sourceResponse
- TheEthosResponse
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 thesourceResponse
, minus the rows in thesourceResponse
which occur before the offset and after numRows - 1. The returnedEthosResponse
will also contain the headers and Http status code from the givensourceResponse
. If thesourceResponse
is null, if thesourceResponse
content is null or empty, or if the offset is negative, the originalsourceResponse
will be returned unchanged. If the offset is positive but the numRows is negative, then theEthosResponse
will contain the same content as thesourceResponse
, minus the rows in thesourceResponse
which 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 theEthosResponse
is null.- Parameters:
ethosResponse
- theEthosResponse
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 acom.fasterxml.jackson.databind.JsonNode
representation of the content body of the givenEthosResponse
.- Parameters:
ethosResponse
- The givenEthosResponse
to convert to aJsonNode
.- Returns:
- A
JsonNode
containing the content body of the givenEthosResponse
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- Thrown if the JacksonobjectMapper
cannot read theEthosResponse
content body.
-
toPageBasedStringList
public List<String> toPageBasedStringList(List<EthosResponse> ethosResponseList)
Converts the given list ofEthosResponse
objects into a list ofString
s, where eachString
in the list is the content body of the givenEthosResponse
in 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 ofEthosResponse
objects to convert to a list ofString
s.- Returns:
- a list of
String
s where eachString
in the list is the content body of the correspondingEthosResponse
object in theethosResponseList
, or an empty list if the givenethosResponseList
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 ofEthosResponse
objects into a list ofString
s, where eachString
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 ofEthosResponse
objects to convert to a list ofString
s.- Returns:
- a list of
String
s where each JSON formattedString
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 JacksonobjectMapper
cannot read theEthosResponse
content body.
-
toPageBasedJsonNodeList
public List<com.fasterxml.jackson.databind.JsonNode> toPageBasedJsonNodeList(List<EthosResponse> ethosResponseList) throws com.fasterxml.jackson.core.JsonProcessingException
Converts the given list ofEthosResponse
objects into a list ofJsonNode
s, where eachJsonNode
in the list contains the content body of the givenEthosResponse
in 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 ofEthosResponse
objects to convert to a list ofJsonNode
s.- Returns:
- A list of
JsonNode
s where eachJsonNode
in the list contains the content body of the correspondingEthosResponse
object in theethosResponseList
, or an empty list if the givenethosResponseList
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 JacksonobjectMapper
cannot read theEthosResponse
content body.
-
toRowBasedJsonNodeList
public List<com.fasterxml.jackson.databind.JsonNode> toRowBasedJsonNodeList(List<EthosResponse> ethosResponseList) throws com.fasterxml.jackson.core.JsonProcessingException
Converts the given list ofEthosResponse
objects into a list ofJsonNode
s, where eachJsonNode
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 ofEthosResponse
objects to convert to a list of row-basedJsonNode
s.- Returns:
- a list of
JsonNode
s where eachJsonNode
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 JacksonobjectMapper
cannot read theEthosResponse
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.
-
-