Search in sources :

Example 21 with RouteBean

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

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

the class SearchResultFactoryImplTest method runGetStopResult.

// Support methods
private StopResult runGetStopResult(List<ServiceAlertBean> serviceAlerts) {
    StopsForRouteBean stopsForRouteBean = mock(StopsForRouteBean.class);
    List<StopGroupingBean> stopGroupingBeans = new ArrayList<StopGroupingBean>();
    when(stopsForRouteBean.getStopGroupings()).thenReturn(stopGroupingBeans);
    StopGroupingBean stopGroupingBean = mock(StopGroupingBean.class);
    stopGroupingBeans.add(stopGroupingBean);
    List<StopGroupBean> stopGroups = new ArrayList<StopGroupBean>();
    StopGroupBean stopGroupBean = mock(StopGroupBean.class);
    stopGroups.add(stopGroupBean);
    when(stopGroupingBean.getStopGroups()).thenReturn(stopGroups);
    List<String> stopIds = new ArrayList<String>();
    when(stopGroupBean.getStopIds()).thenReturn(stopIds);
    NameBean nameBean = mock(NameBean.class);
    when(nameBean.getType()).thenReturn("destination");
    when(stopGroupBean.getName()).thenReturn(nameBean);
    List<String> stopGroupBeanStopIds = new ArrayList<String>();
    stopGroupBeanStopIds.add(TEST_STOP_ID);
    when(stopGroupBean.getStopIds()).thenReturn(stopGroupBeanStopIds);
    when(stopGroupBean.getId()).thenReturn(TEST_STOP_ID);
    stopIds.add(TEST_STOP_ID);
    List<RouteBean> routeBeans = new ArrayList<RouteBean>();
    routeBeans.add(createRouteBean());
    StopBean stopBean = mock(StopBean.class);
    when(stopBean.getId()).thenReturn(TEST_STOP_ID);
    when(stopBean.getRoutes()).thenReturn(routeBeans);
    List<MonitoredStopVisitStructure> monitoredStopVisits = new ArrayList<MonitoredStopVisitStructure>();
    MonitoredStopVisitStructure monitoredStopVisitStructure = mock(MonitoredStopVisitStructure.class);
    monitoredStopVisits.add(monitoredStopVisitStructure);
    MonitoredVehicleJourneyStructure monVehJourney = mock(MonitoredVehicleJourneyStructure.class);
    when(monitoredStopVisitStructure.getMonitoredVehicleJourney()).thenReturn(monVehJourney);
    when(monitoredStopVisitStructure.getRecordedAtTime()).thenReturn(new Date(TEST_TIME));
    LineRefStructure lineRefStructure = mock(LineRefStructure.class);
    when(monVehJourney.getLineRef()).thenReturn(lineRefStructure);
    when(lineRefStructure.getValue()).thenReturn(ROUTE_ID);
    DirectionRefStructure directionRef = mock(DirectionRefStructure.class);
    when(monVehJourney.getDirectionRef()).thenReturn(directionRef);
    when(directionRef.getValue()).thenReturn(TEST_STOP_ID);
    NaturalLanguageStringStructure natLangStrStructure = mock(NaturalLanguageStringStructure.class);
    when(natLangStrStructure.getValue()).thenReturn(TEST_DESTINATION_NAME);
    when(monVehJourney.getDestinationName()).thenReturn(natLangStrStructure);
    MonitoredCallStructure monCall = mock(MonitoredCallStructure.class);
    ExtensionsStructure extensions = mock(ExtensionsStructure.class);
    SiriExtensionWrapper siriExtensionWrapper = mock(SiriExtensionWrapper.class);
    SiriDistanceExtension distances = mock(SiriDistanceExtension.class);
    when(distances.getPresentableDistance()).thenReturn(TEST_PRESENTABLE_DISTANCE);
    when(siriExtensionWrapper.getDistances()).thenReturn(distances);
    when(extensions.getAny()).thenReturn(siriExtensionWrapper);
    when(monCall.getExtensions()).thenReturn(extensions);
    when(monVehJourney.getMonitoredCall()).thenReturn(monCall);
    when(_realtimeService.getMonitoredStopVisitsForStop(eq(TEST_STOP_ID), eq(0), anyLong())).thenReturn(monitoredStopVisits);
    when(_transitDataService.getStopsForRoute(anyString())).thenReturn(stopsForRouteBean);
    when(_realtimeService.getServiceAlertsForRouteAndDirection(ROUTE_ID, TEST_STOP_ID)).thenReturn(serviceAlerts);
    SearchResultFactoryImpl srf = new SearchResultFactoryImpl(_transitDataService, _realtimeService, _configurationService);
    Set<RouteBean> routeFilter = new HashSet<RouteBean>();
    StopResult result = (StopResult) srf.getStopResult(stopBean, routeFilter);
    return result;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri.NaturalLanguageStringStructure) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matchers.anyString(org.mockito.Matchers.anyString) ExtensionsStructure(uk.org.siri.siri.ExtensionsStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) SiriDistanceExtension(org.onebusaway.transit_data_federation.siri.SiriDistanceExtension) MonitoredCallStructure(uk.org.siri.siri.MonitoredCallStructure) HashSet(java.util.HashSet) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) LineRefStructure(uk.org.siri.siri.LineRefStructure) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) Date(java.util.Date) MonitoredVehicleJourneyStructure(uk.org.siri.siri.MonitoredVehicleJourneyStructure) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) DirectionRefStructure(uk.org.siri.siri.DirectionRefStructure) StopResult(org.onebusaway.enterprise.webapp.actions.m.model.StopResult)

Example 23 with RouteBean

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

the class RouteListServiceImpl method getRoutes.

@Override
public List<RouteBean> getRoutes() {
    List<RouteBean> allRoutes = new ArrayList<RouteBean>();
    List<AgencyWithCoverageBean> agencies = _transitDataService.getAgenciesWithCoverage();
    for (AgencyWithCoverageBean agency : agencies) {
        allRoutes.addAll(_transitDataService.getRoutesForAgencyId(agency.getAgency().getId()).getList());
    }
    Collections.sort(allRoutes, (getShowAgencyNames() ? new AgencyAndRouteComparator() : new RouteComparator()));
    return allRoutes;
}
Also used : AgencyAndRouteComparator(org.onebusaway.presentation.impl.AgencyAndRouteComparator) RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ArrayList(java.util.ArrayList) AgencyAndRouteComparator(org.onebusaway.presentation.impl.AgencyAndRouteComparator) RouteComparator(org.onebusaway.presentation.impl.RouteComparator)

Example 24 with RouteBean

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

the class SearchServiceImpl method findRoutesStoppingNearPoint.

@Override
public SearchResultCollection findRoutesStoppingNearPoint(Double latitude, Double longitude, SearchResultFactory resultFactory) {
    CoordinateBounds bounds = SphericalGeometryLibrary.bounds(latitude, longitude, DISTANCE_TO_ROUTES);
    SearchResultCollection results = new SearchResultCollection();
    SearchQueryBean queryBean = new SearchQueryBean();
    queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
    queryBean.setBounds(bounds);
    queryBean.setMaxCount(100);
    RoutesBean routes = null;
    try {
        routes = _transitDataService.getRoutes(queryBean);
    } catch (OutOfServiceAreaServiceException e) {
        return results;
    }
    Collections.sort(routes.getRoutes(), new RouteDistanceFromPointComparator(latitude, longitude));
    for (RouteBean route : routes.getRoutes()) {
        SearchResult result = resultFactory.getRouteResult(route);
        results.addMatch(result);
        if (results.getMatches().size() > MAX_ROUTES) {
            break;
        }
    }
    return results;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) SearchResultCollection(org.onebusaway.presentation.model.SearchResultCollection) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) SearchResult(org.onebusaway.presentation.model.SearchResult) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 25 with RouteBean

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

the class SearchServiceImpl method tryAsRoutes.

private void tryAsRoutes(SearchResultCollection results, String routeQueryMixedCase, SearchResultFactory resultFactory) {
    String routeQuery = new String(routeQueryMixedCase);
    if (routeQuery == null || StringUtils.isEmpty(routeQuery)) {
        return;
    }
    routeQuery = routeQuery.toUpperCase().trim();
    if (routeQuery.length() < 1) {
        return;
    }
    // try to parse routeQuery into separate routes
    List<String> routeTokens = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(routeQuery, " ", true);
    while (tokenizer.hasMoreTokens()) {
        String routeToken = tokenizer.nextToken().trim();
        if (!StringUtils.isEmpty(routeToken)) {
            routeTokens.add(routeToken);
        }
    }
    // or a short name of route (ex: 92)
    for (String route : routeTokens) {
        if (_routeIdToRouteBeanMap.get(route) != null) {
            RouteBean routeBean = _routeIdToRouteBeanMap.get(route);
            results.addMatch(resultFactory.getRouteResult(routeBean));
        }
        if (_routeShortNameToRouteBeanMap.get(route) != null) {
            for (RouteBean routeBean : _routeShortNameToRouteBeanMap.get(route)) {
                results.addMatch(resultFactory.getRouteResult(routeBean));
            }
        }
    }
    return;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList)

Aggregations

RouteBean (org.onebusaway.transit_data.model.RouteBean)63 ArrayList (java.util.ArrayList)35 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)24 StopBean (org.onebusaway.transit_data.model.StopBean)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 TripBean (org.onebusaway.transit_data.model.trips.TripBean)14 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)12 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)12 List (java.util.List)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 NameBean (org.onebusaway.transit_data.model.NameBean)7 Date (java.util.Date)6 Test (org.junit.Test)6 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)6 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)6 IOException (java.io.IOException)5 Matchers.anyString (org.mockito.Matchers.anyString)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5