Search in sources :

Example 1 with RouteAtStop

use of org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getStopResult.

@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
    List<RouteAtStop> routesWithArrivals = new ArrayList<RouteAtStop>();
    List<RouteAtStop> routesWithNoVehiclesEnRoute = new ArrayList<RouteAtStop>();
    List<RouteAtStop> routesWithNoScheduledService = new ArrayList<RouteAtStop>();
    List<RouteBean> filteredRoutes = new ArrayList<RouteBean>();
    Set<String> serviceAlertDescriptions = new HashSet<String>();
    for (RouteBean routeBean : stopBean.getRoutes()) {
        if (routeFilter != null && !routeFilter.isEmpty() && !routeFilter.contains(routeBean)) {
            filteredRoutes.add(routeBean);
            continue;
        }
        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;
                // filter out route directions that don't stop at this stop
                if (!stopGroupBean.getStopIds().contains(stopBean.getId()))
                    continue;
                // arrivals in this direction
                Map<String, List<StopOnRoute>> arrivalsForRouteAndDirection = getDisplayStringsByHeadsignForStopAndRouteAndDirection(stopBean, routeBean, stopGroupBean);
                // service alerts for this route + direction
                List<ServiceAlertBean> serviceAlertBeans = _realtimeService.getServiceAlertsForRouteAndDirection(routeBean.getId(), stopGroupBean.getId());
                populateServiceAlerts(serviceAlertDescriptions, serviceAlertBeans);
                // service in this direction
                Boolean 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"
                if (!arrivalsForRouteAndDirection.isEmpty()) {
                    hasUpcomingScheduledService = true;
                }
                if (arrivalsForRouteAndDirection.isEmpty()) {
                    directions.add(new RouteDirection(stopGroupBean.getName().getName(), stopGroupBean, Collections.<StopOnRoute>emptyList(), hasUpcomingScheduledService, Collections.<String>emptyList()));
                } else {
                    for (Map.Entry<String, List<StopOnRoute>> entry : arrivalsForRouteAndDirection.entrySet()) {
                        directions.add(new RouteDirection(entry.getKey(), stopGroupBean, entry.getValue(), hasUpcomingScheduledService, Collections.<String>emptyList()));
                    }
                }
            }
        }
        // Now one RouteAtStop object exists for each direction for each route.
        for (RouteDirection direction : directions) {
            List<RouteDirection> directionList = Collections.<RouteDirection>singletonList(direction);
            RouteAtStop routeAtStop = new RouteAtStop(routeBean, directionList, serviceAlertDescriptions);
            if (!direction.getStops().isEmpty())
                routesWithArrivals.add(routeAtStop);
            else if (Boolean.FALSE.equals(direction.getHasUpcomingScheduledService()))
                routesWithNoScheduledService.add(routeAtStop);
            else
                routesWithNoVehiclesEnRoute.add(routeAtStop);
        }
    }
    return new StopResult(stopBean, routesWithArrivals, routesWithNoVehiclesEnRoute, routesWithNoScheduledService, filteredRoutes, serviceAlertDescriptions);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.m.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.m.model.RouteAtStop) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) ArrayList(java.util.ArrayList) List(java.util.List) NameBean(org.onebusaway.transit_data.model.NameBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) HashMap(java.util.HashMap) Map(java.util.Map) StopOnRoute(org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute) StopResult(org.onebusaway.enterprise.webapp.actions.m.model.StopResult) HashSet(java.util.HashSet)

Example 2 with RouteAtStop

use of org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop in project onebusaway-application-modules by camsys.

the class IndexAction method getUniqueServiceAlertsForResults.

public Set<String> getUniqueServiceAlertsForResults() {
    Set<String> uniqueServiceAlerts = new HashSet<String>();
    for (SearchResult _result : _results.getMatches()) {
        if (_results.getResultType().equals("RouteResult")) {
            RouteResult result = (RouteResult) _result;
            uniqueServiceAlerts.addAll(result.getServiceAlerts());
        } else if (_results.getResultType().equals("StopResult")) {
            StopResult result = (StopResult) _result;
            for (RouteAtStop route : result.getAllRoutesAvailable()) {
                uniqueServiceAlerts.addAll(route.getServiceAlerts());
            }
        }
    }
    return uniqueServiceAlerts;
}
Also used : RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) SearchResult(org.onebusaway.presentation.model.SearchResult) RouteAtStop(org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop) StopResult(org.onebusaway.enterprise.webapp.actions.m.model.StopResult) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 RouteAtStop (org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop)2 StopResult (org.onebusaway.enterprise.webapp.actions.m.model.StopResult)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 RouteDirection (org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection)1 RouteResult (org.onebusaway.enterprise.webapp.actions.m.model.RouteResult)1 StopOnRoute (org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute)1 SearchResult (org.onebusaway.presentation.model.SearchResult)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1