Search in sources :

Example 1 with RouteDirection

use of org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection 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 2 with RouteDirection

use of org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getStopResult.

@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
    List<RouteAtStop> routesAtStop = new ArrayList<RouteAtStop>();
    for (RouteBean routeBean : stopBean.getRoutes()) {
        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;
                List<String> polylines = new ArrayList<String>();
                for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
                    polylines.add(polyline.getPoints());
                }
                Boolean hasUpcomingScheduledService = null;
                // We do this to prevent checking if there is service in a direction that does not even serve this stop.
                if (stopGroupBean.getStopIds().contains(stopBean.getId())) {
                    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"
                    Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForStopAndRoute(stopBean.getId(), routeBean.getId(), SystemTime.currentTimeMillis());
                    if (routeHasVehiclesInService) {
                        hasUpcomingScheduledService = true;
                    }
                }
                directions.add(new RouteDirection(stopGroupBean, polylines, null, hasUpcomingScheduledService));
            }
        }
        RouteAtStop routeAtStop = new RouteAtStop(routeBean, directions);
        routesAtStop.add(routeAtStop);
    }
    return new StopResult(stopBean, routesAtStop);
}
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) RouteAtStop(org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) StopResult(org.onebusaway.enterprise.webapp.actions.api.model.StopResult)

Example 3 with RouteDirection

use of org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection in project onebusaway-application-modules by camsys.

the class StopForIdAction method execute.

@Override
public String execute() {
    if (_stopId == null) {
        return SUCCESS;
    }
    StopBean stop = _transitDataService.getStop(_stopId);
    if (stop == null) {
        return SUCCESS;
    }
    List<RouteAtStop> routesAtStop = new ArrayList<RouteAtStop>();
    for (RouteBean routeBean : stop.getRoutes()) {
        StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
        List<RouteDirection> routeDirections = new ArrayList<RouteDirection>();
        List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
        for (StopGroupingBean stopGroupingBean : stopGroupings) {
            for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                if (_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), _stopId, routeBean.getId(), stopGroupBean.getId())) {
                    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(_stopId))
                        continue;
                    Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stop.getId(), routeBean.getId(), stopGroupBean.getId());
                    // if there are buses on route, always have "scheduled service"
                    Boolean routeHasVehiclesInService = true;
                    if (routeHasVehiclesInService) {
                        hasUpcomingScheduledService = true;
                    }
                    routeDirections.add(new RouteDirection(stopGroupBean, null, null, hasUpcomingScheduledService));
                }
            }
        }
        RouteAtStop routeAtStop = new RouteAtStop(routeBean, routeDirections);
        routesAtStop.add(routeAtStop);
    }
    _result = new StopResult(stop, routesAtStop);
    List<MonitoredStopVisitStructure> visits = _realtimeService.getMonitoredStopVisitsForStop(_stopId, 0, SystemTime.currentTimeMillis());
    _response = generateSiriResponse(visits, AgencyAndIdLibrary.convertFromString(_stopId));
    return SUCCESS;
}
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) RouteAtStop(org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) StopResult(org.onebusaway.enterprise.webapp.actions.api.model.StopResult)

Aggregations

ArrayList (java.util.ArrayList)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 NameBean (org.onebusaway.transit_data.model.NameBean)3 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)3 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)3 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)3 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)2 StopResult (org.onebusaway.enterprise.webapp.actions.api.model.StopResult)2 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 RouteResult (org.onebusaway.enterprise.webapp.actions.api.model.RouteResult)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 MonitoredStopVisitStructure (uk.org.siri.siri.MonitoredStopVisitStructure)1