use of org.onebusaway.api.actions.siri.model.RouteResult in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getRouteResult.
private RouteResult getRouteResult(RouteBean routeBean, Map<Filters, String> filters) {
List<RouteDirection> directions = new ArrayList<RouteDirection>();
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
// Filter Values
String directionIdFilter = filters.get(Filters.DIRECTION_REF);
String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
// create stop ID->stop bean map
Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
for (StopBean stopBean : stopsForRoute.getStops()) {
stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
}
List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
for (StopGroupingBean stopGroupingBean : stopGroupings) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
NameBean name = stopGroupBean.getName();
String type = name.getType();
String directionId = stopGroupBean.getId();
// Destination and DirectionId Filter
if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
continue;
List<String> polylines = new ArrayList<String>();
for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
polylines.add(polyline.getPoints());
}
// TODO - Re-evaluate the best method to determine upcoming scheduled service
Boolean routeHasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), directionId);
// if there are buses on route, always have "scheduled service"
Boolean routeHasVehiclesInService = getVehiclesInServiceForRoute(routeBean.getId(), directionId, SystemTime.currentTimeMillis());
if (routeHasVehiclesInService) {
routeHasUpcomingScheduledService = true;
}
String hasUpcomingScheduledServiceVal = String.valueOf(routeHasUpcomingScheduledService);
// String hasUpcomingScheduledServiceVal = String.valueOf(routeHasVehiclesInService);
if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter) || routeHasUpcomingScheduledService == null || !routeHasUpcomingScheduledService)
continue;
// stops in this direction
List<StopOnRoute> stopsOnRoute = null;
if (!stopGroupBean.getStopIds().isEmpty()) {
stopsOnRoute = new ArrayList<StopOnRoute>();
for (String stopId : stopGroupBean.getStopIds()) {
// service in this direction
StopBean stopBean = stopIdToStopBeanMap.get(stopId);
Boolean stopHasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
stopsOnRoute.add(new StopOnRoute(stopBean, stopHasUpcomingScheduledService));
}
}
directions.add(new RouteDirection(stopGroupBean, polylines, stopsOnRoute, routeHasUpcomingScheduledService));
}
}
return new RouteResult(routeBean, directions);
}
use of org.onebusaway.api.actions.siri.model.RouteResult in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getAnnotatedLineStructures.
@Override
public Map<Boolean, List<AnnotatedLineStructure>> getAnnotatedLineStructures(List<String> agencyIds, List<AgencyAndId> routeIds, DetailLevel detailLevel, long currentTime, Map<Filters, String> filters) {
// Store processed StopBean as AnnotatedStopPointStructure
List<AnnotatedLineStructure> annotatedLines = new ArrayList<AnnotatedLineStructure>();
// AnnotatedStopPointStructures List with hasUpcomingScheduledService
Map<Boolean, List<AnnotatedLineStructure>> output = new HashMap<Boolean, List<AnnotatedLineStructure>>();
Boolean upcomingServiceAllStops = null;
for (AgencyAndId rteId : routeIds) {
String routeId = AgencyAndId.convertToString(rteId);
RouteBean routeBean = _transitDataService.getRouteForId(routeId);
// Filter By AgencyID
if (routeBean.getAgency() == null || !agencyIds.contains(routeBean.getAgency().getId()))
continue;
AnnotatedLineStructure annotatedLineStructure = new AnnotatedLineStructure();
RouteResult routeResult = getRouteResult(routeBean, filters);
// Skip Routes with no stops
if (routeResult.getDirections() == null || routeResult.getDirections().size() == 0)
continue;
boolean isValid = SiriSupportV2.fillAnnotatedLineStructure(annotatedLineStructure, routeResult, filters, detailLevel, currentTime);
if (isValid)
annotatedLines.add(annotatedLineStructure);
}
output.put(upcomingServiceAllStops, annotatedLines);
return output;
}
Aggregations