use of org.onebusaway.gtfs_transformer.impl.RemoveEntityLibrary in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
Map<Set<AgencyAndId>, AgencyAndId> serviceIdsToUpdatedServiceId = new HashMap<Set<AgencyAndId>, AgencyAndId>();
Map<AgencyAndId, List<AgencyAndId>> mergeToolIdMapping = computeMergeToolIdMapping(dao);
for (Route route : dao.getAllRoutes()) {
Map<TripKey, List<Trip>> tripsByKey = TripKey.groupTripsForRouteByKey(dao, route);
Map<Set<AgencyAndId>, List<TripKey>> tripKeysByServiceIds = _library.groupTripKeysByServiceIds(tripsByKey);
for (Set<AgencyAndId> serviceIds : tripKeysByServiceIds.keySet()) {
AgencyAndId updatedServiceId = createUpdatedServiceId(serviceIdsToUpdatedServiceId, serviceIds);
for (TripKey tripKey : tripKeysByServiceIds.get(serviceIds)) {
List<Trip> tripsForKey = tripsByKey.get(tripKey);
Trip tripToKeep = tripsForKey.get(0);
tripToKeep.setServiceId(updatedServiceId);
for (int i = 1; i < tripsForKey.size(); i++) {
Trip trip = tripsForKey.get(i);
removeEntityLibrary.removeTrip(dao, trip);
}
if (undoGoogleTransitDataFeedMergeTool) {
AgencyAndId updatedTripId = computeUpdatedTripIdForMergedTripsIfApplicable(mergeToolIdMapping, tripsForKey);
if (updatedTripId != null) {
tripToKeep.setId(updatedTripId);
}
}
}
}
}
CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
List<Object> newEntities = new ArrayList<Object>();
for (Map.Entry<Set<AgencyAndId>, AgencyAndId> entry : serviceIdsToUpdatedServiceId.entrySet()) {
Set<ServiceDate> allServiceDates = getServiceDatesForServiceIds(calendarService, entry.getKey());
ServiceCalendarSummary summary = _library.getSummaryForServiceDates(allServiceDates);
_library.computeSimplifiedCalendar(entry.getValue(), summary, newEntities);
}
saveUpdatedCalendarEntities(dao, newEntities);
}
Aggregations