Search in sources :

Example 1 with IncidentRecordList

use of io.syndesis.qe.util.servicenow.model.IncidentRecordList in project syndesis-qe by syndesisio.

the class ServiceNow method parseResponse.

/**
 * Service-Now API returns single object when there is 1 record, but list of records when there are more records.
 *
 * @param response json response
 * @return list of records
 */
private static List<Incident> parseResponse(String response) {
    List<Incident> incidents = new ArrayList<>();
    try {
        IncidentRecordList irl = om.readValue(response, IncidentRecordList.class);
        incidents.addAll(irl.getRecords());
        return incidents;
    } catch (IOException e) {
        // Try to parse it as single record response
        try {
            incidents.add(om.readValue(response, IncidentSingleResponse.class).getRecord());
            return incidents;
        } catch (IOException e1) {
            fail("Unable to unmarshall incident response", e);
        }
    }
    return null;
}
Also used : IncidentSingleResponse(io.syndesis.qe.util.servicenow.model.IncidentSingleResponse) IncidentRecordList(io.syndesis.qe.util.servicenow.model.IncidentRecordList) ArrayList(java.util.ArrayList) Incident(io.syndesis.qe.util.servicenow.model.Incident) IOException(java.io.IOException)

Aggregations

Incident (io.syndesis.qe.util.servicenow.model.Incident)1 IncidentRecordList (io.syndesis.qe.util.servicenow.model.IncidentRecordList)1 IncidentSingleResponse (io.syndesis.qe.util.servicenow.model.IncidentSingleResponse)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1