Search in sources :

Example 1 with RouteEntry

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

the class RouteBeanServiceImplTest method testGetStopsForRoute.

@Test
public void testGetStopsForRoute() {
    AgencyAndId routeId = new AgencyAndId("1", "route");
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("1", "raw_route"));
    List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(routeId);
    routeCollection.setChildren(routes);
    route.setParent(routeCollection);
    Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
    RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
    Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
    StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sidA");
    TripEntryImpl tripB = trip("tripB", "sidA");
    tripA.setRoute(route);
    tripA.setDirectionId("0");
    tripB.setRoute(route);
    tripB.setDirectionId("1");
    route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
    TripNarrative.Builder tnA = TripNarrative.builder();
    tnA.setTripHeadsign("Destination A");
    Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
    TripNarrative.Builder tnB = TripNarrative.builder();
    tnB.setTripHeadsign("Destination B");
    Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
    stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
    stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
    stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
    stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
    stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
    linkBlockTrips(blockA, tripA, tripB);
    List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
    Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
    StopBean stopBeanA = getStopBean(stopA);
    StopBean stopBeanB = getStopBean(stopB);
    StopBean stopBeanC = getStopBean(stopC);
    List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
    Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
    Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
    shapeIds.add(shapeId);
    tripA.setShapeId(shapeId);
    EncodedPolylineBean polyline = new EncodedPolylineBean();
    Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
    // Setup complete
    StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
    List<StopBean> stops = stopsForRoute.getStops();
    assertEquals(3, stops.size());
    assertSame(stopBeanA, stops.get(0));
    assertSame(stopBeanB, stops.get(1));
    assertSame(stopBeanC, stops.get(2));
    List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
    assertEquals(1, polylines.size());
    assertSame(polyline, polylines.get(0));
    List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
    assertEquals(1, groupings.size());
    StopGroupingBean grouping = groupings.get(0);
    assertEquals("direction", grouping.getType());
    List<StopGroupBean> groups = grouping.getStopGroups();
    assertEquals(2, groups.size());
    StopGroupBean groupA = groups.get(0);
    StopGroupBean groupB = groups.get(1);
    NameBean nameA = groupA.getName();
    assertEquals("destination", nameA.getType());
    assertEquals("Destination A", nameA.getName());
    List<String> stopIdsA = groupA.getStopIds();
    assertEquals(3, stopIdsA.size());
    assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
    NameBean nameB = groupB.getName();
    assertEquals("destination", nameB.getType());
    assertEquals("Destination B", nameB.getName());
    List<String> stopIdsB = groupB.getStopIds();
    assertEquals(2, stopIdsB.size());
    assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) HashSet(java.util.HashSet) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) NameBean(org.onebusaway.transit_data.model.NameBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Test(org.junit.Test)

Example 2 with RouteEntry

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

the class UnitTestingSupport method routeCollection.

public static RouteCollectionEntryImpl routeCollection(String id, RouteEntry... routes) {
    RouteCollectionEntryImpl route = new RouteCollectionEntryImpl();
    route.setId(aid(id));
    route.setChildren(Arrays.asList(routes));
    for (RouteEntry routeEntry : routes) {
        ((RouteEntryImpl) routeEntry).setParent(route);
    }
    return route;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)

Example 3 with RouteEntry

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

the class GtfsController method getRoute.

/* Expose shape points for route */
@RequestMapping(value = "/route/{agencyId}/{id}")
@ResponseBody
public ShapePoints getRoute(@PathVariable String agencyId, @PathVariable String id) {
    AgencyAndId routeId = new AgencyAndId(agencyId, id);
    RouteEntry route = _transitGraphDao.getRouteForId(routeId);
    // BAD - just uses first trip.
    TripEntry trip = routeToTrip(route);
    AgencyAndId shapeId = trip.getShapeId();
    return _shapePointService.getShapePointsForShapeId(shapeId);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RouteEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry 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 5 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.

/**
 * This class was copied from org/onebusaway/transit_data_federation/impl
 * /realtime/gtfs_realtime/GtfsRealtimeEntitySource.java. It was modified
 * slightly, primarily the return values changed to AgencyAndId ids. The
 * documentation is from the original class.
 */
/**
 * 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 AgencyAndId getRouteId(String routeId) {
    for (String agencyId : _agencyIds) {
        AgencyAndId id = new AgencyAndId(agencyId, routeId);
        RouteEntry route = _transitGraphDao.getRouteForId(id);
        if (route != null)
            return id;
    }
    try {
        AgencyAndId id = AgencyAndId.convertFromString(routeId);
        RouteEntry route = _transitGraphDao.getRouteForId(id);
        if (route != null)
            return id;
    } catch (IllegalArgumentException ex) {
    }
    _log.debug("route not found with id \"{}\"", routeId);
    // If not found, just return null.
    return null;
}
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