Search in sources :

Example 41 with JsonNode

use of com.mashape.unirest.http.JsonNode in project InciDashboard_i3a by Arquisoft.

the class IncidentService method getAllOpenIncidents.

public static Incident[] getAllOpenIncidents() {
    try {
        HttpResponse<JsonNode> response = Unirest.post(API_GATEWAY + "/incidents?status=OPEN").asJson();
        ObjectMapper mapper = new ObjectMapper();
        Incident[] items = mapper.readValue(response.getBody().toString(), Incident[].class);
        log.info("Incidents retrieved: " + items.length);
        return items;
    } catch (IOException | UnirestException e) {
        log.error("Error getting all open incidents: " + e.getMessage());
        return null;
    }
}
Also used : UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode) Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 42 with JsonNode

use of com.mashape.unirest.http.JsonNode in project InciDashboard_i3a by Arquisoft.

the class IncidentService method getIncident.

public static Incident getIncident(String id) {
    try {
        HttpResponse<JsonNode> response = Unirest.post(API_GATEWAY + "/incidents/" + id).asJson();
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(response.getBody().toString(), Incident.class);
    } catch (IOException | UnirestException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 43 with JsonNode

use of com.mashape.unirest.http.JsonNode in project InciDashboard_i3a by Arquisoft.

the class IncidentService method getAllIncidents.

public static List<Incident> getAllIncidents() {
    try {
        HttpResponse<JsonNode> response = Unirest.post(API_GATEWAY + "/incidents").asJson();
        ObjectMapper mapper = new ObjectMapper();
        List<Incident> items = mapper.readValue(response.getBody().toString(), mapper.getTypeFactory().constructParametricType(List.class, Incident.class));
        return items;
    } catch (IOException | UnirestException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode) List(java.util.List) Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 44 with JsonNode

use of com.mashape.unirest.http.JsonNode in project InciDashboard_i3a by Arquisoft.

the class AgentService method getAgent.

public static Agent getAgent(String id) {
    try {
        HttpResponse<JsonNode> response = Unirest.post(API_GATEWAY + "/agents/" + id).asJson();
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(response.getBody().toString(), Agent.class);
    } catch (IOException | UnirestException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 45 with JsonNode

use of com.mashape.unirest.http.JsonNode in project InciDashboard_i3a by Arquisoft.

the class AgentService method getAllSensors.

public static Agent[] getAllSensors() {
    try {
        HttpResponse<JsonNode> response = Unirest.post(API_GATEWAY + "/agents?kindCode=3").asJson();
        ObjectMapper mapper = new ObjectMapper();
        Agent[] items = mapper.readValue(response.getBody().toString(), Agent[].class);
        return items;
    } catch (IOException | UnirestException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Agent(io.github.asw.i3a.operatorsWebClient.entitites.Agent) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.mashape.unirest.http.JsonNode)47 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)20 JSONObject (org.json.JSONObject)19 IOException (java.io.IOException)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 JSONArray (org.json.JSONArray)11 RestResponseResult (uk.ac.ebi.spot.goci.model.RestResponseResult)5 Incident (io.github.asw.i3a.operatorsWebClient.entitites.Incident)4 List (java.util.List)4 ActionException (org.apache.zeppelin.elasticsearch.action.ActionException)4 ActionResponse (org.apache.zeppelin.elasticsearch.action.ActionResponse)4 HitWrapper (org.apache.zeppelin.elasticsearch.action.HitWrapper)4 JSONException (org.json.JSONException)4 Gson (com.google.gson.Gson)3 Type (java.lang.reflect.Type)3 JsonObjectBuilder (javax.json.JsonObjectBuilder)3 Test (org.junit.Test)3 RestTemplate (org.springframework.web.client.RestTemplate)3 HttpResponse (com.mashape.unirest.http.HttpResponse)2 HttpRequest (com.mashape.unirest.request.HttpRequest)2