Search in sources :

Example 1 with AgencyEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.

the class StopEntriesFactory method processStops.

/**
 * Iterate over each stop, generating a StopEntry for the graph.
 *
 * @param graph
 */
public void processStops(TransitGraphImpl graph) {
    int stopIndex = 0;
    Collection<Stop> stops = _gtfsDao.getAllStops();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(stops.size());
    Map<String, ArrayList<StopEntry>> stopEntriesByAgencyId = new FactoryMap<String, ArrayList<StopEntry>>(new ArrayList<StopEntry>());
    for (Stop stop : stops) {
        if (stopIndex % logInterval == 0)
            _log.info("stops: " + stopIndex + "/" + stops.size());
        stopIndex++;
        StopEntryImpl stopEntry = new StopEntryImpl(stop.getId(), stop.getLat(), stop.getLon());
        stopEntry.setWheelchairBoarding(getWheelchairBoardingAccessibilityForStop(stop));
        graph.putStopEntry(stopEntry);
        stopEntriesByAgencyId.get(stop.getId().getAgencyId()).add(stopEntry);
    }
    for (Map.Entry<String, ArrayList<StopEntry>> entry : stopEntriesByAgencyId.entrySet()) {
        String agencyId = entry.getKey();
        ArrayList<StopEntry> stopEntries = entry.getValue();
        stopEntries.trimToSize();
        AgencyEntryImpl agency = graph.getAgencyForId(agencyId);
        if (agency == null) {
            String msg = null;
            if (stopEntries.size() > 0) {
                msg = "no agency found for agencyId=" + agencyId + " of stop entry " + stopEntries.get(0).getId();
            } else {
                msg = "no agency found for agencyId=" + agencyId + " of empty stop entry list.";
            }
            _log.error(msg);
            throw new IllegalStateException(msg);
        }
        agency.setStops(stopEntries);
    }
    graph.refreshStopMapping();
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Example 2 with AgencyEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.

the class RouteCollectionEntriesFactoryTest method testProcessRouteCollections.

@Test
public void testProcessRouteCollections() {
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId("A");
    graph.putAgencyEntry(agency);
    graph.refreshAgencyMapping();
    RouteEntryImpl routeA = new RouteEntryImpl();
    routeA.setId(new AgencyAndId("A", "routeA"));
    graph.putRouteEntry(routeA);
    RouteEntryImpl routeB = new RouteEntryImpl();
    routeB.setId(new AgencyAndId("A", "routeB"));
    graph.putRouteEntry(routeB);
    RouteCollectionEntriesFactory factory = new RouteCollectionEntriesFactory();
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRouteCollections(graph);
    RouteCollectionEntry routeEntryA = graph.getRouteCollectionForId(routeA.getId());
    assertEquals(routeA.getId(), routeEntryA.getId());
    List<RouteEntry> routes = routeEntryA.getChildren();
    assertEquals(1, routes.size());
    assertTrue(routes.contains(routeA));
    RouteCollectionEntry routeEntryB = graph.getRouteCollectionForId(routeB.getId());
    assertEquals(routeB.getId(), routeEntryB.getId());
    routes = routeEntryB.getChildren();
    assertEquals(1, routes.size());
    assertTrue(routes.contains(routeB));
    List<RouteCollectionEntry> routeCollections = graph.getAllRouteCollections();
    assertEquals(2, routeCollections.size());
    assertTrue(routeCollections.contains(routeEntryA));
    assertTrue(routeCollections.contains(routeEntryB));
    routeCollections = agency.getRouteCollections();
    assertEquals(2, routeCollections.size());
    assertTrue(routeCollections.contains(routeEntryA));
    assertTrue(routeCollections.contains(routeEntryB));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Test(org.junit.Test)

Example 3 with AgencyEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.

the class RouteCollectionEntriesFactoryTest method testGroupRoutesByShortName.

@Test
public void testGroupRoutesByShortName() {
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId("A");
    graph.putAgencyEntry(agency);
    graph.refreshAgencyMapping();
    RouteEntryImpl routeA = new RouteEntryImpl();
    routeA.setId(new AgencyAndId("A", "routeA"));
    graph.putRouteEntry(routeA);
    RouteEntryImpl routeB = new RouteEntryImpl();
    routeB.setId(new AgencyAndId("A", "routeB"));
    graph.putRouteEntry(routeB);
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Route rA = new Route();
    rA.setId(routeA.getId());
    rA.setShortName("10");
    Mockito.when(gtfsDao.getRouteForId(routeA.getId())).thenReturn(rA);
    Route rB = new Route();
    rB.setId(routeB.getId());
    rB.setShortName("10");
    Mockito.when(gtfsDao.getRouteForId(routeB.getId())).thenReturn(rB);
    RouteCollectionEntriesFactory factory = new RouteCollectionEntriesFactory();
    factory.setGroupRoutesByShortName(true);
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRouteCollections(graph);
    AgencyAndId id = new AgencyAndId("A", "10");
    RouteCollectionEntry routeCollectionEntry = graph.getRouteCollectionForId(id);
    assertEquals(id, routeCollectionEntry.getId());
    List<RouteEntry> routes = routeCollectionEntry.getChildren();
    assertEquals(2, routes.size());
    assertTrue(routes.contains(routeA));
    assertTrue(routes.contains(routeB));
    List<RouteCollectionEntry> routeCollections = graph.getAllRouteCollections();
    assertEquals(1, routeCollections.size());
    assertTrue(routeCollections.contains(routeCollectionEntry));
    routeCollections = agency.getRouteCollections();
    assertEquals(1, routeCollections.size());
    assertTrue(routeCollections.contains(routeCollectionEntry));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 4 with AgencyEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.

the class AgencyEntriesFactory method processAgencies.

public void processAgencies(TransitGraphImpl graph) {
    Collection<Agency> agencies = _gtfsDao.getAllAgencies();
    for (Agency agency : agencies) {
        AgencyEntryImpl agencyEntry = new AgencyEntryImpl();
        agencyEntry.setId(_uniqueService.unique(agency.getId()));
        graph.putAgencyEntry(agencyEntry);
    }
    graph.refreshAgencyMapping();
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)

Example 5 with AgencyEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.

the class UnitTestingSupport method agency.

/**
 **
 * Entity Factory Methods
 ***
 */
public static AgencyEntryImpl agency(String id) {
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId(id);
    return agency;
}
Also used : AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)

Aggregations

AgencyEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)7 Test (org.junit.Test)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)3 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)3 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 FactoryMap (org.onebusaway.collections.FactoryMap)2 Stop (org.onebusaway.gtfs.model.Stop)2 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)2 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)2 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)2 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)2 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)2 HashMap (java.util.HashMap)1 Agency (org.onebusaway.gtfs.model.Agency)1 Route (org.onebusaway.gtfs.model.Route)1 StopEntriesFactory (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopEntriesFactory)1