@Test public void testPublishDriverAlertLogFile() throws Exception { byte[] buf = new byte[] { (byte)0x6f, (byte)0x75, (byte)0x4d, (byte)0x19, (byte)0xa4, (byte)0xa1, (byte)0x5c, (byte)0xce, (byte)0x67, (byte)0x06, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x09, (byte)0x27, (byte)0xa9, (byte)0x2c, (byte)0xe2, (byte)0x5a, (byte)0x8f, (byte)0x01, (byte)0x11, (byte)0x00, 'T', 'e', 's', 't', ' ', 'D', 'r', 'i', 'v', 'e', 'r', ' ', 'A', 'l', 'e', 'r', 't' }; String filename = RecordType.driverAlert.name() + GZ; BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); List<OdeData> dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); for (OdeData data : dataList) { assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), DateTimeUtils.nowZDT()) > 0); data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); assertEquals("{\"metadata\":{\"logFileName\":\"driverAlert.gz\",\"recordType\":\"driverAlert\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"NA\"},\"payloadType\":\"us.dot.its.jpo.ode.model.OdeDriverAlertPayload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"alert\":\"Test Driver Alert\"}}", data.toJson()); } }
public List<OdeData> publish(BufferedInputStream bis, String fileName, ImporterFileType fileType) throws LogFileToAsn1CodecPublisherException { XmlUtils xmlUtils = new XmlUtils(); ParserStatus status; List<OdeData> dataList = new ArrayList<>(); if (fileType == ImporterFileType.LEAR_LOG_FILE) { fileParser = LogFileParser.factory(fileName); do { try { status = fileParser.parseFile(bis, fileName); if (status == ParserStatus.COMPLETE) { addDataToList(dataList); } else if (status == ParserStatus.EOF) { publishList(xmlUtils, dataList); } else if (status == ParserStatus.INIT) { logger.error("Failed to parse the header bytes."); } else { logger.error("Failed to decode ASN.1 data"); } } catch (Exception e) { throw new LogFileToAsn1CodecPublisherException("Error parsing or publishing data.", e); } } while (status == ParserStatus.COMPLETE); } return dataList; }
LogFileToAsn1CodecPublisher implements Asn1CodecPublisher { public List<OdeData> publish(BufferedInputStream bis, String fileName, ImporterFileType fileType) throws LogFileToAsn1CodecPublisherException { XmlUtils xmlUtils = new XmlUtils(); ParserStatus status; List<OdeData> dataList = new ArrayList<>(); if (fileType == ImporterFileType.LEAR_LOG_FILE) { fileParser = LogFileParser.factory(fileName); do { try { status = fileParser.parseFile(bis, fileName); if (status == ParserStatus.COMPLETE) { addDataToList(dataList); } else if (status == ParserStatus.EOF) { publishList(xmlUtils, dataList); } else if (status == ParserStatus.INIT) { logger.error("Failed to parse the header bytes."); } else { logger.error("Failed to decode ASN.1 data"); } } catch (Exception e) { throw new LogFileToAsn1CodecPublisherException("Error parsing or publishing data.", e); } } while (status == ParserStatus.COMPLETE); } return dataList; } }
LogFileToAsn1CodecPublisher implements Asn1CodecPublisher { public List<OdeData> publish(BufferedInputStream bis, String fileName, ImporterFileType fileType) throws LogFileToAsn1CodecPublisherException { XmlUtils xmlUtils = new XmlUtils(); ParserStatus status; List<OdeData> dataList = new ArrayList<>(); if (fileType == ImporterFileType.LEAR_LOG_FILE) { fileParser = LogFileParser.factory(fileName); do { try { status = fileParser.parseFile(bis, fileName); if (status == ParserStatus.COMPLETE) { addDataToList(dataList); } else if (status == ParserStatus.EOF) { publishList(xmlUtils, dataList); } else if (status == ParserStatus.INIT) { logger.error("Failed to parse the header bytes."); } else { logger.error("Failed to decode ASN.1 data"); } } catch (Exception e) { throw new LogFileToAsn1CodecPublisherException("Error parsing or publishing data.", e); } } while (status == ParserStatus.COMPLETE); } return dataList; } LogFileToAsn1CodecPublisher(StringPublisher dataPub); }
LogFileToAsn1CodecPublisher implements Asn1CodecPublisher { public List<OdeData> publish(BufferedInputStream bis, String fileName, ImporterFileType fileType) throws LogFileToAsn1CodecPublisherException { XmlUtils xmlUtils = new XmlUtils(); ParserStatus status; List<OdeData> dataList = new ArrayList<>(); if (fileType == ImporterFileType.LEAR_LOG_FILE) { fileParser = LogFileParser.factory(fileName); do { try { status = fileParser.parseFile(bis, fileName); if (status == ParserStatus.COMPLETE) { addDataToList(dataList); } else if (status == ParserStatus.EOF) { publishList(xmlUtils, dataList); } else if (status == ParserStatus.INIT) { logger.error("Failed to parse the header bytes."); } else { logger.error("Failed to decode ASN.1 data"); } } catch (Exception e) { throw new LogFileToAsn1CodecPublisherException("Error parsing or publishing data.", e); } } while (status == ParserStatus.COMPLETE); } return dataList; } LogFileToAsn1CodecPublisher(StringPublisher dataPub); List<OdeData> publish(BufferedInputStream bis, String fileName, ImporterFileType fileType); boolean isDriverAlertRecord(); boolean isBsmRecord(); }
LogFileToAsn1CodecPublisher implements Asn1CodecPublisher { public List<OdeData> publish(BufferedInputStream bis, String fileName, ImporterFileType fileType) throws LogFileToAsn1CodecPublisherException { XmlUtils xmlUtils = new XmlUtils(); ParserStatus status; List<OdeData> dataList = new ArrayList<>(); if (fileType == ImporterFileType.LEAR_LOG_FILE) { fileParser = LogFileParser.factory(fileName); do { try { status = fileParser.parseFile(bis, fileName); if (status == ParserStatus.COMPLETE) { addDataToList(dataList); } else if (status == ParserStatus.EOF) { publishList(xmlUtils, dataList); } else if (status == ParserStatus.INIT) { logger.error("Failed to parse the header bytes."); } else { logger.error("Failed to decode ASN.1 data"); } } catch (Exception e) { throw new LogFileToAsn1CodecPublisherException("Error parsing or publishing data.", e); } } while (status == ParserStatus.COMPLETE); } return dataList; } LogFileToAsn1CodecPublisher(StringPublisher dataPub); List<OdeData> publish(BufferedInputStream bis, String fileName, ImporterFileType fileType); boolean isDriverAlertRecord(); boolean isBsmRecord();  }