use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesForStopIds.
public StopsWithArrivalsAndDeparturesBean getArrivalsAndDeparturesForStopIds(Set<AgencyAndId> ids, ArrivalsAndDeparturesQueryBean query) throws NoSuchStopServiceException {
List<StopBean> stops = new ArrayList<StopBean>();
List<ArrivalAndDepartureBean> allArrivalsAndDepartures = new ArrayList<ArrivalAndDepartureBean>();
Set<AgencyAndId> allNearbyStopIds = new HashSet<AgencyAndId>();
Map<String, ServiceAlertBean> situationsById = new HashMap<String, ServiceAlertBean>();
Counter<TimeZone> timeZones = new Counter<TimeZone>();
for (AgencyAndId id : ids) {
StopBean stopBean = _stopBeanService.getStopForId(id);
stops.add(stopBean);
List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
allArrivalsAndDepartures.addAll(arrivalsAndDepartures);
List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stopBean, 100);
allNearbyStopIds.addAll(nearbyStopIds);
TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(id.getAgencyId());
timeZones.increment(timeZone);
List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
for (ServiceAlertBean situation : situations) situationsById.put(situation.getId(), situation);
}
allNearbyStopIds.removeAll(ids);
List<StopBean> nearbyStops = new ArrayList<StopBean>();
for (AgencyAndId id : allNearbyStopIds) {
StopBean stop = _stopBeanService.getStopForId(id);
nearbyStops.add(stop);
}
TimeZone timeZone = timeZones.getMax();
if (timeZone == null)
timeZone = TimeZone.getDefault();
StopsWithArrivalsAndDeparturesBean result = new StopsWithArrivalsAndDeparturesBean();
result.setStops(stops);
result.setArrivalsAndDepartures(allArrivalsAndDepartures);
result.setNearbyStops(nearbyStops);
result.setSituations(new ArrayList<ServiceAlertBean>(situationsById.values()));
result.setTimeZone(timeZone.getID());
return result;
}
use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesForRouteAction method getRouteIdsForMatchingRoutes.
private Set<String> getRouteIdsForMatchingRoutes() {
StopsWithArrivalsAndDeparturesBean result = _model.getResult();
Set<String> ids = new HashSet<String>();
for (StopBean stop : result.getStops()) {
for (RouteBean route : stop.getRoutes()) {
if (route.getShortName().equals(_route))
ids.add(route.getId());
}
}
return ids;
}
use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesTemplate method buildTemplate.
@Override
public void buildTemplate(ActionContext context) {
ValueStack valueStack = context.getValueStack();
PhoneArrivalsAndDeparturesModel model = (PhoneArrivalsAndDeparturesModel) valueStack.findValue("model");
StopsWithArrivalsAndDeparturesBean result = model.getResult();
buildPredictedArrivalsTemplate(result.getArrivalsAndDepartures());
addMessage(Messages.ARRIVAL_INFO_ON_SPECIFIC_ROUTE);
AgiActionName byRouteAction = addActionWithParameterFromMatch("1(\\d+)#", "/stop/arrivalsAndDeparturesForRoute", "route", 1);
byRouteAction.putParam("model", model);
addMessage(Messages.ARRIVAL_INFO_BOOKMARK_THIS_LOCATION);
AgiActionName bookmarkAction = addAction("2", "/stop/bookmark");
bookmarkAction.putParam("stops", result.getStops());
addMessage(Messages.ARRIVAL_INFO_RETURN_TO_MAIN_MENU);
addAction("3", "/index");
addAction("(#|[04-9]|1.*\\*)", "/repeat");
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesAction method displayData.
private String displayData() {
PhoneArrivalsAndDeparturesModel model = (PhoneArrivalsAndDeparturesModel) sessionMap.get("_model");
StopsWithArrivalsAndDeparturesBean result = model.getResult();
buildPredictedArrivals(result.getArrivalsAndDepartures(), result.getStops());
setNextAction("stops/arrivals-and-departures");
_log.debug("setting navState, have stopIds=" + model.getStopIds());
sessionMap.put("navState", new Integer(DO_ROUTING));
sessionMap.put("stopIds", model.getStopIds());
sessionMap.put("stops", result.getStops());
return SUCCESS;
}
use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesAction method filterArrivalsAndDeparturesByRoute.
private void filterArrivalsAndDeparturesByRoute(String[] tokens) {
// Filter by route
Set<String> routes = new HashSet<String>();
for (String token : tokens) {
String[] routeNames = token.split(",");
for (String routeName : routeNames) routes.add(routeName);
}
StopsWithArrivalsAndDeparturesBean result = _model.getResult();
Iterator<ArrivalAndDepartureBean> it = result.getArrivalsAndDepartures().iterator();
while (it.hasNext()) {
ArrivalAndDepartureBean bean = it.next();
TripBean trip = bean.getTrip();
RouteBean route = trip.getRoute();
String routeName = RoutePresenter.getNameForRoute(route);
if (!routes.contains(routeName))
it.remove();
}
}
Aggregations