Skip to content

Commit

Permalink
fix for reading all node list items from the ODE
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael7371 committed Nov 11, 2024
1 parent f52f3e8 commit c71236c
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Boolean getConfluentCloudStatus() {
private String impClientType = "Software";
private String impClientSubType = "Application";
private String impTopicType;
private String impCacheRegistration;
private Boolean impCacheRegistration;
private BigDecimal impMecLatitude;
private BigDecimal impMecLongitude;
private String impCertPath;
Expand Down Expand Up @@ -198,6 +198,8 @@ void initialize() {
String impMecLongitudeStr = CommonUtils.getEnvironmentVariable("IMP_MEC_LONGITUDE");
impMecLongitude = new BigDecimal(impMecLongitudeStr);
impCertPath = CommonUtils.getEnvironmentVariable("IMP_CERT_PATH");
impCacheRegistration = CommonUtils.getEnvironmentVariable("IMP_CACHE_REGISTRATION", "false")
.equalsIgnoreCase("true");
} else {
logger.info("IMP is disabled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ImpDepositorService(DepositorProperties properties) {

@KafkaListener(topics = "topic.OdeTimJsonTMCFiltered", groupId = "jpo-s3-depositor", concurrency = "${listen.concurrency:1}")
public void tmcTimListener(String message) {
boolean retain = true;
try {
OdeTimData timMsg = mapper.readValue(message, OdeTimData.class);
String asn1String = timMsg.getMetadata().getAsn1();
Expand All @@ -58,7 +59,7 @@ public void tmcTimListener(String message) {
log.info("Sending TIM message to MQTT topics: {}", topicList);

for (String topic : topicList) {
mqttService.publish(topic, geoRoutedMsg);
mqttService.publish(topic, geoRoutedMsg, retain);
}

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ public static SSLSocketFactory createSocketFactory(String caCertPath, String cli
return sslSocketFactory;
}

public void publish(String topic, GeoRoutedMsg geoRoutedMsg) throws MqttException {
boolean retained = false;
public void publish(String topic, GeoRoutedMsg geoRoutedMsg, boolean retain) throws MqttException {
log.debug("Publishing message to topic: {}", topic);
client.publish(topic, geoRoutedMsg.toByteArray(), 0, retained);
client.publish(topic, geoRoutedMsg.toByteArray(), 0, retain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,24 @@ public ConfigData registerClientPartner() {
try {
ConfigData configData;
String deviceID = null;
Boolean cacheRegistration = properties.getImpCacheRegistration();

String configPath = properties.getImpCertPath() + "/config.json";
String caCertPath = properties.getImpCertPath() + "/imp-ca.pem";
String certPath = properties.getImpCertPath() + "/imp-cert.pem";
String keyPath = properties.getImpCertPath() + "/imp-key.pem";

if (!validRegistration(configPath)) {
if (!validRegistration(configPath) || !cacheRegistration) {
log.info("Registering client partner");

long startTime = System.currentTimeMillis();
String token = getToken();
long tokenTime = System.currentTimeMillis();
log.info("Time to get token: " + (tokenTime - startTime) + " ms");

ClientRegistrationResponse registrationResponse = register(token);
long registrationTime = System.currentTimeMillis();
log.info("Time to register: " + (registrationTime - tokenTime) + " ms");

CommonUtils.writeToFile(caCertPath, registrationResponse.getCertificate().getCaPem());
CommonUtils.writeToFile(certPath, registrationResponse.getCertificate().getCertPem());
Expand All @@ -71,6 +78,8 @@ public ConfigData registerClientPartner() {
deviceID = registrationResponse.getDeviceID();

ClientConnectionResponse connectionResponse = connection(token, deviceID);
long connectionTime = System.currentTimeMillis();
log.info("Time to connect: " + (connectionTime - registrationTime) + " ms");

URI uri = new URI(connectionResponse.getMqttURL());
configData = new ConfigData(configPath, caCertPath, certPath, keyPath, properties.getImpVendor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public static List<double[]> getTimPathCoordList(OdeTimData timMessage) {
} else if (delta.getNodeLL2() != null) {
deltaLong = Double.parseDouble(delta.getNodeLL2().getLon()) / odeScaleFactor;
deltaLat = Double.parseDouble(delta.getNodeLL2().getLat()) / odeScaleFactor;
} else if (delta.getNodeLL3() != null) {
deltaLong = Double.parseDouble(delta.getNodeLL3().getLon()) / odeScaleFactor;
deltaLat = Double.parseDouble(delta.getNodeLL3().getLat()) / odeScaleFactor;
} else if (delta.getNodeLL4() != null) {
deltaLong = Double.parseDouble(delta.getNodeLL4().getLon()) / odeScaleFactor;
deltaLat = Double.parseDouble(delta.getNodeLL4().getLat()) / odeScaleFactor;
} else if (delta.getNodeLL5() != null) {
deltaLong = Double.parseDouble(delta.getNodeLL5().getLon()) / odeScaleFactor;
deltaLat = Double.parseDouble(delta.getNodeLL5().getLat()) / odeScaleFactor;
} else if (delta.getNodeLL6() != null) {
deltaLong = Double.parseDouble(delta.getNodeLL6().getLon()) / odeScaleFactor;
deltaLat = Double.parseDouble(delta.getNodeLL6().getLat()) / odeScaleFactor;
} else {
log.error("Error: Delta node not found");
return null;
Expand All @@ -117,7 +129,7 @@ public static List<double[]> getTimPathCoordList(OdeTimData timMessage) {

// Calculate the distance from the current point to the new point
double distance = haversine(currentLat, currentLong, newLat, newLong);
log.info("Distance: {}", distance);
log.debug("Distance: {}", distance);

// If the distance is greater than the threshold, add intermediate points
if (distance > thresholdDistance) {
Expand All @@ -136,7 +148,6 @@ public static List<double[]> getTimPathCoordList(OdeTimData timMessage) {
currentLat = newLat;
pathCoordinates.add(new double[] { currentLong, currentLat });
}
log.info("Path coordinates: {}", pathCoordinates);
return pathCoordinates;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,86 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "node-LL2", "node-LL1" })
@JsonPropertyOrder({ "node-LL2", "node-LL1", "node-LL3", "node-LL4", "node-LL5", "node-LL6" })
public class Delta implements Serializable {

@JsonProperty("node-LL2")
private NodeLL2 nodeLL2;
private NodeLLGeneric nodeLL2;
@JsonProperty("node-LL1")
private NodeLL1 nodeLL1;
private NodeLLGeneric nodeLL1;
private final static long serialVersionUID = 6901929116021526241L;

@JsonProperty("node-LL2")
public NodeLL2 getNodeLL2() {
public NodeLLGeneric getNodeLL2() {
return nodeLL2;
}

@JsonProperty("node-LL2")
public void setNodeLL2(NodeLL2 nodeLL2) {
public void setNodeLL2(NodeLLGeneric nodeLL2) {
this.nodeLL2 = nodeLL2;
}

@JsonProperty("node-LL1")
public NodeLL1 getNodeLL1() {
public NodeLLGeneric getNodeLL1() {
return nodeLL1;
}

@JsonProperty("node-LL1")
public void setNodeLL1(NodeLL1 nodeLL1) {
public void setNodeLL1(NodeLLGeneric nodeLL1) {
this.nodeLL1 = nodeLL1;
}

@JsonProperty("node-LL3")

private NodeLLGeneric nodeLL3;

@JsonProperty("node-LL4")
private NodeLLGeneric nodeLL4;

@JsonProperty("node-LL5")
private NodeLLGeneric nodeLL5;

@JsonProperty("node-LL6")
private NodeLLGeneric nodeLL6;

@JsonProperty("node-LL3")
public NodeLLGeneric getNodeLL3() {
return nodeLL3;
}

@JsonProperty("node-LL3")
public void setNodeLL3(NodeLLGeneric nodeLL3) {
this.nodeLL3 = nodeLL3;
}

@JsonProperty("node-LL4")
public NodeLLGeneric getNodeLL4() {
return nodeLL4;
}

@JsonProperty("node-LL4")
public void setNodeLL4(NodeLLGeneric nodeLL4) {
this.nodeLL4 = nodeLL4;
}

@JsonProperty("node-LL5")
public NodeLLGeneric getNodeLL5() {
return nodeLL5;
}

@JsonProperty("node-LL5")
public void setNodeLL5(NodeLLGeneric nodeLL5) {
this.nodeLL5 = nodeLL5;
}

@JsonProperty("node-LL6")
public NodeLLGeneric getNodeLL6() {
return nodeLL6;
}

@JsonProperty("node-LL6")
public void setNodeLL6(NodeLLGeneric nodeLL6) {
this.nodeLL6 = nodeLL6;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@

package us.dot.its.jpo.ode.s3.depositor.models.ode;

import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "lon", "lat" })
public class NodeLL1 implements Serializable {

@JsonProperty("lon")
private String lon;
@JsonProperty("lat")
private String lat;
private final static long serialVersionUID = -1382973741234036148L;

@JsonProperty("lon")
public String getLon() {
return lon;
}

@JsonProperty("lon")
public void setLon(String lon) {
this.lon = lon;
}

@JsonProperty("lat")
public String getLat() {
return lat;
}

@JsonProperty("lat")
public void setLat(String lat) {
this.lat = lat;
}

}

package us.dot.its.jpo.ode.s3.depositor.models.ode;

import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "lon", "lat" })
public class NodeLLGeneric implements Serializable {

@JsonProperty("lon")
private String lon;
@JsonProperty("lat")
private String lat;
private final static long serialVersionUID = -1382973741234036148L;

@JsonProperty("lon")
public String getLon() {
return lon;
}

@JsonProperty("lon")
public void setLon(String lon) {
this.lon = lon;
}

@JsonProperty("lat")
public String getLat() {
return lat;
}

@JsonProperty("lat")
public void setLat(String lat) {
this.lat = lat;
}

}

0 comments on commit c71236c

Please sign in to comment.