@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
HashMap<String, Trip> tripsUpdated = new HashMap<>();
ArrayList<Trip> tripsToRemove = new ArrayList<>();
_log.info("Total dao {}", dao.getAllTrips().size());
_log.info("Stop times: {}" , dao.getAllStopTimes().size());
for (Trip trip : dao.getAllTrips()) {
if (trip.getMtaTripId() != null) {
if (tripsUpdated.containsKey(trip.getMtaTripId())) {
tripsToRemove.add(trip);
for (StopTime stopTime : dao.getStopTimesForTrip(trip)){
stopTime.setTrip(tripsUpdated.get(trip.getMtaTripId()));
}
} else {
tripsUpdated.put(trip.getMtaTripId(), trip);
trip.setId(new AgencyAndId(trip.getId().getAgencyId(), trip.getMtaTripId()));
}
}
}
for (Trip tripToRemove : tripsToRemove) {
dao.removeEntity(tripToRemove);
}
_log.info("Total dao {}", dao.getAllTrips().size());
_log.info("Stop times: {}" , dao.getAllStopTimes().size());
}