Search in sources :

Example 16 with StopBean

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

the class MultipleStopsFoundAction method displayData.

private String displayData() {
    List<StopBean> stops = (List<StopBean>) sessionMap.get("stops");
    int index = 1;
    addMessage(Messages.MULTIPLE_STOPS_WERE_FOUND);
    for (StopBean stop : stops) {
        addMessage(Messages.FOR);
        String destination = _destinationPronunciation.modify(stop.getName());
        destination = destination.replaceAll("\\&", "and");
        addText(destination);
        addText(", ");
        addMessage(Messages.PLEASE_PRESS);
        String key = Integer.toString(index++);
        addText(key);
        addText(". ");
    }
    addMessage(Messages.TO_REPEAT);
    sessionMap.put("stops", stops);
    sessionMap.put("navState", new Integer(DO_ROUTING));
    return SUCCESS;
}
Also used : StopBean(org.onebusaway.transit_data.model.StopBean) List(java.util.List)

Example 17 with StopBean

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

the class StopForCodeAction method execute.

public String execute() throws Exception {
    _log.info("in stop for code");
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null)
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    if (_stopCode == null || _stopCode.length() == 0)
        return INPUT;
    if (_stop != null) {
        _stops = Arrays.asList(_stop);
    } else {
        _log.info("searching on stopCode=" + _stopCode);
        SearchQueryBean searchQuery = new SearchQueryBean();
        searchQuery.setBounds(bounds);
        searchQuery.setMaxCount(5);
        searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
        searchQuery.setQuery(_stopCode);
        StopsBean stopsBean = _transitDataService.getStops(searchQuery);
        _stops = stopsBean.getStops();
    }
    logUserInteraction("query", _stopCode);
    if (_stops.size() == 0) {
        sessionMap.put("messageFromAction", getText(Messages.NO_STOPS_WERE_FOUND));
        sessionMap.put("backAction", "stops-index");
        return "noStopsFound";
    } else if (_stops.size() == 1) {
        StopBean stop = _stops.get(0);
        _stopIds = Arrays.asList(stop.getId());
        return SUCCESS;
    } else {
        sessionMap.put("stops", _stops);
        return "multipleStopsFound";
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 18 with StopBean

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

the class StopFoundAction method execute.

@Override
public String execute() throws Exception {
    Integer navState = (Integer) sessionMap.get("navState");
    if (navState == null) {
        navState = DISPLAY_DATA;
    }
    _log.debug("StopsForRouteNavigationAction:navState: " + navState);
    if (navState == DISPLAY_DATA) {
        ActionContext context = ActionContext.getContext();
        ValueStack vs = context.getValueStack();
        StopBean stop = (StopBean) vs.findValue("stop");
        sessionMap.put("stop", stop);
        addMessage(Messages.THE_STOP_NUMBER_FOR);
        addText(_destinationPronunciation.modify(stop.getName()));
        String stopDir = stop.getDirection();
        if (stopDir != null && stopDir.length() > 0) {
            String direction = _directionPronunciation.modify(stopDir);
            addMessage(Messages.DIRECTION_BOUND, direction);
        }
        addMessage(Messages.IS);
        addText(stop.getCode() + ".");
        addMessage(Messages.STOP_FOUND_ARRIVAL_INFO);
        // AgiActionName arrivalInfoAction = addAction("1", "/stop/arrivalsAndDeparturesForStopId");
        // arrivalInfoAction.putParam("stopIds", Arrays.asList(stop.getId()));
        addMessage(Messages.STOP_FOUND_BOOKMARK_THIS_LOCATION);
        // AgiActionName bookmarkAction = addAction("2", "/stop/bookmark");
        // bookmarkAction.putParam("stop", stop);
        addMessage(Messages.STOP_FOUND_RETURN_TO_MAIN_MENU);
        // addAction("3", "/index");
        // addAction("[04-9]", "/repeat");
        addMessage(Messages.HOW_TO_GO_BACK);
        // addAction("\\*", "/back");
        addMessage(Messages.TO_REPEAT);
        sessionMap.put("navState", new Integer(DO_ROUTING));
        return SUCCESS;
    } else {
        if (PREVIOUS_MENU_ITEM.equals(getInput())) {
            return "back";
        } else if ("1".equals(getInput())) {
            StopBean stop = (StopBean) sessionMap.get("stop");
            _stopIds = Arrays.asList(stop.getId());
            return "arrivals-and-departures";
        } else if ("2".equals(getInput())) {
            StopBean stop = (StopBean) sessionMap.get("stop");
            _stopIds = Arrays.asList(stop.getId());
            return "bookmark-stop";
        }
        return SUCCESS;
    }
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) StopBean(org.onebusaway.transit_data.model.StopBean) ActionContext(com.opensymphony.xwork2.ActionContext)

Example 19 with StopBean

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

the class SearchResultFactoryImpl method getRouteResult.

@Override
public SearchResult getRouteResult(RouteBean routeBean) {
    List<RouteDirection> directions = new ArrayList<RouteDirection>();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
    // create stop ID->stop bean map
    Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
    for (StopBean stopBean : stopsForRoute.getStops()) {
        stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
    }
    // add stops in both directions
    List<VehicleActivityStructure> journeyList = _realtimeService.getVehicleActivityForRoute(routeBean.getId(), null, 0, SystemTime.currentTimeMillis(), false);
    Map<String, List<String>> stopIdToDistanceAwayStringMap = new HashMap<String, List<String>>();
    Map<String, List<String>> stopIdToVehicleIdMap = new HashMap<String, List<String>>();
    Map<String, Boolean> stopIdToRealtimeDataMap = new HashMap<String, Boolean>();
    // build map of stop IDs to list of distance strings
    for (VehicleActivityStructure journey : journeyList) {
        // on detour?
        MonitoredCallStructure monitoredCall = journey.getMonitoredVehicleJourney().getMonitoredCall();
        if (monitoredCall == null) {
            continue;
        }
        String stopId = monitoredCall.getStopPointRef().getValue();
        fillDistanceAwayStringsList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToDistanceAwayStringMap);
        fillVehicleIdsStringList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToVehicleIdMap);
        fillRealtimeData(journey.getMonitoredVehicleJourney(), stopId, stopIdToRealtimeDataMap);
    }
    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;
            // service in this direction
            Boolean hasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), stopGroupBean.getId());
            // if there are buses on route, always have "scheduled service"
            Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForRoute(routeBean.getId(), stopGroupBean.getId(), SystemTime.currentTimeMillis());
            if (routeHasVehiclesInService) {
                hasUpcomingScheduledService = true;
            }
            // stops in this direction
            List<StopOnRoute> stopsOnRoute = null;
            if (!stopGroupBean.getStopIds().isEmpty()) {
                stopsOnRoute = new ArrayList<StopOnRoute>();
                for (String stopId : stopGroupBean.getStopIds()) {
                    if (_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), stopId, routeBean.getId(), stopGroupBean.getId())) {
                        stopsOnRoute.add(new StopOnRoute(stopIdToStopBeanMap.get(stopId), stopIdToDistanceAwayStringMap.get(stopId), stopIdToRealtimeDataMap.get(stopId), stopIdToVehicleIdMap.get(stopId)));
                    }
                }
            }
            directions.add(new RouteDirection(stopGroupBean.getName().getName(), stopGroupBean, stopsOnRoute, hasUpcomingScheduledService, null));
        }
    }
    // service alerts in this direction
    Set<String> serviceAlertDescriptions = new HashSet<String>();
    List<ServiceAlertBean> serviceAlertBeans = _realtimeService.getServiceAlertsForRoute(routeBean.getId());
    populateServiceAlerts(serviceAlertDescriptions, serviceAlertBeans);
    return new RouteResult(routeBean, directions, serviceAlertDescriptions);
}
Also used : HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) MonitoredCallStructure(uk.org.siri.siri.MonitoredCallStructure) HashSet(java.util.HashSet) RouteDirection(org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) NameBean(org.onebusaway.transit_data.model.NameBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute)

Example 20 with StopBean

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

Aggregations

StopBean (org.onebusaway.transit_data.model.StopBean)69 ArrayList (java.util.ArrayList)34 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 RouteBean (org.onebusaway.transit_data.model.RouteBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)17 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)15 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)15 HashMap (java.util.HashMap)12 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)9 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)9 NameBean (org.onebusaway.transit_data.model.NameBean)9 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)8 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashSet (java.util.HashSet)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 List (java.util.List)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 Test (org.junit.Test)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)5