use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult 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);
}
use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImplTest method testGetRouteResultServiceAlertWithSummariesOnly.
@Test
public void testGetRouteResultServiceAlertWithSummariesOnly() {
RouteResult result = runGetRouteResult(createServiceAlerts(new String[] {}, new String[] { TEST_SUMMARY }));
Set<String> alerts = result.getServiceAlerts();
assertEquals(1, alerts.size());
assertEquals(TEST_SUMMARY, alerts.toArray()[0]);
assertEquals("name not expected", ROUTE_ID, result.getId());
}
use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult 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;
}
use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.
the class IndexAction method getRouteColors.
public String getRouteColors() {
Set<String> routeColors = new HashSet<String>();
for (SearchResult _result : _results.getMatches()) {
RouteResult result = (RouteResult) _result;
routeColors.add(result.getColor());
}
return StringUtils.join(routeColors, ",");
}
use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImplTest method testGetRouteResultServiceAlertWithDescriptionsOnly.
@Test
public void testGetRouteResultServiceAlertWithDescriptionsOnly() {
RouteResult result = runGetRouteResult(createServiceAlerts(new String[] { TEST_DESCRIPTION, TEST_DESCRIPTION2 }, new String[] { TEST_SUMMARY }));
Set<String> alerts = result.getServiceAlerts();
assertEquals(2, alerts.size());
String[] array = alerts.toArray(new String[] {});
// array position is no longer guaranteed
boolean found0 = ((TEST_DESCRIPTION).equals(array[0])) || ((TEST_DESCRIPTION).equals(array[1]));
boolean found1 = ((TEST_DESCRIPTION2).equals(array[0])) || ((TEST_DESCRIPTION2).equals(array[1]));
assertTrue(found0);
assertTrue(found1);
assertEquals("name not expected", ROUTE_ID, result.getId());
}
Aggregations