Search in sources :

Example 6 with Incident

use of io.github.asw.i3a.operatorsWebClient.entitites.Incident in project InciDashboard_i3a by Arquisoft.

the class IncidentService method getInProcessIncidentsOfOperator.

public static List<Incident> getInProcessIncidentsOfOperator(String id) {
    try {
        HttpResponse<JsonNode> response = Unirest.post(API_GATEWAY + "/incidents?operatorId=" + id + "&status=IN_PROCESS").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 7 with Incident

use of io.github.asw.i3a.operatorsWebClient.entitites.Incident 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 8 with Incident

use of io.github.asw.i3a.operatorsWebClient.entitites.Incident 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 9 with Incident

use of io.github.asw.i3a.operatorsWebClient.entitites.Incident in project InciDashboard_i3a by Arquisoft.

the class IncidentController method getDetail.

@RequestMapping("/incident/details/{id}")
public String getDetail(Model model, @PathVariable String id, @Nullable @CookieValue("operatorId") String opId) {
    if (opId == null)
        return "redirect:/login";
    Incident inci = IncidentService.getIncident(id);
    model.addAttribute("incident", inci);
    try {
        if (!inci.getLocation().isEmpty() && inci.getLocation().contains(", "))
            model.addAttribute("lat", Double.parseDouble(inci.getLocation().split(", ")[0]));
        model.addAttribute("lng", Double.parseDouble(inci.getLocation().split(", ")[1]));
    } catch (Exception e) {
        log.error("Error parsin the location of the incident no map will be displayed.");
    }
    log.info("Seeing incent: " + id + " details");
    return "incident/details";
}
Also used : Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) ParseException(java.text.ParseException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Incident

use of io.github.asw.i3a.operatorsWebClient.entitites.Incident in project InciDashboard_i3a by Arquisoft.

the class IncidentController method setEdit.

@RequestMapping(value = "/incident/edit/{id}", method = RequestMethod.POST)
public String setEdit(Model model, @ModelAttribute("inciInfo") InciInfo newInciData, @Nullable @CookieValue("operatorId") String opId, @PathVariable String id) {
    if (opId == null)
        return "redirect:/login";
    Incident incident = IncidentService.getIncident(id);
    giveNewDataToIncident(newInciData, incident, opId);
    assignOp(opId, incident);
    incident.setIncidentId(id);
    log.info("Operator assigned to the incident");
    IncidentService.saveIncident(incident);
    log.info("Incident updated in the database");
    return "redirect:/operator/listMyIncidents";
}
Also used : Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Incident (io.github.asw.i3a.operatorsWebClient.entitites.Incident)10 JsonNode (com.mashape.unirest.http.JsonNode)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 List (java.util.List)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)3 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 IncidentService (io.github.asw.i3a.operatorsWebClient.client.IncidentService)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Collections (java.util.Collections)2 Locale (java.util.Locale)2 Slf4j (lombok.extern.slf4j.Slf4j)2 JSONException (org.json.JSONException)2 Nullable (org.springframework.lang.Nullable)2 Controller (org.springframework.stereotype.Controller)2 Model (org.springframework.ui.Model)2 CookieValue (org.springframework.web.bind.annotation.CookieValue)2 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)2 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)2