Search in sources :

Example 1 with RemoveEntityLibrary

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);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) HashSet(java.util.HashSet) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceCalendarSummary(org.onebusaway.gtfs_transformer.updates.CalendarSimplicationLibrary.ServiceCalendarSummary) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ArrayList(java.util.ArrayList) List(java.util.List) RemoveEntityLibrary(org.onebusaway.gtfs_transformer.impl.RemoveEntityLibrary) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) Route(org.onebusaway.gtfs.model.Route)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 FactoryMap (org.onebusaway.collections.FactoryMap)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Route (org.onebusaway.gtfs.model.Route)1 Trip (org.onebusaway.gtfs.model.Trip)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)1 RemoveEntityLibrary (org.onebusaway.gtfs_transformer.impl.RemoveEntityLibrary)1 ServiceCalendarSummary (org.onebusaway.gtfs_transformer.updates.CalendarSimplicationLibrary.ServiceCalendarSummary)1