Search in sources :

Example 16 with NameBean

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

the class StopsForRouteNavigationTemplate method buildTemplate.

@Override
public void buildTemplate(ActionContext context) {
    ValueStack vs = context.getValueStack();
    NavigationBean navigation = (NavigationBean) vs.findValue("navigation");
    List<NameBean> names = navigation.getNames();
    int index = navigation.getCurrentIndex();
    if (index < 0)
        index = 0;
    /**
     * We always listen for the key-press for the previous name in case it takes
     * the user a second to press
     */
    if (index > 0)
        addNavigationSelectionActionForIndex(navigation, index - 1);
    /**
     * If we're at the first entry and there is a second, we allow the user to
     * jump ahead
     */
    if (index == 0 && names.size() > 1) {
        addNavigationSelectionActionForIndex(navigation, index + 1);
    }
    if (index >= names.size()) {
        AgiActionName action = setNextAction("/search/navigate-to");
        action.putParam("navigation", navigation);
        action.putParam("index", 0);
        action.setExcludeFromHistory(true);
        // Add an extra pause so the user has a chance to make a selection from
        // the previous entry
        addPause(1000);
        addMessage(Messages.TO_REPEAT);
    } else {
        String key = addNavigationSelectionActionForIndex(navigation, index);
        NameBean name = names.get(index);
        handleName(name, key);
        addNavigateToAction(navigation, "4", first(index - 1));
        addNavigateToAction(navigation, "6", index + 1);
        addNavigateToAction(navigation, "7", first(index - 10));
        addNavigateToAction(navigation, "9", index + 10);
        AgiActionName action = setNextAction("/search/navigate-to");
        action.putParam("navigation", navigation);
        action.putParam("index", index + 1);
        action.setExcludeFromHistory(true);
    }
    addAction("\\*", "/back");
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) NavigationBean(org.onebusaway.phone.actions.search.NavigationBean) NameBean(org.onebusaway.transit_data.model.NameBean) AgiActionName(org.onebusaway.probablecalls.AgiActionName)

Example 17 with NameBean

use of org.onebusaway.transit_data.model.NameBean 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 18 with NameBean

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

the class SearchResultFactoryImpl method getStopResult.

@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
    List<RouteAtStop> routesAtStop = new ArrayList<RouteAtStop>();
    for (RouteBean routeBean : stopBean.getRoutes()) {
        StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
        List<RouteDirection> directions = new ArrayList<RouteDirection>();
        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"))
                    continue;
                List<String> polylines = new ArrayList<String>();
                for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
                    polylines.add(polyline.getPoints());
                }
                Boolean hasUpcomingScheduledService = null;
                // We do this to prevent checking if there is service in a direction that does not even serve this stop.
                if (stopGroupBean.getStopIds().contains(stopBean.getId())) {
                    hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
                    // if there are buses on route, always have "scheduled service"
                    Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForStopAndRoute(stopBean.getId(), routeBean.getId(), SystemTime.currentTimeMillis());
                    if (routeHasVehiclesInService) {
                        hasUpcomingScheduledService = true;
                    }
                }
                directions.add(new RouteDirection(stopGroupBean, polylines, null, hasUpcomingScheduledService));
            }
        }
        RouteAtStop routeAtStop = new RouteAtStop(routeBean, directions);
        routesAtStop.add(routeAtStop);
    }
    return new StopResult(stopBean, routesAtStop);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteAtStop(org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) StopResult(org.onebusaway.enterprise.webapp.actions.api.model.StopResult)

Example 19 with NameBean

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

the class SearchResultFactoryImpl method getRouteResultForRegion.

@Override
public SearchResult getRouteResultForRegion(RouteBean routeBean) {
    List<String> polylines = new ArrayList<String>();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
    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"))
                continue;
            for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
                polylines.add(polyline.getPoints());
            }
        }
    }
    return new RouteInRegionResult(routeBean, polylines);
}
Also used : RouteInRegionResult(org.onebusaway.enterprise.webapp.actions.api.model.RouteInRegionResult) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean)

Example 20 with NameBean

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

the class StopForIdAction method execute.

@Override
public String execute() {
    if (_stopId == null) {
        return SUCCESS;
    }
    StopBean stop = _transitDataService.getStop(_stopId);
    if (stop == null) {
        return SUCCESS;
    }
    List<RouteAtStop> routesAtStop = new ArrayList<RouteAtStop>();
    for (RouteBean routeBean : stop.getRoutes()) {
        StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
        List<RouteDirection> routeDirections = new ArrayList<RouteDirection>();
        List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
        for (StopGroupingBean stopGroupingBean : stopGroupings) {
            for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                if (_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), _stopId, routeBean.getId(), stopGroupBean.getId())) {
                    NameBean name = stopGroupBean.getName();
                    String type = name.getType();
                    if (!type.equals("destination"))
                        continue;
                    // filter out route directions that don't stop at this stop
                    if (!stopGroupBean.getStopIds().contains(_stopId))
                        continue;
                    Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stop.getId(), routeBean.getId(), stopGroupBean.getId());
                    // if there are buses on route, always have "scheduled service"
                    Boolean routeHasVehiclesInService = true;
                    if (routeHasVehiclesInService) {
                        hasUpcomingScheduledService = true;
                    }
                    routeDirections.add(new RouteDirection(stopGroupBean, null, null, hasUpcomingScheduledService));
                }
            }
        }
        RouteAtStop routeAtStop = new RouteAtStop(routeBean, routeDirections);
        routesAtStop.add(routeAtStop);
    }
    _result = new StopResult(stop, routesAtStop);
    List<MonitoredStopVisitStructure> visits = _realtimeService.getMonitoredStopVisitsForStop(_stopId, 0, SystemTime.currentTimeMillis());
    _response = generateSiriResponse(visits, AgencyAndIdLibrary.convertFromString(_stopId));
    return SUCCESS;
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteAtStop(org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) StopResult(org.onebusaway.enterprise.webapp.actions.api.model.StopResult)

Aggregations

NameBean (org.onebusaway.transit_data.model.NameBean)25 ArrayList (java.util.ArrayList)16 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)16 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)14 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)14 StopBean (org.onebusaway.transit_data.model.StopBean)10 RouteBean (org.onebusaway.transit_data.model.RouteBean)7 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)4 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 StopSelectionBean (org.onebusaway.presentation.model.StopSelectionBean)3 ValueStack (com.opensymphony.xwork2.util.ValueStack)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)2 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)2