Search in sources :

Example 1 with Incident

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

the class OperatorController method getMyIncidentsList.

@RequestMapping("/operator/listMyIncidents")
public String getMyIncidentsList(Model model, @Nullable @CookieValue("operatorId") String opId) {
    if (opId == null)
        return "redirect:/login";
    List<Incident> incidents = IncidentService.getInProcessIncidentsOfOperator(opId);
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
    Collections.sort(incidents, Collections.reverseOrder((i1, i2) -> {
        try {
            return sdf.parse(i1.getDate()).compareTo(sdf.parse(i2.getDate()));
        } catch (ParseException e) {
            log.error(e.getMessage());
            return 0;
        }
    }));
    model.addAttribute("incidents", incidents);
    log.info("Redirecting to the incidents of the operator");
    return "operator/incidents";
}
Also used : Locale(java.util.Locale) OperatorService(io.github.asw.i3a.operatorsWebClient.client.OperatorService) HttpServletResponse(javax.servlet.http.HttpServletResponse) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) CookieValue(org.springframework.web.bind.annotation.CookieValue) UserInfo(io.github.asw.i3a.operatorsWebClient.entitites.UserInfo) List(java.util.List) JSONException(org.json.JSONException) Model(org.springframework.ui.Model) Slf4j(lombok.extern.slf4j.Slf4j) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) Locale(java.util.Locale) HttpResponse(com.mashape.unirest.http.HttpResponse) Nullable(org.springframework.lang.Nullable) ParseException(java.text.ParseException) Cookie(javax.servlet.http.Cookie) JsonNode(com.mashape.unirest.http.JsonNode) Collections(java.util.Collections) IncidentService(io.github.asw.i3a.operatorsWebClient.client.IncidentService) Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Incident

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

the class Receiver method listen.

@KafkaListener(topics = "${kafka.topic}")
public void listen(String kafkaInput) {
    JsonNode kafkaPayload = new JsonNode(kafkaInput);
    String incidentId = "";
    try {
        incidentId = kafkaPayload.getObject().getString("incidentId");
        log.info("Incident received on kafka with id: " + incidentId);
    } catch (JSONException e) {
        log.error(e.getMessage());
    }
    Incident in = assignOperator(IncidentService.getIncident(incidentId));
    this.template.convertAndSend("/topic/incidents", in);
}
Also used : JSONException(org.json.JSONException) JsonNode(com.mashape.unirest.http.JsonNode) Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 3 with Incident

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

the class IncidentController method getListOpen.

@RequestMapping(value = "/incidents", method = RequestMethod.GET)
public String getListOpen(Model model, @Nullable @CookieValue("operatorId") String opId) {
    if (opId == null)
        return "redirect:/login";
    List<Incident> incidents = Arrays.asList(IncidentService.getAllOpenIncidents());
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
    Collections.sort(incidents, Collections.reverseOrder((i1, i2) -> {
        try {
            return sdf.parse(i1.getDate()).compareTo(sdf.parse(i2.getDate()));
        } catch (ParseException e) {
            log.error(e.getMessage());
            return 0;
        }
    }));
    model.addAttribute("incidents", incidents);
    log.info("Incidents sent to the model: " + incidents.size());
    return "incident/list";
}
Also used : Locale(java.util.Locale) PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) CookieValue(org.springframework.web.bind.annotation.CookieValue) Comment(io.github.asw.i3a.operatorsWebClient.entitites.Comment) List(java.util.List) Model(org.springframework.ui.Model) Slf4j(lombok.extern.slf4j.Slf4j) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) Locale(java.util.Locale) Nullable(org.springframework.lang.Nullable) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) ParseException(java.text.ParseException) Collections(java.util.Collections) IncidentService(io.github.asw.i3a.operatorsWebClient.client.IncidentService) InciInfo(io.github.asw.i3a.operatorsWebClient.entitites.InciInfo) Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Incident

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

the class IncidentController method getEdit.

@RequestMapping(value = "/incident/edit/{id}", method = RequestMethod.GET)
public String getEdit(Model model, @Nullable @CookieValue("operatorId") String opId, @PathVariable String id) {
    if (opId == null)
        return "redirect:/login";
    Incident incident = IncidentService.getIncident(id);
    model.addAttribute("incident", incident);
    log.info("Page for editing incident: " + id);
    return "incident/edit";
}
Also used : Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Incident

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

the class IncidentTest method extraTest.

@Test
public void extraTest() {
    Incident i = new Incident();
    i.setIncidentId("5aef2acdb1f3911fd0bdb41c");
    assertNotNull(i.getDate().equals("Sun May 06 18:18:21 CEST 2018"));
    Incident i2 = new Incident();
    assertTrue(i.canEquals(i2));
}
Also used : Incident(io.github.asw.i3a.operatorsWebClient.entitites.Incident) UnitTest(TestKit.UnitTest) Test(org.junit.Test)

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