-
Notifications
You must be signed in to change notification settings - Fork 3
Address Comments from #49: Improve Logging and JSON Handling #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
payneBrandon
merged 10 commits into
release/v2.0
from
pr/addressing-comments-for-release-2.0
Apr 18, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d64bb9f
Added warn log statement for when 'itis' or 'text' not found in item …
dmccoystephenson 6f3fba5
Added another warn log statement for when 'itis' or 'text' not found …
dmccoystephenson e0c5c74
Set default frameType to 'advisory' when missing in JSON.
dmccoystephenson 4921818
Replaced usages of `System.out` with slf4j logging in JsonToJavaConve…
dmccoystephenson 8c912f4
Refactor: remove unused conversion methods and imports
dmccoystephenson bdb6408
Make ObjectMapper instance final in JsonToJavaConverter
dmccoystephenson a9aa1ec
Refactor TIM test data handling with external JSON file
dmccoystephenson 13adeb1
Set ACM_LOG_LEVEL via environment variable for local deployment
dmccoystephenson ed575b4
Merge remote-tracking branch 'origin/dev' into pr/addressing-comments…
dmccoystephenson 98992ab
Merge branch 'release/v2.0' into pr/addressing-comments-for-release-2.0
dmccoystephenson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
|
@@ -29,8 +30,6 @@ | |
| import us.dot.its.jpo.ode.plugin.SNMP; | ||
| import us.dot.its.jpo.ode.plugin.ServiceRequest; | ||
| import us.dot.its.jpo.ode.plugin.SnmpProtocol; | ||
| import us.dot.its.jpo.ode.plugin.j2735.J2735SpecialVehicleExtensions; | ||
| import us.dot.its.jpo.ode.plugin.j2735.J2735SupplementalVehicleExtensions; | ||
| import us.dot.its.jpo.ode.plugin.j2735.OdePosition3D; | ||
| import us.dot.its.jpo.ode.plugin.j2735.OdeTravelerInformationMessage; | ||
| import us.dot.its.jpo.ode.plugin.j2735.OdeTravelerInformationMessage.DataFrame.Region; | ||
|
|
@@ -40,45 +39,15 @@ | |
| import us.dot.its.jpo.ode.util.JsonUtils; | ||
|
|
||
| @Component | ||
| @Slf4j | ||
| public class JsonToJavaConverter { | ||
|
|
||
| private ObjectMapper mapper = new ObjectMapper(); | ||
| private final ObjectMapper mapper = new ObjectMapper(); | ||
|
|
||
| public JsonToJavaConverter() { | ||
| mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
| } | ||
|
|
||
| public J2735SpecialVehicleExtensions convertJ2735SpecialVehicleExtensionsJsonToJava(String value, int i) { | ||
|
|
||
| JsonNode part2Node = getPart2Node(value, i); | ||
| J2735SpecialVehicleExtensions spve = null; | ||
| try { | ||
| spve = mapper.treeToValue(part2Node, J2735SpecialVehicleExtensions.class); | ||
| } catch (JsonProcessingException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return spve; | ||
| } | ||
|
|
||
| public J2735SupplementalVehicleExtensions convertJ2735SupplementalVehicleExtensionsJsonToJava(String value, int i) { | ||
|
|
||
| JsonNode part2Node = getPart2Node(value, i); | ||
| J2735SupplementalVehicleExtensions suve = null; | ||
| try { | ||
| suve = mapper.treeToValue(part2Node, J2735SupplementalVehicleExtensions.class); | ||
| } catch (JsonProcessingException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return suve; | ||
| } | ||
|
|
||
| public JsonNode getPart2Node(String value, int i) { | ||
| JsonNode part2 = JsonUtils.getJsonNode(value, "payload").get("data").get("partII"); | ||
| if (part2 != null) | ||
| return part2.get(i).get("value"); | ||
| return null; | ||
| } | ||
|
|
||
| public OdeLogMetadata convertTimMetadataJsonToJava(String value) { | ||
|
|
||
| OdeLogMetadata odeTimMetadata = null; | ||
|
|
@@ -95,13 +64,12 @@ public OdeLogMetadata convertTimMetadataJsonToJava(String value) { | |
| ((ObjectNode) metaDataNode).replace("receivedMessageDetails", receivedMessageDetailsNode); | ||
| } | ||
| } | ||
| // System.out.println(metaDataNode); | ||
| log.trace("MetaDataNode: {}", metaDataNode); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: This was a commented out System.out print and has been changed to a TRACE level log. |
||
| odeTimMetadata = mapper.treeToValue(metaDataNode, OdeLogMetadata.class); | ||
| } catch (IOException e) { | ||
| System.out.println("IOException"); | ||
| System.out.println(e.getStackTrace()); | ||
| log.error("An IOException occurred while converting TIM metadata JSON to Java", e); | ||
| } catch (NullPointerException e) { | ||
| System.out.println(e.getMessage()); | ||
| log.error("A NullPointerException occurred while converting TIM metadata JSON to Java: {}", e.getMessage()); | ||
| } | ||
|
|
||
| return odeTimMetadata; | ||
|
|
@@ -166,10 +134,10 @@ public OdeRequestMsgMetadata convertBroadcastTimMetadataJsonToJava(String value) | |
| } | ||
|
|
||
| } catch (IOException e) { | ||
| System.out.println("IOException"); | ||
| System.out.println(e.getStackTrace()); | ||
| log.error("An IOException occurred while converting Broadcast TIM metadata JSON to Java", e); | ||
| } catch (NullPointerException e) { | ||
| System.out.println(e.getMessage()); | ||
| log.error("A NullPointerException occurred while converting Broadcast TIM metadata JSON to Java: {}", | ||
| e.getMessage()); | ||
| } | ||
| return odeTimMetadata; | ||
| } | ||
|
|
@@ -359,7 +327,7 @@ else if (sequenceArrNode.get("item").get("text") != null) | |
| regions.add(region); | ||
| } | ||
| } else { | ||
| System.out.println("warning: geographicalPathNode is not an object or an array"); | ||
| log.warn("geographicalPathNode is not an object or an array"); | ||
| } | ||
|
|
||
| dataFrame.setRegions(regions.toArray(new OdeTravelerInformationMessage.DataFrame.Region[regions.size()])); | ||
|
|
@@ -369,9 +337,9 @@ else if (sequenceArrNode.get("item").get("text") != null) | |
| odeTimPayload = new OdeTimPayload(); | ||
| odeTimPayload.setData(tim); | ||
| } catch (IOException e) { | ||
| System.out.println(e.getStackTrace()); | ||
| log.error("An IOException occurred while converting TIM JSON to Java", e); | ||
| } catch (NullPointerException e) { | ||
| System.out.println(e.getMessage()); | ||
| log.error("A NullPointerException occurred while converting TIM JSON to Java: {}", e.getMessage()); | ||
| } | ||
|
|
||
| return odeTimPayload; | ||
|
|
@@ -523,21 +491,28 @@ public OdeTimPayload convertTmcTimTopicJsonToJava(String value) { | |
| String item = null; | ||
| if (sequenceArrNode != null && sequenceArrNode.isArray()) { | ||
| for (final JsonNode objNode : sequenceArrNode) { | ||
| if (objNode.get("item").get("itis") != null) | ||
| if (objNode.get("item").get("itis") != null) { | ||
| item = mapper.treeToValue(objNode.get("item").get("itis"), String.class); | ||
| else if (objNode.get("item").get("text") != null) | ||
| } else if (objNode.get("item").get("text") != null) { | ||
| item = mapper.treeToValue(objNode.get("item").get("text"), String.class); | ||
| if (!itemsList.contains(item)) | ||
| } else { | ||
| log.warn("'itis' or 'text' not found in item when converting TMC TIM"); | ||
| } | ||
| if (!itemsList.contains(item)) { | ||
| itemsList.add(item); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ADD NON ARRAY ELEMENT | ||
| if (sequenceArrNode != null && !sequenceArrNode.isArray()) { | ||
| if (sequenceArrNode.get("item").get("itis") != null) | ||
| if (sequenceArrNode.get("item").get("itis") != null) { | ||
| item = mapper.treeToValue(sequenceArrNode.get("item").get("itis"), String.class); | ||
| else if (sequenceArrNode.get("item").get("text") != null) | ||
| } else if (sequenceArrNode.get("item").get("text") != null) { | ||
| item = mapper.treeToValue(sequenceArrNode.get("item").get("text"), String.class); | ||
| } else { | ||
| log.warn("'itis' or 'text' not found in item when converting TMC TIM"); | ||
| } | ||
|
|
||
| itemsList.add(item); | ||
| } | ||
|
|
@@ -547,6 +522,9 @@ else if (sequenceArrNode.get("item").get("text") != null) | |
| if (frameTypeNode != null && frameTypeNode.fieldNames().hasNext()) { | ||
| TravelerInfoType frameType = TravelerInfoType.valueOf(frameTypeNode.fieldNames().next()); | ||
| dataFrame.setFrameType(frameType); | ||
| } else { | ||
| log.warn("frameType not found in TravelerDataFrame when converting TMC TIM. Defaulting to 'advisory'"); | ||
| dataFrame.setFrameType(TravelerInfoType.advisory); | ||
| } | ||
|
|
||
| JsonNode startTimeNode = travelerDataFrame.get("startTime"); | ||
|
|
@@ -576,7 +554,7 @@ else if (sequenceArrNode.get("item").get("text") != null) | |
| regions.add(region); | ||
| } | ||
| } else { | ||
| System.out.println("warning: geographicalPathNode is not an object or an array"); | ||
| log.warn("geographicalPathNode is not an object or an array"); | ||
| } | ||
|
|
||
| dataFrame.setRegions(regions.toArray(OdeTravelerInformationMessage.DataFrame.Region[]::new)); | ||
|
|
@@ -587,9 +565,9 @@ else if (sequenceArrNode.get("item").get("text") != null) | |
| odeTimPayload = new OdeTimPayload(); | ||
| odeTimPayload.setData(tim); | ||
| } catch (IOException e) { | ||
| System.out.println(e.getStackTrace()); | ||
| log.error("An IOException occurred while converting TMC TIM JSON to Java", e); | ||
| } catch (NullPointerException e) { | ||
| System.out.println(e.getMessage()); | ||
| log.error("A NullPointerException occurred while converting TMC TIM JSON to Java: {}", e.getMessage()); | ||
| } | ||
|
|
||
| return odeTimPayload; | ||
|
|
@@ -603,9 +581,9 @@ public OdeTravelerInformationMessage convertBroadcastTimPayloadJsonToJava(String | |
| JsonNode timNode = JsonUtils.getJsonNode(value, "payload").get("data"); | ||
| odeTim = mapper.treeToValue(timNode, OdeTravelerInformationMessage.class); | ||
| } catch (IOException e) { | ||
| System.out.println(e.getStackTrace()); | ||
| log.error("An IOException occurred while converting Broadcast TIM JSON to Java", e); | ||
| } catch (NullPointerException e) { | ||
| System.out.println(e.getMessage()); | ||
| log.error("A NullPointerException occurred while converting Broadcast TIM JSON to Java: {}", e.getMessage()); | ||
| } | ||
|
|
||
| return odeTim; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ry/src/test/resources/com/trihydro/library/service/mockOdeTravelerInformationMessage.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| { | ||
| "msgCnt": "1", | ||
| "timeStamp": "2017-08-03T22:25:36.297Z", | ||
| "urlB": "null", | ||
| "packetID": "EC9C236B0000000000", | ||
| "dataframes": [ | ||
| { | ||
| "startDateTime": "2017-08-02T22:25:00.000Z", | ||
| "durationTime": 1, | ||
| "doNotUse1": "0", | ||
| "frameType": "advisory", | ||
| "msgId": { | ||
| "roadSignID": { | ||
| "position": { | ||
| "latitude": "41.678473", | ||
| "longitude": "-108.782775", | ||
| "elevation": "917.1432" | ||
| }, | ||
| "viewAngle": "1010101010101010", | ||
| "mutcdCode": "warning", | ||
| "crc": "0000" | ||
| } | ||
| }, | ||
| "priority": "0", | ||
| "doNotUse2": "3", | ||
| "regions": [ | ||
| { | ||
| "name": "Testing TIM", | ||
| "regulatorID": "0", | ||
| "segmentID": "33", | ||
| "anchorPosition": { | ||
| "latitude": "41.2500807", | ||
| "longitude": "-111.0093847", | ||
| "elevation": "2020.6969900289998" | ||
| }, | ||
| "laneWidth": "7", | ||
| "directionality": "3", | ||
| "closedPath": "false", | ||
| "description": "path", | ||
| "path": { | ||
| "scale": "0", | ||
| "type": "ll", | ||
| "nodes": [ | ||
| { | ||
| "nodeLong": "0.0030982", | ||
| "nodeLat": "0.0014562", | ||
| "delta": "node-LL3" | ||
| }, | ||
| { | ||
| "nodeLong": "-111.0093847", | ||
| "nodeLat": "41.2500807", | ||
| "delta": "node-LatLon" | ||
| } | ||
| ] | ||
| }, | ||
| "direction": "0000000000001010" | ||
| } | ||
| ], | ||
| "doNotUse4": "2", | ||
| "doNotUse3": "3", | ||
| "content": "Advisory", | ||
| "items": [ | ||
| "125", | ||
| "some text", | ||
| "250", | ||
| "'98765" | ||
| ], | ||
| "url": "null" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: These methods were not used