}
@Override
public List<RTTicket> findByQuery(String query, String orderby, TicketSearchResponseFormat format) throws Exception {
client.login();
RTRESTResponse response = client.searchTickets(query, orderby, format);
client.logout();
TicketSearchResponseParser parser = null;
switch (format) {
case IDONLY: parser = null; break;
case IDANDSUBJECT: parser = null; break;
case MULTILINE: parser = MultilineTicketSearchResponseParser.getInstance(); break;
}
if (parser != null) {
if (response.getStatusCode() == 200l) {
return parser.parseTicketSearchResponse(response);
} else if (response.getStatusCode() == 401l) {
throw new CredentialException(response.getStatusMessage());
} else {
throw new IOException(String.format("Server returned REST-response code %s (%s)", response.getStatusCode(), response.getStatusMessage()));
}
} else {
throw new UnsupportedOperationException("Could not create parser for response format.");
}
}