Search in sources :

Example 1 with AgencyEntry

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

the class RoutesBeanServiceImpl method getRoutesForAgencyId.

@Cacheable
@Override
public ListBean<RouteBean> getRoutesForAgencyId(String agencyId) {
    AgencyEntry agency = _graphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<RouteBean> routes = new ArrayList<RouteBean>();
    for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
        AgencyAndId routeId = routeCollection.getId();
        RouteBean route = _routeBeanService.getRouteForId(routeId);
        routes.add(route);
    }
    return new ListBean<RouteBean>(routes, false);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 2 with AgencyEntry

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

the class GtfsController method getRoutesByAgency.

// Get list of routes by agency
@RequestMapping(value = "/routes/{agencyId}")
@ResponseBody
public List<String> getRoutesByAgency(@PathVariable String agencyId) {
    AgencyEntry agency = _transitGraphDao.getAgencyForId(agencyId);
    List<RouteCollectionEntry> collections = agency.getRouteCollections();
    List<String> routes = new ArrayList<String>();
    for (RouteCollectionEntry entry : collections) {
        for (RouteEntry route : entry.getChildren()) {
            String id = route.getId().getId();
            routes.add(id);
        }
    }
    return routes;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) ArrayList(java.util.ArrayList) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with AgencyEntry

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

the class GtfsRealtimeArchiverTask method init.

protected void init() {
    while (!initialized) {
        _log.info("Still waiting for context initialization");
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException ex) {
        // don't handle exception
        }
    }
    if (_agencyIds.isEmpty()) {
        _log.info("no agency ids specified for GtfsRealtimeSource");
        for (AgencyEntry agency : _transitGraphDao.getAllAgencies()) {
            _agencyIds.add(agency.getId());
        }
        if (_agencyIds.size() > 3) {
            _log.warn("The default agency id set is quite large (n=" + _agencyIds.size() + ").  You might consider specifying the applicable agencies for your GtfsRealtimeSource.");
        }
    }
    _log.info("Number of agencies: " + _agencyIds.size());
    for (String agency : _agencyIds) {
        _log.info("Agency id: " + agency);
    }
    _entitySource = new GtfsRealtimeEntitySource();
    _entitySource.setAgencyIds(_agencyIds);
    _entitySource.setTransitGraphDao(_transitGraphDao);
    if (_tripUpdatesUrl == null) {
        _log.warn("no tripUpdatesUrl configured.  This is most likely a configuration issue");
    }
    if (_vehiclePositionsUrl == null) {
        _log.warn("no vehiclePositionsUrl configured.  This is most likely a configuration issue");
    }
    if (_alertsUrl == null) {
        _log.warn("no alertsUrl configured.  This is most likely a configuration issue");
    }
    if (_refreshInterval > 0) {
        _log.info("scheduling executor for refresh=" + _refreshInterval);
        _refreshTask = _scheduledExecutorService.scheduleAtFixedRate(new UpdateTask(), 0, _refreshInterval, TimeUnit.SECONDS);
    }
}
Also used : AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)

Example 4 with AgencyEntry

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

the class AgencyServiceImpl method getAgencyIdsAndCoverageAreas.

@Cacheable
public Map<String, CoordinateBounds> getAgencyIdsAndCoverageAreas() {
    Map<String, CoordinateBounds> boundsByAgencyId = new HashMap<String, CoordinateBounds>();
    for (AgencyEntry agency : _graph.getAllAgencies()) {
        CoordinateBounds bounds = new CoordinateBounds();
        for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
            for (RouteEntry route : routeCollection.getChildren()) {
                for (TripEntry trip : route.getTrips()) {
                    for (StopTimeEntry stopTime : trip.getStopTimes()) {
                        StopEntry stop = stopTime.getStop();
                        bounds.addPoint(stop.getStopLat(), stop.getStopLon());
                    }
                }
            }
        }
        boundsByAgencyId.put(agency.getId(), bounds);
    }
    return boundsByAgencyId;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) HashMap(java.util.HashMap) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 5 with AgencyEntry

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

the class AgencyEntriesFactoryTest method testProcessAgencies.

@Test
public void testProcessAgencies() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agencyA = new Agency();
    agencyA.setId("A");
    Agency agencyB = new Agency();
    agencyB.setId("B");
    Mockito.when(gtfsDao.getAllAgencies()).thenReturn(Arrays.asList(agencyA, agencyB));
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntriesFactory factory = new AgencyEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processAgencies(graph);
    AgencyEntry agencyEntryA = graph.getAgencyForId("A");
    assertEquals("A", agencyEntryA.getId());
    AgencyEntry agencyEntryB = graph.getAgencyForId("B");
    assertEquals("B", agencyEntryB.getId());
    List<AgencyEntry> agencies = graph.getAllAgencies();
    assertEquals(2, agencies.size());
    assertTrue(agencies.contains(agencyEntryA));
    assertTrue(agencies.contains(agencyEntryB));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Agency(org.onebusaway.gtfs.model.Agency) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Test(org.junit.Test)

Aggregations

AgencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)8 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)5 ArrayList (java.util.ArrayList)4 Cacheable (org.onebusaway.container.cache.Cacheable)4 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 ListBean (org.onebusaway.transit_data.model.ListBean)3 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)3 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)3 HashMap (java.util.HashMap)2 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 Test (org.junit.Test)1 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 Agency (org.onebusaway.gtfs.model.Agency)1 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)1 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)1