Skip to content

Commit 22422e4

Browse files
Added initialization of detail field in entity to ""
Switched up RabbitMQ topic handling to use cot_uid for distinguishing between an alert and an event Added a temporary location for events (Avon Park-ish) Updated default plugin prefs to same topic for event and entities Updated the support in the test client for images
1 parent 59e0ca5 commit 22422e4

5 files changed

Lines changed: 40 additions & 21 deletions

File tree

TAK Server Plugin/Plugin/src/takserver-sender-plugin-mcs/src/main/java/tak/server/plugins/McsSenderPlugin.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,25 @@ public void stop() {
107107
public void messageReceived(String topic, String message){
108108
try {
109109
Message takMessage = null;
110-
if(_rabbitMqConsumer.isEntityKey(topic)) {
111-
112-
EntityDto entity = McsCoTConverter.convertToEntity(message, config);
113-
if (entity == null){
110+
//Eventually the topic will be specific towards a message type (entity vs alert)
111+
//For now we will look for 'cot_uid' which is a key in an alert message
112+
if(message.contains("cot_uid")) {
113+
EventDto event = McsCoTConverter.convertToEvent(message, config);
114+
if (event == null){
114115
_logger.error("error converting message to event");
115116
return;
116117
}
117118

118-
takMessage = McsCoTConverter.convertToMessage(entity, config);
119+
takMessage = McsCoTConverter.convertToMessage(event, config);
119120
}
120-
121-
if(_rabbitMqConsumer.isEventKey(topic)) {
122-
123-
EventDto event = McsCoTConverter.convertToEvent(message, config);
124-
if (event == null){
121+
else {
122+
EntityDto entity = McsCoTConverter.convertToEntity(message, config);
123+
if (entity == null){
125124
_logger.error("error converting message to event");
126125
return;
127126
}
128127

129-
takMessage = McsCoTConverter.convertToMessage(event, config);
128+
takMessage = McsCoTConverter.convertToMessage(entity, config);
130129
}
131130

132131
if (takMessage == null){

TAK Server Plugin/Plugin/src/takserver-sender-plugin-mcs/src/main/java/tak/server/plugins/dto/EntityDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class EntityDto {
2525
@SerializedName("point")
2626
private PointDto _point = null;
2727

28-
private transient String _detail = null;
28+
private transient String _detail = "";
2929

3030
public String getUid() {
3131
return _uid;

TAK Server Plugin/Plugin/src/takserver-sender-plugin-mcs/src/main/java/tak/server/plugins/utilities/McsCoTConverter.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tak.server.plugins.utilities;
22

33
import java.util.List;
4+
import java.util.Random;
45
import java.time.Instant;
56

67
import com.google.gson.Gson;
@@ -54,8 +55,14 @@ public static Message convertToMessage(EventDto event, PluginConfiguration confi
5455
cotEventBuilder.setSendTime(timeMs);
5556
cotEventBuilder.setStartTime(timeMs);
5657
cotEventBuilder.setStaleTime(staleMs);
57-
cotEventBuilder.setLat(0.0);
58-
cotEventBuilder.setLon(0.0);
58+
//27.6615493 -81.2769707 - Generally around Avon Park
59+
Random r = new Random();
60+
double tempLat = 27.6615493 + r.nextDouble() * .08;
61+
double tempLon = -81.2769707 + r.nextDouble() * .08;
62+
63+
cotEventBuilder.setLat(tempLat);
64+
cotEventBuilder.setLon(tempLon);
65+
5966
cotEventBuilder.setHae(9999999);
6067
cotEventBuilder.setCe(9999999);
6168
cotEventBuilder.setLe(9999999);
@@ -129,14 +136,18 @@ private static String getFormattedEntityDetail(String entityDetail) {
129136
videoXml = JSONML.toString(videoJsonObject);
130137
}
131138

132-
//TODO - NEED TO HANDLE THE URL BASED IMAGES
133139
String imageValue = detailJsonObject.optString("image");
134140
String imageXml = "";
135141
if (imageValue != "") {
136142
JSONObject imageJsonObject = new JSONObject();
137143
imageJsonObject.put(tagName, "image");
138-
imageJsonObject.put("mime", imageValue.substring(imageValue.indexOf(':') + 1, imageValue.indexOf(';')));
139-
imageJsonObject.put(childNodes, new JSONArray().put(imageValue.substring(imageValue.indexOf(',') + 1)));
144+
if (imageValue.contains("data:image")){
145+
imageJsonObject.put("mime", imageValue.substring(imageValue.indexOf(':') + 1, imageValue.indexOf(';')));
146+
imageJsonObject.put(childNodes, new JSONArray().put(imageValue.substring(imageValue.indexOf(',') + 1)));
147+
}
148+
else {
149+
imageJsonObject.put("url", imageValue);
150+
}
140151
detailJsonObject.remove("image");
141152
imageXml = JSONML.toString(imageJsonObject);
142153
}

TAK Server Plugin/Plugin/src/takserver-sender-plugin-mcs/tak.server.plugins.McsSenderPlugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ rabbitmq:
99
entityKey: "dragonfly.demo_entities"
1010
publishEntityKey: "dragonfly.demo_entities"
1111
enableEntityRouting: true
12-
eventKey: "dragonfly.events"
12+
eventKey: "dragonfly.demo_entities"
1313
enableEventRouting: true
1414

TAK Server Plugin/RabbitMQ Client/Program.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ class Program
1212
{
1313
private static string EXCHANGE = "dragonfly";
1414
private static string ROUTING_KEY = "dragonfly.demo_entities";
15-
private static string EVENT_ROUTING_KEY = "dragonfly.events";
15+
private static string EVENT_ROUTING_KEY = "dragonfly.demo_entities";
1616
private static string RABBITMQ_HOSTNAME = "dragonfly.caeusa.com";
1717
private static string PASSWORD = "dragonfly";
1818
private static string USERNAME = "rapidx";
1919
private static bool USE_RAPIDX = true;
2020

21-
private static string MESSAGE = "{\"uid\":\"ExampleCompany.12345-abcde-6789-fghij\",\"type\":\"a-f-G-U-C\",\"time\":\"1614187736429\",\"start\":\"1614187736429\",\"stale\":\"1614191352000\",\"how\":\"m-g\",\"point\":{\"lat\":\"39.0495\",\"lon\":\"-85.7445\",\"hae\":\"9999999\",\"ce\":\"9999999\",\"le\":\"9999999\"},\"detail\":{\"milsym2525C\":\"SFGPUCI*****\", \"video\":\"https://cdn.bitdegree.org/learn/Pexels%20Videos%203373.mp4?raw=true\", \"image\": \"data:image/png;base64,IMAGEPLACEHOLDER\", \"feedType\":\"OSH_SENSOR\",\"serviceDetails\":{\"serviceUrl\":\"THE SERVICE URL\",\"provider\":{\"providerName\":\"SOME NAME\",\"providerData\":\"SOME DATA\"},\"offeringID\":\"THE OFFERING ID\",\"temporalData\":\"THE TEMPORAL DATA\"}}}";
21+
private static string MESSAGE = "{\"uid\":\"CustomIDForTAKServerTest.12345\",\"type\":\"a-f-G-U-C\",\"time\":\"1614187736429\",\"start\":\"1614187736429\",\"stale\":\"1614191352000\",\"how\":\"m-g\",\"point\":{\"lat\":\"39.0495\",\"lon\":\"-85.7445\",\"hae\":\"9999999\",\"ce\":\"9999999\",\"le\":\"9999999\"},\"detail\":{\"milsym2525C\":\"SFGPUCI*****\", \"video\":\"https://cdn.bitdegree.org/learn/Pexels%20Videos%203373.mp4?raw=true\", \"image\": \"IMAGEPLACEHOLDER\", \"feedType\":\"OSH_SENSOR\",\"serviceDetails\":{\"serviceUrl\":\"THE SERVICE URL\",\"provider\":{\"providerName\":\"SOME NAME\",\"providerData\":\"SOME DATA\"},\"offeringID\":\"THE OFFERING ID\",\"temporalData\":\"THE TEMPORAL DATA\"}}}";
2222

2323
private static string EVENT_MESSAGE = "{\"cot_uid\":\"b5034f03-b209-47a8-aa39-31d32e8ee337\",\"message\":\"This is a demo alert\",\"type\":\"warning\"}";
2424

25+
private static string IMAGE_URL = @"https://i.picsum.photos/id/1025/4951/3301.jpg?hmac=_aGh5AtoOChip_iaMo8ZvvytfEojcgqbCH7dzaz-H8Y";
26+
2527
private static Random _random = new Random();
2628
private static double MIN_LAT = 39.04;
2729
private static double MAX_LAT = 39.05;
@@ -106,7 +108,11 @@ private static string MassageMessage(string message)
106108
using (var sr = new StreamReader("Base64Image.txt"))
107109
imageBase64 = sr.ReadToEnd();
108110

109-
message = message.Replace("IMAGEPLACEHOLDER", imageBase64);
111+
var randomNumber = GetRandomNumber(0, 10);
112+
if(IsOdd(randomNumber))
113+
message = message.Replace("IMAGEPLACEHOLDER", @"data:image/png;base64," + imageBase64);
114+
else
115+
message = message.Replace("IMAGEPLACEHOLDER", IMAGE_URL);
110116

111117
var jObject = JObject.Parse(message);
112118

@@ -138,6 +144,9 @@ private static double GetRandomNumber(double minimum, double maximum)
138144
return _random.NextDouble() * (maximum - minimum) + minimum;
139145
}
140146

147+
private static bool IsOdd(double number) => Math.Round(number, 0) % 2 == 0;
148+
149+
141150
/*
142151
ConnectionFactory factory = new ConnectionFactory();
143152
factory.UserName = "rapidx";

0 commit comments

Comments
 (0)