@Test public void save() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); CsvEventRepository sut = new CsvEventRepository(out, false); Event event = SuddenSpeedChangeEventBuilder.SuddenSpeedChangeEvent() .title("title") .description("description") .state(Event.State.PAST) .startTime(LocalDateTime.of(2017, 1, 22, 10, 0, 0)) .endTime(LocalDateTime.of(2017, 1, 22, 12, 32, 1)) .endTime(null) .behaviour() .isPrimary(true) .vessel() .mmsi(123456789) .imo(123456) .callsign("callsign") .type(1) .toBow(10) .toStern(20) .toPort(30) .toStarboard(40) .name("name") .trackingPoint() .timestamp(LocalDateTime.of(2017, 1, 22, 10, 0, 0)) .positionInterpolated(false) .eventCertainty(TrackingPoint.EventCertainty.RAISED) .speedOverGround(12.0f) .courseOverGround(45f) .trueHeading(46f) .latitude(56.0) .longitude(12.0) .getEvent(); sut.save(event); assertEquals( "eventId,eventType,startTime,endTime,title,description,mmsis,pMmsi,pName,pCallsign,pType,pLength,pLat,pLon,pSog,pCog,pHdg,sMmsi,sName,sCallsign,sType,sLength,sLat,sLon,sSog,sCog,sHdg,filterSuggest\r\n" + "0,SuddenSpeedChangeEvent,2017-01-22T10:00,,title,description,[123456789],123456789,name,callsign,1,30,56.0000,12.0000,12.0,45,46,,,,,,,,,,,\"-start \"\"2017-01-22-09:50\"\" -end \"\"2017-01-22-10:20\"\" -exp \"\"m.pos within circle(56.0000,12.0000,1000)\"\"\"\r\n", out.toString() ); }
@Override public void save(Event event) { if (readonly == false) { if (event.getState() == Event.State.ONGOING) insertOngoingEvent(event); else removeOngoingEvent(event); if (event.getState() == Event.State.PAST) { try { Behaviour primaryBehaviour = event.primaryBehaviour(); Behaviour secondaryBehaviour = event.arbitraryNonPrimaryBehaviour(); TrackingPoint primaryLastTrackingPoint = primaryBehaviour.getTrackingPoints().last(); TrackingPoint secondaryLastTrackingPoint = secondaryBehaviour == null ? null : secondaryBehaviour.getTrackingPoints().last(); printer.printRecord( event.getId(), event.getEventType(), event.getStartTime(), event.getEndTime(), event.getTitle(), event.getDescription(), event.involvedMmsis(), primaryBehaviour.getVessel().getMmsi(), primaryBehaviour.getVessel().getName(), primaryBehaviour.getVessel().getCallsign(), primaryBehaviour.getVessel().getType(), primaryBehaviour.getVessel().getLength(), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLatitude()), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLongitude()), String.format(Locale.ENGLISH, "%.1f", primaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getMmsi(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getName(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getCallsign(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getType(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getLength(), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLatitude()), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLongitude()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.1f", secondaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), filterSuggestion(event) ); printer.flush(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } }
CsvEventRepository implements EventRepository { @Override public void save(Event event) { if (readonly == false) { if (event.getState() == Event.State.ONGOING) insertOngoingEvent(event); else removeOngoingEvent(event); if (event.getState() == Event.State.PAST) { try { Behaviour primaryBehaviour = event.primaryBehaviour(); Behaviour secondaryBehaviour = event.arbitraryNonPrimaryBehaviour(); TrackingPoint primaryLastTrackingPoint = primaryBehaviour.getTrackingPoints().last(); TrackingPoint secondaryLastTrackingPoint = secondaryBehaviour == null ? null : secondaryBehaviour.getTrackingPoints().last(); printer.printRecord( event.getId(), event.getEventType(), event.getStartTime(), event.getEndTime(), event.getTitle(), event.getDescription(), event.involvedMmsis(), primaryBehaviour.getVessel().getMmsi(), primaryBehaviour.getVessel().getName(), primaryBehaviour.getVessel().getCallsign(), primaryBehaviour.getVessel().getType(), primaryBehaviour.getVessel().getLength(), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLatitude()), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLongitude()), String.format(Locale.ENGLISH, "%.1f", primaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getMmsi(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getName(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getCallsign(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getType(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getLength(), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLatitude()), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLongitude()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.1f", secondaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), filterSuggestion(event) ); printer.flush(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } } }
CsvEventRepository implements EventRepository { @Override public void save(Event event) { if (readonly == false) { if (event.getState() == Event.State.ONGOING) insertOngoingEvent(event); else removeOngoingEvent(event); if (event.getState() == Event.State.PAST) { try { Behaviour primaryBehaviour = event.primaryBehaviour(); Behaviour secondaryBehaviour = event.arbitraryNonPrimaryBehaviour(); TrackingPoint primaryLastTrackingPoint = primaryBehaviour.getTrackingPoints().last(); TrackingPoint secondaryLastTrackingPoint = secondaryBehaviour == null ? null : secondaryBehaviour.getTrackingPoints().last(); printer.printRecord( event.getId(), event.getEventType(), event.getStartTime(), event.getEndTime(), event.getTitle(), event.getDescription(), event.involvedMmsis(), primaryBehaviour.getVessel().getMmsi(), primaryBehaviour.getVessel().getName(), primaryBehaviour.getVessel().getCallsign(), primaryBehaviour.getVessel().getType(), primaryBehaviour.getVessel().getLength(), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLatitude()), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLongitude()), String.format(Locale.ENGLISH, "%.1f", primaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getMmsi(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getName(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getCallsign(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getType(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getLength(), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLatitude()), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLongitude()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.1f", secondaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), filterSuggestion(event) ); printer.flush(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } } @Inject  CsvEventRepository(OutputStream out, boolean readonly); }
CsvEventRepository implements EventRepository { @Override public void save(Event event) { if (readonly == false) { if (event.getState() == Event.State.ONGOING) insertOngoingEvent(event); else removeOngoingEvent(event); if (event.getState() == Event.State.PAST) { try { Behaviour primaryBehaviour = event.primaryBehaviour(); Behaviour secondaryBehaviour = event.arbitraryNonPrimaryBehaviour(); TrackingPoint primaryLastTrackingPoint = primaryBehaviour.getTrackingPoints().last(); TrackingPoint secondaryLastTrackingPoint = secondaryBehaviour == null ? null : secondaryBehaviour.getTrackingPoints().last(); printer.printRecord( event.getId(), event.getEventType(), event.getStartTime(), event.getEndTime(), event.getTitle(), event.getDescription(), event.involvedMmsis(), primaryBehaviour.getVessel().getMmsi(), primaryBehaviour.getVessel().getName(), primaryBehaviour.getVessel().getCallsign(), primaryBehaviour.getVessel().getType(), primaryBehaviour.getVessel().getLength(), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLatitude()), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLongitude()), String.format(Locale.ENGLISH, "%.1f", primaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getMmsi(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getName(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getCallsign(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getType(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getLength(), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLatitude()), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLongitude()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.1f", secondaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), filterSuggestion(event) ); printer.flush(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } } @Inject  CsvEventRepository(OutputStream out, boolean readonly); @Override List<String> getEventTypes(); @Override void save(Event event); @Override Event getEvent(long eventId); @Override List<Event> findEventsByFromAndToAndTypeAndVesselAndArea(Date from, Date to, String type, String vessel, Double north, Double east, Double south, Double west); @Override List<Event> findEventsByFromAndTo(Date from, Date to); @Override List<Event> findRecentEvents(int numberOfEvents); @Override T findOngoingEventByVessel(int mmsi, Class<T> eventClass); }
CsvEventRepository implements EventRepository { @Override public void save(Event event) { if (readonly == false) { if (event.getState() == Event.State.ONGOING) insertOngoingEvent(event); else removeOngoingEvent(event); if (event.getState() == Event.State.PAST) { try { Behaviour primaryBehaviour = event.primaryBehaviour(); Behaviour secondaryBehaviour = event.arbitraryNonPrimaryBehaviour(); TrackingPoint primaryLastTrackingPoint = primaryBehaviour.getTrackingPoints().last(); TrackingPoint secondaryLastTrackingPoint = secondaryBehaviour == null ? null : secondaryBehaviour.getTrackingPoints().last(); printer.printRecord( event.getId(), event.getEventType(), event.getStartTime(), event.getEndTime(), event.getTitle(), event.getDescription(), event.involvedMmsis(), primaryBehaviour.getVessel().getMmsi(), primaryBehaviour.getVessel().getName(), primaryBehaviour.getVessel().getCallsign(), primaryBehaviour.getVessel().getType(), primaryBehaviour.getVessel().getLength(), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLatitude()), String.format(Locale.ENGLISH, "%.4f", primaryLastTrackingPoint.getLongitude()), String.format(Locale.ENGLISH, "%.1f", primaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), String.format(Locale.ENGLISH, "%.0f", primaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getMmsi(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getName(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getCallsign(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getType(), secondaryBehaviour == null ? null : secondaryBehaviour.getVessel().getLength(), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLatitude()), secondaryLastTrackingPoint == null ? null : String.format(Locale.ENGLISH, "%.4f", secondaryLastTrackingPoint.getLongitude()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.1f", secondaryBehaviour.mostRecentTrackingPoint().getSpeedOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getCourseOverGround()), secondaryBehaviour == null ? null : String.format(Locale.ENGLISH, "%.0f", secondaryBehaviour.mostRecentTrackingPoint().getTrueHeading()), filterSuggestion(event) ); printer.flush(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } } @Inject  CsvEventRepository(OutputStream out, boolean readonly); @Override List<String> getEventTypes(); @Override void save(Event event); @Override Event getEvent(long eventId); @Override List<Event> findEventsByFromAndToAndTypeAndVesselAndArea(Date from, Date to, String type, String vessel, Double north, Double east, Double south, Double west); @Override List<Event> findEventsByFromAndTo(Date from, Date to); @Override List<Event> findRecentEvents(int numberOfEvents); @Override T findOngoingEventByVessel(int mmsi, Class<T> eventClass);  }