Search in sources :

Example 16 with RouteEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry in project onebusaway-application-modules by camsys.

the class GtfsRealtimeEntitySource method getRouteId.

/**
 * Given a route id without an agency prefix, we attempt to find a
 * {@link RouteEntry} with the specified id by cycling through the set of
 * agency ids specified in {@link #setAgencyIds(List)}. If a
 * {@link RouteEntry} is found, we return the id of the parent
 * {@link RouteCollectionEntry} as the matching id. This is to deal with the
 * fact that while GTFS deals with underlying routes, internally OneBusAway
 * mostly deals with RouteCollections.
 *
 * If no route is found in the {@link TransitGraphDao} with the specified id
 * for any of the configured agencies, a {@link Id} will be constructed with
 * the first agency id from the agency list.
 *
 * @param routeId
 * @return an Id for {@link RouteCollectionEntry} with a matching
 *         {@link RouteEntry} id
 */
public Id getRouteId(String routeId) {
    for (String agencyId : _agencyIds) {
        AgencyAndId id = new AgencyAndId(agencyId, routeId);
        RouteEntry route = _transitGraphDao.getRouteForId(id);
        if (route != null)
            return ServiceAlertLibrary.id(route.getParent().getId());
    }
    try {
        AgencyAndId id = AgencyAndId.convertFromString(routeId);
        RouteEntry route = _transitGraphDao.getRouteForId(id);
        if (route != null)
            return ServiceAlertLibrary.id(route.getParent().getId());
    } catch (IllegalArgumentException ex) {
    }
    _log.warn("route not found with id \"{}\"", routeId);
    AgencyAndId id = new AgencyAndId(_agencyIds.get(0), routeId);
    return ServiceAlertLibrary.id(id);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId)

Aggregations

RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)16 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)10 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)7 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)7 ArrayList (java.util.ArrayList)6 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)6 Test (org.junit.Test)4 Route (org.onebusaway.gtfs.model.Route)4 RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)4 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)4 HashMap (java.util.HashMap)3 Cacheable (org.onebusaway.container.cache.Cacheable)3 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)3 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)3 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)3 AgencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)3 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 HashSet (java.util.HashSet)2