forked from usdot-jpo-ode/jpo-cvmanager
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
747def7
commit 121965e
Showing
5 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
100 changes: 100 additions & 0 deletions
100
...ictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/DecoderController.java
This file contains 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,100 @@ | ||
package us.dot.its.jpo.ode.api.controllers; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
|
||
// import jakarta.ws.rs.core.Response; | ||
|
||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import us.dot.its.jpo.ode.api.models.UploadData; | ||
import us.dot.its.jpo.ode.mockdata.MockUploadDataGenerator; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import us.dot.its.jpo.ode.api.ConflictMonitorApiProperties; | ||
|
||
// import us.dot.its.jpo.ode.coder.StringPublisher; | ||
|
||
@RestController | ||
public class DecoderController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AssessmentController.class); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Autowired | ||
ConflictMonitorApiProperties props; | ||
|
||
|
||
// private StringPublisher bsmPublisher; | ||
|
||
public String getCurrentTime() { | ||
return ZonedDateTime.now().toInstant().toEpochMilli() + ""; | ||
} | ||
|
||
@CrossOrigin(origins = "http://localhost:3000") | ||
@RequestMapping(value = "/decoder/upload", method = RequestMethod.POST, produces = "application/json") | ||
public @ResponseBody ResponseEntity<String> new_bulk_upload_request( | ||
@RequestBody UploadData newUploadData, | ||
@RequestParam(name = "test", required = false, defaultValue = "false") boolean testData) { | ||
try { | ||
logger.info("Uploading Bulk Data"); | ||
|
||
if (testData) { | ||
newUploadData = MockUploadDataGenerator.getUploadData(); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).contentType(MediaType.TEXT_PLAIN) | ||
.body(newUploadData.toString()); | ||
} | ||
|
||
return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON) | ||
.body(newUploadData.toString()); | ||
} catch (Exception e) { | ||
logger.info("Failed to Upload Bulk Data"); | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).contentType(MediaType.TEXT_PLAIN) | ||
.body(ExceptionUtils.getStackTrace(e)); | ||
} | ||
} | ||
|
||
// public void publishBSM(String asn1Bsm){ | ||
// String payloadHexString = HexUtils.toHexString(payload); | ||
// logger.debug("Packet: {}", payloadHexString); | ||
|
||
// // Add header data for the decoding process | ||
// ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC); | ||
// String timestamp = utc.format(DateTimeFormatter.ISO_INSTANT); | ||
|
||
// JSONObject metadataObject = new JSONObject(); | ||
// metadataObject.put("utctimestamp", timestamp); | ||
// metadataObject.put("originRsu", senderIp); | ||
|
||
// JSONObject messageObject = new JSONObject(); | ||
// messageObject.put("metadata", metadataObject); | ||
// messageObject.put("payload", payloadHexString); | ||
|
||
// JSONArray messageList = new JSONArray(); | ||
// messageList.put(messageObject); | ||
|
||
// JSONObject jsonObject = new JSONObject(); | ||
// jsonObject.put("BsmMessageContent", messageList); | ||
|
||
// logger.debug("BSM JSON Object: {}", jsonObject.toString()); | ||
|
||
// // Submit JSON to the OdeRawEncodedMessageJson Kafka Topic | ||
// this.bsmPublisher.publish(jsonObject.toString(), this.bsmPublisher.getOdeProperties().getKafkaTopicOdeRawEncodedBSMJson()); | ||
|
||
// } | ||
} |
24 changes: 24 additions & 0 deletions
24
jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/models/UploadData.java
This file contains 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,24 @@ | ||
package us.dot.its.jpo.ode.api.models; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import lombok.EqualsAndHashCode; | ||
|
||
@ToString | ||
@Setter | ||
@EqualsAndHashCode | ||
@Getter | ||
public class UploadData { | ||
public boolean test; | ||
public List<String> bsmList = new ArrayList<>(); | ||
public List<String> spatList = new ArrayList<>(); | ||
public List<String> mapList = new ArrayList<>(); | ||
public List<String> genericUpload = new ArrayList<>(); | ||
public Long uploadTime; | ||
public String ID; | ||
} |
25 changes: 25 additions & 0 deletions
25
...lictvisualizer-api/src/main/java/us/dot/its/jpo/ode/mockdata/MockUploadDataGenerator.java
This file contains 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,25 @@ | ||
package us.dot.its.jpo.ode.mockdata; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
import us.dot.its.jpo.ode.api.models.UploadData; | ||
|
||
public class MockUploadDataGenerator { | ||
|
||
public static UploadData getUploadData(){ | ||
|
||
|
||
UploadData data = new UploadData(); | ||
|
||
data.bsmList.add("0022e12d18466c65c1493800000e00e4616183e85a8f0100c000038081bc001480b8494c4c950cd8cde6e9651116579f22a424dd78fffff00761e4fd7eb7d07f7fff80005f11d1020214c1c0ffc7c016aff4017a0ff65403b0fd204c20ffccc04f8fe40c420ffe6404cefe60e9a10133408fcfde1438103ab4138f00e1eec1048ec160103e237410445c171104e26bc103dc4154305c2c84103b1c1c8f0a82f42103f34262d1123198103dac25fb12034ce10381c259f12038ca103574251b10e3b2210324c23ad0f23d8efffe0000209340d10000004264bf00"); | ||
data.mapList.add("001283c138003000205e9c014d3eab092ca624b5518202dc3658042800000400023622c60ca009f66d48abfaf81388d8ad18070027d9b2ffcfe9804f13667b1ffd009ec2c76e3ffc82c4e0001004b00c5000000800066c4574101813ecd8b757fae027d9b30e6ff5604ec363561fe7809ec6cd69bfec813c4d8a617fc9027d9b2147008604fb163666000016250000802580228000001000096229e1309b51a6fe4204dd361cf1fe5009f6018e1000096020a00000080004d88a57f84027d9b3827002804ec36087600a009f62c289407282c310001c0440188800000006c46dbe02813ec5816d800710052200000001b11b6fad404fb16054a0000401c8800000006c47b3d24813ec5816d801b100c4200000000af890f12c580007e87100d4200000008af4c0f12c580077e7a2c0004000160002001cb028d000000800052c160bc40b5fffd8a9409d86bfebb5b40141457fef53b76c008b467014145800080002bffcbffc82c6a0001804b024d000000800036c2213c3b013ecd80096d64027d9affd8cdfc04f635ff7983bc09f66c0082aa2014280b1b80006012c0b3400000100004b02bcf0f6d7fe065d602788b0138eb900b1240001012c083400000080009b0c2af0b804fb15fe6de171afff6c63e04ec15fe1de670060e40002581ea8000004000135da6df0180a0a6adc2c00d0143cd51897fda028c8abb25001a0b0680008012c105400000200009aedbefae005053540ee003c0a326a9cf3fed8143c5667780010582c0004009608aa00000080004d76de7ee402829aba88ffdc050f354525fff80a322bcf23fa602c690000c04b0395000000200016bb4fbd4e01414d3215800802940ab108fff2030d2000110126200000001aee5103be050a15f6f1ffc8404d8800000006bb97c18e0142857dfa800010146200000001aee89099a050a15f8720000b05dd000000800046be3743b781428d80e1b00002879b00514b4404f63600827d8c09e22c000400015ffe6007016190000402582ce8000004000135ecee1de80a146c02e54758143cd8059ad3e027b1b00613dd004f102c360000804b055d000000200046bcc7c3c781428d80108c6e02829b002b2ece050a16019a4b29b00ab5c3604f136004e410409ec018a10000960c3a00000080004d7de9878602851b003923cc05053601623b440a0a6bfb8c3a5014140b0640005012c197400000100005afe570ef2050a36003a47c80a0a6bfd2c45f014140b054000501101a8200000001b05a90edc050535ffe605800a0a101b8200000001b08a30ec0050535ffe605300a0a101c8200000005b0c6f0ea4050515ffca0568b0001000e"); | ||
data.spatList.add("001338000817a780000089680500204642b342b34802021a15a955a940181190acd0acd20100868555c555c00104342aae2aae002821a155715570"); | ||
|
||
data.ID = UUID.randomUUID().toString().replace("-", ""); | ||
data.uploadTime = Instant.now().toEpochMilli(); | ||
|
||
return data; | ||
} | ||
|
||
} |