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);
}
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;
}
Aggregations