Search in sources :

Example 11 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class StopsOnRouteForDirectionAction method execute.

@Override
public String execute() {
    if (_routeId == null) {
        return SUCCESS;
    }
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(_routeId);
    // create stop ID->stop bean map
    Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
    for (StopBean stopBean : stopsForRoute.getStops()) {
        stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
    }
    // break up stops into destinations
    List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
    for (StopGroupingBean stopGroupingBean : stopGroupings) {
        for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
            NameBean name = stopGroupBean.getName();
            String type = name.getType();
            if (!type.equals("destination") || !stopGroupBean.getId().equals(_directionId))
                continue;
            if (!stopGroupBean.getStopIds().isEmpty()) {
                for (String stopId : stopGroupBean.getStopIds()) {
                    String agencyId = AgencyAndIdLibrary.convertFromString(_routeId).getAgencyId();
                    if (_transitDataService.stopHasRevenueServiceOnRoute(agencyId, stopId, stopsForRoute.getRoute().getId(), stopGroupBean.getId())) {
                        _stops.add(new StopOnRoute(stopIdToStopBeanMap.get(stopId)));
                    }
                }
            }
        }
    }
    return SUCCESS;
}
Also used : StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute)

Example 12 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class StopsForRouteAction method execute.

@Override
@Actions({ @Action(value = "/where/iphone/stops-for-route") })
public String execute() throws ServiceException {
    if (_id == null || _id.length() == 0)
        return INPUT;
    _route = _transitDataService.getRouteForId(_id);
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(_id);
    Map<String, StopGroupingBean> groupingsByType = MappingLibrary.mapToValue(stopsForRoute.getStopGroupings(), "type", String.class);
    StopGroupingBean byDirection = groupingsByType.get(TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
    if (_groupIndex == -1) {
        if (byDirection != null) {
            for (StopGroupBean group : byDirection.getStopGroups()) _directionNames.add(group.getName());
        }
        _stops = stopsForRoute.getStops();
        Collections.sort(_stops, _stopNameComparator);
    } else {
        if (byDirection == null)
            return INPUT;
        List<StopGroupBean> groups = byDirection.getStopGroups();
        if (_groupIndex < 0 && groups.size() <= _groupIndex)
            return INPUT;
        Map<String, StopBean> stopById = MappingLibrary.mapToValue(stopsForRoute.getStops(), "id", String.class);
        StopGroupBean stopGroup = groups.get(_groupIndex);
        _stops = new ArrayList<StopBean>();
        for (String stopId : stopGroup.getStopIds()) _stops.add(stopById.get(stopId));
    }
    return SUCCESS;
}
Also used : StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopBean(org.onebusaway.transit_data.model.StopBean) Actions(org.apache.struts2.convention.annotation.Actions)

Example 13 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImplTest method runGetStopResult.

// Support methods
private StopResult runGetStopResult(List<ServiceAlertBean> serviceAlerts) {
    StopsForRouteBean stopsForRouteBean = mock(StopsForRouteBean.class);
    List<StopGroupingBean> stopGroupingBeans = new ArrayList<StopGroupingBean>();
    when(stopsForRouteBean.getStopGroupings()).thenReturn(stopGroupingBeans);
    StopGroupingBean stopGroupingBean = mock(StopGroupingBean.class);
    stopGroupingBeans.add(stopGroupingBean);
    List<StopGroupBean> stopGroups = new ArrayList<StopGroupBean>();
    StopGroupBean stopGroupBean = mock(StopGroupBean.class);
    stopGroups.add(stopGroupBean);
    when(stopGroupingBean.getStopGroups()).thenReturn(stopGroups);
    List<String> stopIds = new ArrayList<String>();
    when(stopGroupBean.getStopIds()).thenReturn(stopIds);
    NameBean nameBean = mock(NameBean.class);
    when(nameBean.getType()).thenReturn("destination");
    when(stopGroupBean.getName()).thenReturn(nameBean);
    List<String> stopGroupBeanStopIds = new ArrayList<String>();
    stopGroupBeanStopIds.add(TEST_STOP_ID);
    when(stopGroupBean.getStopIds()).thenReturn(stopGroupBeanStopIds);
    when(stopGroupBean.getId()).thenReturn(TEST_STOP_ID);
    stopIds.add(TEST_STOP_ID);
    List<RouteBean> routeBeans = new ArrayList<RouteBean>();
    routeBeans.add(createRouteBean());
    StopBean stopBean = mock(StopBean.class);
    when(stopBean.getId()).thenReturn(TEST_STOP_ID);
    when(stopBean.getRoutes()).thenReturn(routeBeans);
    List<MonitoredStopVisitStructure> monitoredStopVisits = new ArrayList<MonitoredStopVisitStructure>();
    MonitoredStopVisitStructure monitoredStopVisitStructure = mock(MonitoredStopVisitStructure.class);
    monitoredStopVisits.add(monitoredStopVisitStructure);
    MonitoredVehicleJourneyStructure monVehJourney = mock(MonitoredVehicleJourneyStructure.class);
    when(monitoredStopVisitStructure.getMonitoredVehicleJourney()).thenReturn(monVehJourney);
    when(monitoredStopVisitStructure.getRecordedAtTime()).thenReturn(new Date(TEST_TIME));
    LineRefStructure lineRefStructure = mock(LineRefStructure.class);
    when(monVehJourney.getLineRef()).thenReturn(lineRefStructure);
    when(lineRefStructure.getValue()).thenReturn(ROUTE_ID);
    DirectionRefStructure directionRef = mock(DirectionRefStructure.class);
    when(monVehJourney.getDirectionRef()).thenReturn(directionRef);
    when(directionRef.getValue()).thenReturn(TEST_STOP_ID);
    NaturalLanguageStringStructure natLangStrStructure = mock(NaturalLanguageStringStructure.class);
    when(natLangStrStructure.getValue()).thenReturn(TEST_DESTINATION_NAME);
    when(monVehJourney.getDestinationName()).thenReturn(natLangStrStructure);
    MonitoredCallStructure monCall = mock(MonitoredCallStructure.class);
    ExtensionsStructure extensions = mock(ExtensionsStructure.class);
    SiriExtensionWrapper siriExtensionWrapper = mock(SiriExtensionWrapper.class);
    SiriDistanceExtension distances = mock(SiriDistanceExtension.class);
    when(distances.getPresentableDistance()).thenReturn(TEST_PRESENTABLE_DISTANCE);
    when(siriExtensionWrapper.getDistances()).thenReturn(distances);
    when(extensions.getAny()).thenReturn(siriExtensionWrapper);
    when(monCall.getExtensions()).thenReturn(extensions);
    when(monVehJourney.getMonitoredCall()).thenReturn(monCall);
    when(_realtimeService.getMonitoredStopVisitsForStop(eq(TEST_STOP_ID), eq(0), anyLong())).thenReturn(monitoredStopVisits);
    when(_transitDataService.getStopsForRoute(anyString())).thenReturn(stopsForRouteBean);
    when(_realtimeService.getServiceAlertsForRouteAndDirection(ROUTE_ID, TEST_STOP_ID)).thenReturn(serviceAlerts);
    SearchResultFactoryImpl srf = new SearchResultFactoryImpl(_transitDataService, _realtimeService, _configurationService);
    Set<RouteBean> routeFilter = new HashSet<RouteBean>();
    StopResult result = (StopResult) srf.getStopResult(stopBean, routeFilter);
    return result;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri.NaturalLanguageStringStructure) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matchers.anyString(org.mockito.Matchers.anyString) ExtensionsStructure(uk.org.siri.siri.ExtensionsStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) SiriDistanceExtension(org.onebusaway.transit_data_federation.siri.SiriDistanceExtension) MonitoredCallStructure(uk.org.siri.siri.MonitoredCallStructure) HashSet(java.util.HashSet) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) LineRefStructure(uk.org.siri.siri.LineRefStructure) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) Date(java.util.Date) MonitoredVehicleJourneyStructure(uk.org.siri.siri.MonitoredVehicleJourneyStructure) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) DirectionRefStructure(uk.org.siri.siri.DirectionRefStructure) StopResult(org.onebusaway.enterprise.webapp.actions.m.model.StopResult)

Example 14 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class BeanFactoryV2 method getStopsForRoute.

public StopsForRouteV2Bean getStopsForRoute(StopsForRouteBean stopsForRoute, boolean includePolylines) {
    StopsForRouteV2Bean bean = new StopsForRouteV2Bean();
    RouteBean route = stopsForRoute.getRoute();
    if (route != null) {
        addToReferences(route);
        bean.setRouteId(route.getId());
    }
    List<String> stopIds = new ArrayList<String>();
    for (StopBean stop : stopsForRoute.getStops()) {
        stopIds.add(stop.getId());
        addToReferences(stop);
    }
    bean.setStopIds(stopIds);
    bean.setStopGroupings(stopsForRoute.getStopGroupings());
    if (!includePolylines) {
        for (StopGroupingBean grouping : stopsForRoute.getStopGroupings()) {
            for (StopGroupBean group : grouping.getStopGroups()) group.setPolylines(null);
        }
    }
    if (includePolylines)
        bean.setPolylines(stopsForRoute.getPolylines());
    return bean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 15 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean 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)

Aggregations

StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)26 ArrayList (java.util.ArrayList)21 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)21 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)21 NameBean (org.onebusaway.transit_data.model.NameBean)16 StopBean (org.onebusaway.transit_data.model.StopBean)15 RouteBean (org.onebusaway.transit_data.model.RouteBean)13 HashMap (java.util.HashMap)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)8 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)7 HashSet (java.util.HashSet)5 List (java.util.List)5 Matchers.anyString (org.mockito.Matchers.anyString)3 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)3 AnnotatedStopPointStructure (uk.org.siri.siri_2.AnnotatedStopPointStructure)3 Map (java.util.Map)2 Before (org.junit.Before)2 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)2