Search in sources :

Example 6 with StopGroupingBean

use of org.onebusaway.transit_data.model.StopGroupingBean 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);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) RouteResult(org.onebusaway.enterprise.webapp.actions.api.model.RouteResult) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean)

Example 7 with StopGroupingBean

use of org.onebusaway.transit_data.model.StopGroupingBean 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);
}
Also used : HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) MonitoredCallStructure(uk.org.siri.siri.MonitoredCallStructure) HashSet(java.util.HashSet) RouteDirection(org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) NameBean(org.onebusaway.transit_data.model.NameBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute)

Example 8 with StopGroupingBean

use of org.onebusaway.transit_data.model.StopGroupingBean 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);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteAtStop(org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) ArrayList(java.util.ArrayList) List(java.util.List) NameBean(org.onebusaway.transit_data.model.NameBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) HashMap(java.util.HashMap) Map(java.util.Map) StopOnRoute(org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute) StopResult(org.onebusaway.enterprise.webapp.actions.m.model.StopResult) HashSet(java.util.HashSet)

Example 9 with StopGroupingBean

use of org.onebusaway.transit_data.model.StopGroupingBean 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;
}
Also used : StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute)

Example 10 with StopGroupingBean

use of org.onebusaway.transit_data.model.StopGroupingBean in project onebusaway-application-modules by camsys.

the class StopsForRouteAction method execute.

@Override
@Actions({ @Action(value = "/where/iphone/stops-for-route") })
public String execute() throws ServiceException {
    if (_id == null || _id.length() == 0)
        return INPUT;
    _route = _transitDataService.getRouteForId(_id);
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(_id);
    Map<String, StopGroupingBean> groupingsByType = MappingLibrary.mapToValue(stopsForRoute.getStopGroupings(), "type", String.class);
    StopGroupingBean byDirection = groupingsByType.get(TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
    if (_groupIndex == -1) {
        if (byDirection != null) {
            for (StopGroupBean group : byDirection.getStopGroups()) _directionNames.add(group.getName());
        }
        _stops = stopsForRoute.getStops();
        Collections.sort(_stops, _stopNameComparator);
    } else {
        if (byDirection == null)
            return INPUT;
        List<StopGroupBean> groups = byDirection.getStopGroups();
        if (_groupIndex < 0 && groups.size() <= _groupIndex)
            return INPUT;
        Map<String, StopBean> stopById = MappingLibrary.mapToValue(stopsForRoute.getStops(), "id", String.class);
        StopGroupBean stopGroup = groups.get(_groupIndex);
        _stops = new ArrayList<StopBean>();
        for (String stopId : stopGroup.getStopIds()) _stops.add(stopById.get(stopId));
    }
    return SUCCESS;
}
Also used : StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopBean(org.onebusaway.transit_data.model.StopBean) Actions(org.apache.struts2.convention.annotation.Actions)

Aggregations

StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)23 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)21 ArrayList (java.util.ArrayList)17 StopBean (org.onebusaway.transit_data.model.StopBean)15 NameBean (org.onebusaway.transit_data.model.NameBean)14 RouteBean (org.onebusaway.transit_data.model.RouteBean)12 HashMap (java.util.HashMap)9 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)7 HashSet (java.util.HashSet)5 List (java.util.List)4 Matchers.anyString (org.mockito.Matchers.anyString)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)3 Map (java.util.Map)2 Before (org.junit.Before)2 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)2 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)2 StopResult (org.onebusaway.enterprise.webapp.actions.api.model.StopResult)2