Skip to content

Commit

Permalink
Added conversion for ProcessedMap and ProcessedSpat
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Wiens committed May 10, 2024
1 parent 7ec86f8 commit cd4d96b
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package us.dot.its.jpo.ode.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand All @@ -11,13 +12,18 @@
import us.dot.its.jpo.ode.api.models.messages.DecodedMessage;
import us.dot.its.jpo.ode.api.models.messages.EncodedMessage;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableWebMvc
@SpringBootApplication
@EnableScheduling
@ComponentScan(basePackages = {"us.dot.its.jpo.ode.api", "us.dot.its.jpo.geojsonconverter.validator"})
public class ConflictApiApplication extends SpringBootServletInitializer {

@Autowired DecoderManager manager;

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ConflictApiApplication.class);
Expand All @@ -29,12 +35,12 @@ public static void main(String[] args) {
System.out.println("Conflict Monitor API docs page found here: http://localhost:8081/swagger-ui/index.html");
System.out.println("Startup Complete");

DecodedMessage bsm = DecoderManager.decode(new EncodedMessage("00145144ad0b7947c2ed9ad2748035a4e8ff880000000fd2229199307d7d07d0b17fff05407d12720038c000fe72c107b001ea88fffeb4002127c0009000000fdfffe3ffff9407344704000041910120100000000efc10609c26e900e11f61a947802127c0009000000fdfffe3ffff9407453304000041910120100000008ffffe501ca508100000000000a508100000404804000000849f00024000003f7fff8ffffe501ca508100000fe501ca508100000fffe501ca51c10000000024000003f7fff8ffffe501ca51c1", MessageType.BSM));
// DecodedMessage bsm = manager.decode(new EncodedMessage("00145144ad0b7947c2ed9ad2748035a4e8ff880000000fd2229199307d7d07d0b17fff05407d12720038c000fe72c107b001ea88fffeb4002127c0009000000fdfffe3ffff9407344704000041910120100000000efc10609c26e900e11f61a947802127c0009000000fdfffe3ffff9407453304000041910120100000008ffffe501ca508100000000000a508100000404804000000849f00024000003f7fff8ffffe501ca508100000fe501ca508100000fffe501ca51c10000000024000003f7fff8ffffe501ca51c1", MessageType.BSM));

System.out.println(bsm);

// System.out.println(bsm);




// System.out.println("Fully Decoded BSM" + bsm.getBsm());
// OdeBsmData decodeTest;
Expand All @@ -47,6 +53,14 @@ public static void main(String[] args) {
// }
}

@Bean
public void test(){
System.out.println("Running Decoder");
DecodedMessage map = manager.decode(new EncodedMessage("0012839338023000205e96094d40df4c2ca626c8516e02dc3c2010640000000289e01c009f603f42e88039900000000a41107b027d80fd0a4200c6400000002973021c09f603de0c16029200000080002a8a008d027d98fee805404fb0e1085f60588200028096021200000080002aa0007d027d98fe9802e04fb1200c214456228000a02b1240005022c03240000020000d56b40bc04fb35ff655e2c09f623fb81c835fec0db240a0a2bff4aebf82c660000804b0089000000800025670034013ecd7fb9578e027d9aff883c4e050515ffa567a41635000040258024800000400012b8f81f409f663fac094013ecd7fc83ddb02829affa480bc04fb02c6e0000804b09c5000000200035ea98a9604f60da6c7c113d505c35ffe941d409f65c05034c050500c9880004409bc800000006d2bd3cec813c40cde062c1fd400000200008791ea3db3cf380a009f666f05005813d80ffe0a0588c00040092106a00000000bc75cac009f66db54c04a813d80a100801241ed40000000078ebae3b6da7a008809e2050904008811f100000000bc72389009f60eca8002049c400000002f1b2ca3027d93a71fa813ec204bc400000002f1b2b34027b0397608880cd10000000039b8e1a51036820505080d51000000003a7461ed1036760505080dd1000000003b2f62311006260505160bca00000080002b785e2a80a0a6c028de728145037f1f9e456488000202b2540001022c1894000001000057058c5b81414d806dbcd4028a18f4df23a050502c8d0000404b05a5000000800035b6471bc05053602431f380a2864087bdb0141458064ab0d6c00053fc013ec0b0680006012c15940000020000d6c06c6581414d807fb972028a1901d78dc050536020ec1800a0a6c039d639813d80b0780006012c1494000002000096ab8c6581414d8062be32028a1b01417e04050a360172d77009e2058440003009409c200000040006b3486a480a0a1cab7134c8117dcc02879b018fae2c050f3601ced54809e21012720000000067fbad0007e7e84045c80000000100661580958004041c8000000019f3658401cdfa2c0d64000002000144016c02c36ddfff0282984acc1ee05052c36f0ac02828669d82da8f821480a0a10f140002c8e0001004b03190000008000519fd190c43b2e0066108b08401428c342a0ce02828258a0604a6be959aee0e6050502c920001004b02d90000008000459fa164404fb30a8580a00a14619c306701414c32ce10e02829659081f814141029030164b000080200",MessageType.MAP));
System.out.println(map);

}

// @Bean
// public WebMvcConfigurer corsConfigurer() {
// return new WebMvcConfigurer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package us.dot.its.jpo.ode.api.asn1;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -28,6 +30,8 @@
import us.dot.its.jpo.ode.util.XmlUtils;
import us.dot.its.jpo.ode.util.XmlUtils.XmlUtilsException;


@Component
public class BsmDecoder implements Decoder {


Expand All @@ -44,8 +48,8 @@ public DecodedMessage decode(EncodedMessage message) {
String xml = xmlUtils.toXml(data);

// Send String through ASN.1 Decoder to get Decoded XML Data
// String decodedXml = DecoderManager.decodeXmlWithAcm(xml);
String decodedXml = mockDecodeXmlWithAcm(xml);
String decodedXml = DecoderManager.decodeXmlWithAcm(xml);
// String decodedXml = mockDecodeXmlWithAcm(xml);

// Convert to Ode Json
OdeBsmData bsm = getAsOdeJson(decodedXml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.*;
import java.nio.charset.StandardCharsets;
Expand All @@ -27,6 +28,24 @@ public class DecoderManager {
public static final int HEADER_MINIMUM_SIZE = 20;
public static final int bufferSize = 2048;

@Autowired
public BsmDecoder bsmDecoder;

@Autowired
public MapDecoder mapDecoder;

@Autowired
public SpatDecoder spatDecoder;

@Autowired
public SrmDecoder srmDecoder;

@Autowired
public SsmDecoder ssmDecoder;

@Autowired
public TimDecoder timDecoder;

// public static DecodedMessage decode(String inputAsn1){

// // Identify Message Type and Cut off any extra characters
Expand Down Expand Up @@ -64,7 +83,7 @@ public class DecoderManager {
// return null;
// }

public static DecodedMessage decode(EncodedMessage message){
public DecodedMessage decode(EncodedMessage message){
String payload = removeHeader(message.getAsn1Message(), message.getType());
message.setAsn1Message(payload);

Expand All @@ -75,15 +94,20 @@ public static DecodedMessage decode(EncodedMessage message){
decoder = new BsmDecoder();
}
else if(message.getType() == MessageType.MAP){
decoder = new MapDecoder();
// decoder = new MapDecoder();
decoder = mapDecoder;
}else if(message.getType() == MessageType.SPAT){
decoder = new SpatDecoder();
// decoder = new SpatDecoder();
decoder = spatDecoder;
}else if(message.getType() == MessageType.SRM){
decoder = new SrmDecoder();
// decoder = new SrmDecoder();
decoder = srmDecoder;
}else if(message.getType() == MessageType.SSM){
decoder = new SsmDecoder();
// decoder = new SsmDecoder();
decoder = ssmDecoder;
}else if(message.getType() == MessageType.TIM){
decoder = new TimDecoder();
// decoder = new TimDecoder();
decoder = timDecoder;
}else{
return new DecodedMessage(payload, message.getType(), "No Valid Decoder found for Message Type");
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package us.dot.its.jpo.ode.api.asn1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import us.dot.its.jpo.ode.api.models.messages.SpatDecodedMessage;
import us.dot.its.jpo.geojsonconverter.converter.spat.SpatProcessedJsonConverter;
import us.dot.its.jpo.geojsonconverter.partitioner.RsuIntersectionKey;
import us.dot.its.jpo.geojsonconverter.pojos.spat.ProcessedSpat;
import us.dot.its.jpo.geojsonconverter.validator.JsonValidatorResult;
import us.dot.its.jpo.geojsonconverter.validator.SpatJsonValidator;
import us.dot.its.jpo.ode.api.models.messages.DecodedMessage;
import us.dot.its.jpo.ode.api.models.messages.EncodedMessage;
import us.dot.its.jpo.ode.context.AppContext;
Expand All @@ -24,13 +32,21 @@
import us.dot.its.jpo.ode.model.OdeMsgPayload;
import us.dot.its.jpo.ode.model.ReceivedMessageDetails;
import us.dot.its.jpo.ode.model.RxSource;
import us.dot.its.jpo.ode.plugin.j2735.J2735IntersectionState;
import us.dot.its.jpo.ode.plugin.j2735.builders.SPATBuilder;
import us.dot.its.jpo.ode.util.JsonUtils;
import us.dot.its.jpo.ode.util.XmlUtils;
import us.dot.its.jpo.ode.util.XmlUtils.XmlUtilsException;


@Component
public class SpatDecoder implements Decoder {

@Autowired
SpatJsonValidator spatJsonValidator;

public SpatProcessedJsonConverter converter = new SpatProcessedJsonConverter();


@Override
public DecodedMessage decode(EncodedMessage message) {
Expand All @@ -52,8 +68,12 @@ public DecodedMessage decode(EncodedMessage message) {
OdeSpatData spat = getAsOdeJson(decodedXml);

// build output data structure
DecodedMessage decodedMessage = new SpatDecodedMessage(null, spat, message.getAsn1Message(), "");
return decodedMessage;
try{
ProcessedSpat processedSpat = createProcessedSpat(spat);
return new SpatDecodedMessage(processedSpat, spat, message.getAsn1Message(), "");
} catch(Exception e) {
return new SpatDecodedMessage(null, spat, message.getAsn1Message(), e.getMessage());
}

} catch (JsonProcessingException e) {
e.printStackTrace();
Expand Down Expand Up @@ -132,4 +152,24 @@ public OdeSpatData getAsOdeJson(String consumedData) throws XmlUtilsException {
return new OdeSpatData(metadata, payload);
}

public ProcessedSpat createProcessedSpat(OdeSpatData odeSpat){

JsonValidatorResult validationResults = spatJsonValidator.validate(odeSpat.toString());
OdeSpatData rawValue = new OdeSpatData();
rawValue.setMetadata(odeSpat.getMetadata());
OdeSpatMetadata spatMetadata = (OdeSpatMetadata)rawValue.getMetadata();

rawValue.setPayload(odeSpat.getPayload());
OdeSpatPayload spatPayload = (OdeSpatPayload)rawValue.getPayload();
J2735IntersectionState intersectionState = spatPayload.getSpat().getIntersectionStateList().getIntersectionStatelist().get(0);

ProcessedSpat processedSpat = converter.createProcessedSpat(intersectionState, spatMetadata, validationResults);

var key = new RsuIntersectionKey();
key.setRsuId(spatMetadata.getOriginIp());
key.setIntersectionReferenceID(intersectionState.getId());
return processedSpat;

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package us.dot.its.jpo.ode.api.asn1;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -26,6 +28,8 @@
import us.dot.its.jpo.ode.util.XmlUtils;
import us.dot.its.jpo.ode.util.XmlUtils.XmlUtilsException;


@Component
public class SrmDecoder implements Decoder {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package us.dot.its.jpo.ode.api.asn1;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -26,6 +28,7 @@
import us.dot.its.jpo.ode.util.XmlUtils;
import us.dot.its.jpo.ode.util.XmlUtils.XmlUtilsException;

@Component
public class SsmDecoder implements Decoder {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package us.dot.its.jpo.ode.api.asn1;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -23,6 +25,7 @@
import us.dot.its.jpo.ode.util.XmlUtils;
import us.dot.its.jpo.ode.util.XmlUtils.XmlUtilsException;

@Component
public class TimDecoder implements Decoder {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class DecoderController {
@Autowired
ConflictMonitorApiProperties props;

@Autowired DecoderManager decoderManager;

// private StringPublisher bsmPublisher;

public String getCurrentTime() {
Expand Down Expand Up @@ -119,7 +121,7 @@ public String getCurrentTime() {
}
}

DecodedMessage decodedMessage = DecoderManager.decode(encodedMessage);
DecodedMessage decodedMessage = decoderManager.decode(encodedMessage);

return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN)
.body(decodedMessage.toString());
Expand Down
Binary file added jpo-conflictvisualizer-api/test.pdf
Binary file not shown.

0 comments on commit cd4d96b

Please sign in to comment.