Skip to content

Commit

Permalink
Merge branch 'Add-event-count-widget' of github.com:usdot-jpo-ode/jpo…
Browse files Browse the repository at this point in the history
…-conflictvisualizer into Add-event-count-widget
  • Loading branch information
John-Wiens committed May 28, 2024
2 parents 4bc342f + b7fc64d commit 177b696
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jpo-conflictmonitor
Submodule jpo-conflictmonitor updated from e658cc to f0c6e6
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package us.dot.its.jpo.ode.api.controllers;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer;

import us.dot.its.jpo.conflictmonitor.monitor.models.bsm.BsmIntersectionIdKey;
import us.dot.its.jpo.geojsonconverter.pojos.geojson.LineString;
import us.dot.its.jpo.geojsonconverter.pojos.geojson.map.ProcessedMap;
import us.dot.its.jpo.geojsonconverter.pojos.spat.ProcessedSpat;
import us.dot.its.jpo.ode.api.models.LiveFeedSessionIndex;
import us.dot.its.jpo.ode.model.OdeBsmData;

@Controller
Expand All @@ -20,6 +26,24 @@ public class StompController {
@Autowired
private SimpMessagingTemplate brokerMessagingTemplate;

private ObjectMapper mapper;

StompController(){
mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());

DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_INSTANT;
ZonedDateTimeSerializer zonedDateTimeSerializer = new ZonedDateTimeSerializer(dateTimeFormatter);

SimpleModule module = new SimpleModule();
module.addSerializer(ZonedDateTime.class, zonedDateTimeSerializer);
mapper.registerModule(module);

mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
}



// @Scheduled(fixedRate = 10000) // Broadcast a message every second
public void broadcastMessage(String topic, String message) {
brokerMessagingTemplate.convertAndSend(topic, message);
Expand All @@ -41,7 +65,13 @@ public void broadcastSpat(ProcessedSpat spat) {
}

if (intersectionID != -1) {
broadcastMessage(buildTopicName(-1, intersectionID, "spat"), spat.toString());
try {
broadcastMessage(buildTopicName(-1, intersectionID, "spat"), mapper.writeValueAsString(spat));
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

Expand All @@ -57,13 +87,23 @@ public void broadcastMap(ProcessedMap<LineString> map) {
}

if (intersectionID != -1) {
broadcastMessage(buildTopicName(-1, intersectionID, "map"), map.toString());
try {
broadcastMessage(buildTopicName(-1, intersectionID, "map"), mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public void broadcastBSM(BsmIntersectionIdKey key, OdeBsmData bsm) {
if (key.getIntersectionId() != -1) {
broadcastMessage(buildTopicName(-1, key.getIntersectionId(), "bsm"), bsm.toString());
try {
broadcastMessage(buildTopicName(-1, key.getIntersectionId(), "bsm"), mapper.writeValueAsString(bsm));
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Expand Down

0 comments on commit 177b696

Please sign in to comment.