use of org.onebusaway.transit_data.model.NameBean 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());
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;
List<String> polylines = new ArrayList<String>();
for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
polylines.add(polyline.getPoints());
}
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;
}
directions.add(new RouteDirection(stopGroupBean, polylines, null, hasUpcomingScheduledService));
}
}
return new RouteResult(routeBean, directions);
}
use of org.onebusaway.transit_data.model.NameBean 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.transit_data.model.NameBean 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.transit_data.model.NameBean 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;
}
use of org.onebusaway.transit_data.model.NameBean in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImplTest method runGetStopResult.
// Support methods
private StopResult runGetStopResult(List<ServiceAlertBean> serviceAlerts) {
StopsForRouteBean stopsForRouteBean = mock(StopsForRouteBean.class);
List<StopGroupingBean> stopGroupingBeans = new ArrayList<StopGroupingBean>();
when(stopsForRouteBean.getStopGroupings()).thenReturn(stopGroupingBeans);
StopGroupingBean stopGroupingBean = mock(StopGroupingBean.class);
stopGroupingBeans.add(stopGroupingBean);
List<StopGroupBean> stopGroups = new ArrayList<StopGroupBean>();
StopGroupBean stopGroupBean = mock(StopGroupBean.class);
stopGroups.add(stopGroupBean);
when(stopGroupingBean.getStopGroups()).thenReturn(stopGroups);
List<String> stopIds = new ArrayList<String>();
when(stopGroupBean.getStopIds()).thenReturn(stopIds);
NameBean nameBean = mock(NameBean.class);
when(nameBean.getType()).thenReturn("destination");
when(stopGroupBean.getName()).thenReturn(nameBean);
List<String> stopGroupBeanStopIds = new ArrayList<String>();
stopGroupBeanStopIds.add(TEST_STOP_ID);
when(stopGroupBean.getStopIds()).thenReturn(stopGroupBeanStopIds);
when(stopGroupBean.getId()).thenReturn(TEST_STOP_ID);
stopIds.add(TEST_STOP_ID);
List<RouteBean> routeBeans = new ArrayList<RouteBean>();
routeBeans.add(createRouteBean());
StopBean stopBean = mock(StopBean.class);
when(stopBean.getId()).thenReturn(TEST_STOP_ID);
when(stopBean.getRoutes()).thenReturn(routeBeans);
List<MonitoredStopVisitStructure> monitoredStopVisits = new ArrayList<MonitoredStopVisitStructure>();
MonitoredStopVisitStructure monitoredStopVisitStructure = mock(MonitoredStopVisitStructure.class);
monitoredStopVisits.add(monitoredStopVisitStructure);
MonitoredVehicleJourneyStructure monVehJourney = mock(MonitoredVehicleJourneyStructure.class);
when(monitoredStopVisitStructure.getMonitoredVehicleJourney()).thenReturn(monVehJourney);
when(monitoredStopVisitStructure.getRecordedAtTime()).thenReturn(new Date(TEST_TIME));
LineRefStructure lineRefStructure = mock(LineRefStructure.class);
when(monVehJourney.getLineRef()).thenReturn(lineRefStructure);
when(lineRefStructure.getValue()).thenReturn(ROUTE_ID);
DirectionRefStructure directionRef = mock(DirectionRefStructure.class);
when(monVehJourney.getDirectionRef()).thenReturn(directionRef);
when(directionRef.getValue()).thenReturn(TEST_STOP_ID);
NaturalLanguageStringStructure natLangStrStructure = mock(NaturalLanguageStringStructure.class);
when(natLangStrStructure.getValue()).thenReturn(TEST_DESTINATION_NAME);
when(monVehJourney.getDestinationName()).thenReturn(natLangStrStructure);
MonitoredCallStructure monCall = mock(MonitoredCallStructure.class);
ExtensionsStructure extensions = mock(ExtensionsStructure.class);
SiriExtensionWrapper siriExtensionWrapper = mock(SiriExtensionWrapper.class);
SiriDistanceExtension distances = mock(SiriDistanceExtension.class);
when(distances.getPresentableDistance()).thenReturn(TEST_PRESENTABLE_DISTANCE);
when(siriExtensionWrapper.getDistances()).thenReturn(distances);
when(extensions.getAny()).thenReturn(siriExtensionWrapper);
when(monCall.getExtensions()).thenReturn(extensions);
when(monVehJourney.getMonitoredCall()).thenReturn(monCall);
when(_realtimeService.getMonitoredStopVisitsForStop(eq(TEST_STOP_ID), eq(0), anyLong())).thenReturn(monitoredStopVisits);
when(_transitDataService.getStopsForRoute(anyString())).thenReturn(stopsForRouteBean);
when(_realtimeService.getServiceAlertsForRouteAndDirection(ROUTE_ID, TEST_STOP_ID)).thenReturn(serviceAlerts);
SearchResultFactoryImpl srf = new SearchResultFactoryImpl(_transitDataService, _realtimeService, _configurationService);
Set<RouteBean> routeFilter = new HashSet<RouteBean>();
StopResult result = (StopResult) srf.getStopResult(stopBean, routeFilter);
return result;
}
Aggregations