Skip to content

Commit

Permalink
Update and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewjj committed Mar 15, 2024
1 parent b395a0d commit fae9efc
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ private void publishList(XmlUtils xmlUtils, List<OdeData> dataList) throws JsonP
publisher.getOdeProperties().getKafkaTopicOdeRawEncodedTIMJson());
}
}
}

serialId.increment();
serialId.increment();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public Asn1DecodeBSMJSON(OdeProperties odeProps) {
}

@Override
protected Object process(String consumedData) {
protected OdeAsn1Data process(String consumedData) {
OdeAsn1Data messageToPublish = null;
try {
JSONObject rawBsmJsonObject = new JSONObject(consumedData);

Expand All @@ -38,10 +39,11 @@ protected Object process(String consumedData) {
payloadHexString = super.stripDot2Header(payloadHexString);
OdeAsn1Payload payload = new OdeAsn1Payload(HexUtils.fromHexString(payloadHexString));

publishEncodedMessageToAsn1Decoder(new OdeAsn1Data(metadata, payload));
messageToPublish = new OdeAsn1Data(metadata, payload);
publishEncodedMessageToAsn1Decoder(messageToPublish);
} catch (Exception e) {
logger.error("Error publishing to Asn1DecoderInput: {}", e.getMessage());
}
return null;
return messageToPublish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public Asn1DecodeMAPJSON(OdeProperties odeProps) {
}

@Override
protected Object process(String consumedData) {
protected OdeAsn1Data process(String consumedData) {
OdeAsn1Data messageToPublish = null;
try {
JSONObject rawMapJsonObject = new JSONObject(consumedData);

Expand All @@ -39,11 +40,11 @@ protected Object process(String consumedData) {
payloadHexString = super.stripDot2Header(payloadHexString);
OdeAsn1Payload payload = new OdeAsn1Payload(HexUtils.fromHexString(payloadHexString));

publishEncodedMessageToAsn1Decoder(new OdeAsn1Data(metadata, payload));
messageToPublish = new OdeAsn1Data(metadata, payload);
publishEncodedMessageToAsn1Decoder(messageToPublish);
} catch (Exception e) {
logger.error("Error publishing to Asn1DecoderInput: {}", e.getMessage());
}

return null;
return messageToPublish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public Asn1DecodePSMJSON(OdeProperties odeProps) {
}

@Override
protected Object process(String consumedData) {
protected OdeAsn1Data process(String consumedData) {
OdeAsn1Data messageToPublish = null;
try {
JSONObject rawPsmJsonObject = new JSONObject(consumedData);

Expand All @@ -38,10 +39,11 @@ protected Object process(String consumedData) {
payloadHexString = super.stripDot2Header(payloadHexString);
OdeAsn1Payload payload = new OdeAsn1Payload(HexUtils.fromHexString(payloadHexString));

publishEncodedMessageToAsn1Decoder(new OdeAsn1Data(metadata, payload));
messageToPublish = new OdeAsn1Data(metadata, payload);
publishEncodedMessageToAsn1Decoder(messageToPublish);
} catch (Exception e) {
logger.error("Error publishing to Asn1DecoderInput: {}", e.getMessage());
}
return null;
return messageToPublish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public Asn1DecodeSPATJSON(OdeProperties odeProps) {
}

@Override
protected Object process(String consumedData) {
try {
protected OdeAsn1Data process(String consumedData) {
OdeAsn1Data messageToPublish = null;
try {
JSONObject rawSpatJsonObject = new JSONObject(consumedData);

String jsonStringMetadata = rawSpatJsonObject.get("metadata").toString();
Expand All @@ -34,15 +35,17 @@ protected Object process(String consumedData) {
Asn1Encoding unsecuredDataEncoding = new Asn1Encoding("unsecuredData", "MessageFrame", EncodingRule.UPER);
metadata.addEncoding(unsecuredDataEncoding);

String payloadHexString = ((JSONObject)((JSONObject) rawSpatJsonObject.get("payload")).get("data")).getString("bytes");
String payloadHexString = ((JSONObject) ((JSONObject) rawSpatJsonObject.get("payload")).get("data"))
.getString("bytes");
payloadHexString = super.stripDot2Header(payloadHexString);
OdeAsn1Payload payload = new OdeAsn1Payload(HexUtils.fromHexString(payloadHexString));

publishEncodedMessageToAsn1Decoder(new OdeAsn1Data(metadata, payload));
messageToPublish = new OdeAsn1Data(metadata, payload);
publishEncodedMessageToAsn1Decoder(messageToPublish);
} catch (Exception e) {
logger.error("Error publishing to Asn1DecoderInput: {}", e.getMessage());
}
return null;
return messageToPublish;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
import us.dot.its.jpo.ode.model.OdeSrmMetadata;

public class Asn1DecodeSRMJSON extends AbstractAsn1DecodeMessageJSON {
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Logger logger = LoggerFactory.getLogger(this.getClass());
private ObjectMapper objectMapper = new ObjectMapper();

public Asn1DecodeSRMJSON(OdeProperties odeProps) {
super(new StringPublisher(odeProps), odeProps.getSrmStartFlag());
}

@Override
protected Object process(String consumedData) {
try {
protected OdeAsn1Data process(String consumedData) {
OdeAsn1Data messageToPublish = null;
try {
JSONObject rawSrmJsonObject = new JSONObject(consumedData);

String jsonStringMetadata = rawSrmJsonObject.get("metadata").toString();
Expand All @@ -34,14 +35,16 @@ protected Object process(String consumedData) {
Asn1Encoding unsecuredDataEncoding = new Asn1Encoding("unsecuredData", "MessageFrame", EncodingRule.UPER);
metadata.addEncoding(unsecuredDataEncoding);

String payloadHexString = ((JSONObject)((JSONObject) rawSrmJsonObject.get("payload")).get("data")).getString("bytes");
String payloadHexString = ((JSONObject) ((JSONObject) rawSrmJsonObject.get("payload")).get("data"))
.getString("bytes");
payloadHexString = super.stripDot2Header(payloadHexString);
OdeAsn1Payload payload = new OdeAsn1Payload(HexUtils.fromHexString(payloadHexString));

publishEncodedMessageToAsn1Decoder(new OdeAsn1Data(metadata, payload));
messageToPublish = new OdeAsn1Data(metadata, payload);
publishEncodedMessageToAsn1Decoder(messageToPublish);
} catch (Exception e) {
logger.error("Error publishing to Asn1DecoderInput: {}", e.getMessage());
}
return null;
return messageToPublish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
import us.dot.its.jpo.ode.model.OdeSsmMetadata;

public class Asn1DecodeSSMJSON extends AbstractAsn1DecodeMessageJSON {
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Logger logger = LoggerFactory.getLogger(this.getClass());
private ObjectMapper objectMapper = new ObjectMapper();

public Asn1DecodeSSMJSON(OdeProperties odeProps) {
super(new StringPublisher(odeProps), odeProps.getSsmStartFlag());
}

@Override
protected Object process(String consumedData) {
try {
protected OdeAsn1Data process(String consumedData) {
OdeAsn1Data messageToPublish = null;
try {
JSONObject rawSsmJsonObject = new JSONObject(consumedData);

String jsonStringMetadata = rawSsmJsonObject.get("metadata").toString();
Expand All @@ -34,14 +35,16 @@ protected Object process(String consumedData) {
Asn1Encoding unsecuredDataEncoding = new Asn1Encoding("unsecuredData", "MessageFrame", EncodingRule.UPER);
metadata.addEncoding(unsecuredDataEncoding);

String payloadHexString = ((JSONObject)((JSONObject) rawSsmJsonObject.get("payload")).get("data")).getString("bytes");
String payloadHexString = ((JSONObject) ((JSONObject) rawSsmJsonObject.get("payload")).get("data"))
.getString("bytes");
payloadHexString = super.stripDot2Header(payloadHexString);
OdeAsn1Payload payload = new OdeAsn1Payload(HexUtils.fromHexString(payloadHexString));

publishEncodedMessageToAsn1Decoder(new OdeAsn1Data(metadata, payload));
messageToPublish = new OdeAsn1Data(metadata, payload);
publishEncodedMessageToAsn1Decoder(messageToPublish);
} catch (Exception e) {
logger.error("Error publishing to Asn1DecoderInput: {}", e.getMessage());
}
return null;
return messageToPublish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public Asn1DecodeTIMJSON(OdeProperties odeProps) {
}

@Override
protected Object process(String consumedData) {
protected OdeAsn1Data process(String consumedData) {
OdeAsn1Data messageToPublish = null;
try {
JSONObject rawTimJsonObject = new JSONObject(consumedData);

Expand All @@ -38,10 +39,11 @@ protected Object process(String consumedData) {
payloadHexString = super.stripDot2Header(payloadHexString);
OdeAsn1Payload payload = new OdeAsn1Payload(HexUtils.fromHexString(payloadHexString));

publishEncodedMessageToAsn1Decoder(new OdeAsn1Data(metadata, payload));
messageToPublish = new OdeAsn1Data(metadata, payload);
publishEncodedMessageToAsn1Decoder(messageToPublish);
} catch (Exception e) {
logger.error("Error publishing to Asn1DecoderInput: {}", e.getMessage());
}
return null;
return messageToPublish;
}
}
Loading

0 comments on commit fae9efc

Please sign in to comment.