Search in sources :

Example 1 with StopRouteDirection

use of org.onebusaway.api.actions.siri.model.StopRouteDirection in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method processAnnotatedStopPoints.

private void processAnnotatedStopPoints(List<String> agencyIds, List<AgencyAndId> routeIds, List<StopBean> stopBeans, List<AnnotatedStopPointStructure> annotatedStopPoints, Map<Filters, String> filters, Map<String, StopsForRouteBean> stopsForRouteCache, DetailLevel detailLevel, long currentTime) {
    for (StopBean stopBean : stopBeans) {
        List<StopsForRouteBean> stopsForRouteList = new ArrayList<StopsForRouteBean>();
        boolean filterByLineRef = (routeIds != null && routeIds.size() > 0) ? true : false;
        boolean containsLineRef = false;
        // Get a list of all the routes for the stop
        for (RouteBean route : stopBean.getRoutes()) {
            // Filter By AgencyID
            if (route.getAgency() == null || !agencyIds.contains(route.getAgency().getId()))
                continue;
            // Add list of stops retreived from route to cache
            StopsForRouteBean stopsForRoute = stopsForRouteCache.get(route.getId());
            if (stopsForRoute == null) {
                stopsForRoute = _transitDataService.getStopsForRoute(route.getId());
                stopsForRouteCache.put(route.getId(), stopsForRoute);
            }
            if (stopsForRoute != null)
                stopsForRouteList.add(stopsForRoute);
            if (filterByLineRef && routeIds.contains(AgencyAndIdLibrary.convertFromString(route.getId())))
                containsLineRef = true;
        }
        // Filter By LineRef
        if (filterByLineRef && !containsLineRef)
            continue;
        // Get Stops with List of Routes, Direction, and Upcoming Service Info
        StopRouteDirection stopRouteDirection = getStopRouteDirection(stopBean, stopsForRouteList, filters);
        // Skip if No Route Directions Found
        if (stopRouteDirection == null)
            continue;
        // Used to filter stops that don't have any routes that match hasUpcomingScheduledStop
        if (stopRouteDirection.getRouteDirections() == null || stopRouteDirection.getRouteDirections().size() == 0)
            continue;
        AnnotatedStopPointStructure annotatedStopPoint = new AnnotatedStopPointStructure();
        boolean isValid = SiriSupportV2.fillAnnotatedStopPointStructure(annotatedStopPoint, stopRouteDirection, filters, detailLevel, currentTime);
        if (isValid)
            annotatedStopPoints.add(annotatedStopPoint);
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean)

Example 2 with StopRouteDirection

use of org.onebusaway.api.actions.siri.model.StopRouteDirection in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getStopRouteDirection.

private StopRouteDirection getStopRouteDirection(StopBean stop, List<StopsForRouteBean> stopsForRouteList, Map<Filters, String> filters) {
    // Filter Values
    String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
    String directionIdFilter = filters.get(Filters.DIRECTION_REF);
    StopRouteDirection stopRouteDirection = new StopRouteDirection(stop);
    for (StopsForRouteBean stopsForRoute : stopsForRouteList) // Check to see which stop group the specified stop exists in (usually 2 stop groups)
    for (StopGroupingBean stopGrouping : stopsForRoute.getStopGroupings()) {
        for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
            NameBean name = stopGroup.getName();
            String type = name.getType();
            String directionId = stopGroup.getId();
            RouteBean route = stopsForRoute.getRoute();
            // Destination and DirectionId Filter
            if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
                continue;
            // filter out route directions that don't stop at this stop
            if (!stopGroup.getStopIds().contains(stop.getId()))
                continue;
            // filter hasUpcomingScheduledService
            Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((route.getAgency() != null ? route.getAgency().getId() : null), SystemTime.currentTimeMillis(), stop.getId(), stopsForRoute.getRoute().getId(), directionId);
            String hasUpcomingScheduledServiceVal = String.valueOf(hasUpcomingScheduledService);
            if (!hasUpcomingScheduledServiceVal.trim().equals("false")) {
                hasUpcomingScheduledServiceVal = "true";
            }
            if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter))
                continue;
            stopRouteDirection.addRouteDirection(new RouteForDirection(route.getId(), directionId, hasUpcomingScheduledService));
        }
    }
    return stopRouteDirection;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteForDirection(org.onebusaway.api.actions.siri.model.RouteForDirection) NameBean(org.onebusaway.transit_data.model.NameBean)

Aggregations

StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)2 ArrayList (java.util.ArrayList)1 RouteForDirection (org.onebusaway.api.actions.siri.model.RouteForDirection)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1 AnnotatedStopPointStructure (uk.org.siri.siri_2.AnnotatedStopPointStructure)1