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);
}
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;
}
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);
}
}
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;
}
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));
}
Aggregations