Search in sources :

Example 6 with StopsForRouteBean

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

the class StopPointsActionTest method initialize.

@Before
public void initialize() throws Exception {
    // Agencies
    Map<String, List<CoordinateBounds>> agencies = new HashMap<String, List<CoordinateBounds>>();
    agencies.put("1", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.410813, -122.038662, 47.810813, -122.638662))));
    agencies.put("3", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(0.0, 0.0, 0.0, 0.0))));
    agencies.put("40", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.510813, -122.138662, 47.710813, -122.538662))));
    // Route Bean
    Builder routeBuilder = RouteBean.builder();
    routeBuilder.setAgency(new AgencyBean());
    routeBuilder.setId("1_100194");
    routeBean = routeBuilder.create();
    // Route Bean List
    routes = new ArrayList<RouteBean>(1);
    routes.add(routeBean);
    // Stop Bean
    stopBean = new StopBean();
    stopBean.setId("1_430");
    stopBean.setName("3rd Ave & Pine St");
    stopBean.setLon(-122.338662);
    stopBean.setLat(47.610813);
    stopBean.setRoutes(routes);
    // Stop Bean List
    stops = new ArrayList<StopBean>(1);
    stops.add(stopBean);
    // Stop Group
    stopIds = new ArrayList<String>(1);
    stopIds.add(stopBean.getId());
    stopGroupName = new NameBean("destination", "Destination");
    stopGroup = new StopGroupBean();
    stopGroup.setId("0");
    stopGroup.setStopIds(stopIds);
    stopGroup.setName(stopGroupName);
    // Stop Group List
    stopGroups = new ArrayList<StopGroupBean>(1);
    stopGroups.add(stopGroup);
    // Stop Grouping
    stopGrouping = new StopGroupingBean();
    stopGrouping.setStopGroups(stopGroups);
    // Stop Grouping List
    List<StopGroupingBean> stopGroupings = new ArrayList<StopGroupingBean>(1);
    stopGroupings.add(stopGrouping);
    // Stops For Route
    stopsForRouteBean = new StopsForRouteBean();
    stopsForRouteBean.setRoute(routeBean);
    stopsForRouteBean.setStopGroupings(stopGroupings);
    stopsForRouteBean.setStops(stops);
    // LineDirectionStructure
    LineDirectionStructure lds = new LineDirectionStructure();
    DirectionRefStructure drs = new DirectionRefStructure();
    LineRefStructure lrs = new LineRefStructure();
    lds.setDirectionRef(drs);
    lds.setLineRef(lrs);
    drs.setValue("0");
    lrs.setValue("1_100194");
    // Location Structure
    LocationStructure ls = new LocationStructure();
    BigDecimal lat = new BigDecimal(47.610813);
    BigDecimal lon = new BigDecimal(-122.338662);
    ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    // StopNames
    NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
    stopName.setValue("3rd Ave & Pine St");
    List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
    stopNames.add(stopName);
    // StopPointRef
    StopPointRefStructure stopPointRef = new StopPointRefStructure();
    stopPointRef.setValue("1_430");
    // Monitored
    Boolean monitored = true;
    // AnnotatedStopPointStructure
    AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
    mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
    mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
    mockStopPoint.setLocation(ls);
    mockStopPoint.getStopName().add(stopName);
    mockStopPoint.setStopPointRef(stopPointRef);
    mockStopPoint.setMonitored(monitored);
    List<AnnotatedStopPointStructure> mockStopPoints = new ArrayList<AnnotatedStopPointStructure>(1);
    mockStopPoints.add(mockStopPoint);
    Map<Boolean, List<AnnotatedStopPointStructure>> annotatedStopPointMap = new HashMap<Boolean, List<AnnotatedStopPointStructure>>();
    annotatedStopPointMap.put(true, mockStopPoints);
    when(realtimeService.getAnnotatedStopPointStructures(anyListOf(String.class), anyListOf(AgencyAndId.class), any(DetailLevel.class), anyLong(), anyMapOf(Filters.class, String.class))).thenReturn(annotatedStopPointMap);
    // XML Serializer
    SiriXmlSerializerV2 serializer = new SiriXmlSerializerV2();
    when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
    // Print Writer
    PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
        // Do nothing
        }
    });
    when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
    when(transitDataService.getRouteForId("1_430")).thenReturn(routeBean);
    when(transitDataService.getStopsForRoute("1_430")).thenReturn(stopsForRouteBean);
    when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
    when(transitDataService.getAgencyIdsWithCoverageArea()).thenReturn(agencies);
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) LineDirectionStructure(uk.org.siri.siri_2.LineDirectionStructure) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) Builder(org.onebusaway.transit_data.model.RouteBean.Builder) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matchers.anyString(org.mockito.Matchers.anyString) LocationStructure(uk.org.siri.siri_2.LocationStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Filters(org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters) ArrayList(java.util.ArrayList) List(java.util.List) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) PrintWriter(java.io.PrintWriter) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) SiriXmlSerializerV2(org.onebusaway.transit_data_federation.siri.SiriXmlSerializerV2) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Before(org.junit.Before)

Example 7 with StopsForRouteBean

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

the class StopsForRouteAction method execute.

@Override
public String execute() throws Exception {
    /* Need to check this for testing from  the web */
    Integer navState = (Integer) sessionMap.get("navState");
    if (navState == null) {
        _log.debug("StopsForRouteAction:navState is null");
    } else {
        _log.debug("StopsForRouteAction:navState is NOT null, resetting to DISPLAY_DATA");
        navState = DISPLAY_DATA;
        sessionMap.put("navState", new Integer(navState));
    }
    _log.debug("in StopsForRoute with input: " + getInput() + " route.getId: " + _route.getId());
    clearInput();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(_route.getId());
    List<Integer> selectionIndices = Collections.emptyList();
    StopSelectionBean selection = _stopSelectionService.getSelectedStops(stopsForRoute, selectionIndices);
    List<NameBean> names = new ArrayList<NameBean>(selection.getNames());
    _navigation = new NavigationBean();
    _navigation.setRoute(_route);
    _navigation.setStopsForRoute(stopsForRoute);
    _navigation.setSelectionIndices(selectionIndices);
    _navigation.setCurrentIndex(0);
    _navigation.setSelection(selection);
    _navigation.setNames(names);
    // Set navigation bean in session
    sessionMap.put("navigation", _navigation);
    if (selection.hasStop()) {
        _log.debug("in StopsForRoute with input=" + getInput());
        _stop = selection.getStop();
        return "stopFound";
    }
    return SUCCESS;
}
Also used : StopSelectionBean(org.onebusaway.presentation.model.StopSelectionBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) NameBean(org.onebusaway.transit_data.model.NameBean)

Example 8 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean 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 9 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean 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 10 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean 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)

Aggregations

StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)26 ArrayList (java.util.ArrayList)21 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)21 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)21 NameBean (org.onebusaway.transit_data.model.NameBean)16 StopBean (org.onebusaway.transit_data.model.StopBean)15 RouteBean (org.onebusaway.transit_data.model.RouteBean)13 HashMap (java.util.HashMap)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)8 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)7 HashSet (java.util.HashSet)5 List (java.util.List)5 Matchers.anyString (org.mockito.Matchers.anyString)3 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)3 AnnotatedStopPointStructure (uk.org.siri.siri_2.AnnotatedStopPointStructure)3 Map (java.util.Map)2 Before (org.junit.Before)2 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)2