Search in sources :

Example 41 with StopBean

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

the class RouteBeanServiceImplTest method testGetStopsForRoute.

@Test
public void testGetStopsForRoute() {
    AgencyAndId routeId = new AgencyAndId("1", "route");
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("1", "raw_route"));
    List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(routeId);
    routeCollection.setChildren(routes);
    route.setParent(routeCollection);
    Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
    RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
    Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
    StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sidA");
    TripEntryImpl tripB = trip("tripB", "sidA");
    tripA.setRoute(route);
    tripA.setDirectionId("0");
    tripB.setRoute(route);
    tripB.setDirectionId("1");
    route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
    TripNarrative.Builder tnA = TripNarrative.builder();
    tnA.setTripHeadsign("Destination A");
    Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
    TripNarrative.Builder tnB = TripNarrative.builder();
    tnB.setTripHeadsign("Destination B");
    Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
    stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
    stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
    stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
    stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
    stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
    linkBlockTrips(blockA, tripA, tripB);
    List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
    Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
    StopBean stopBeanA = getStopBean(stopA);
    StopBean stopBeanB = getStopBean(stopB);
    StopBean stopBeanC = getStopBean(stopC);
    List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
    Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
    Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
    shapeIds.add(shapeId);
    tripA.setShapeId(shapeId);
    EncodedPolylineBean polyline = new EncodedPolylineBean();
    Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
    // Setup complete
    StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
    List<StopBean> stops = stopsForRoute.getStops();
    assertEquals(3, stops.size());
    assertSame(stopBeanA, stops.get(0));
    assertSame(stopBeanB, stops.get(1));
    assertSame(stopBeanC, stops.get(2));
    List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
    assertEquals(1, polylines.size());
    assertSame(polyline, polylines.get(0));
    List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
    assertEquals(1, groupings.size());
    StopGroupingBean grouping = groupings.get(0);
    assertEquals("direction", grouping.getType());
    List<StopGroupBean> groups = grouping.getStopGroups();
    assertEquals(2, groups.size());
    StopGroupBean groupA = groups.get(0);
    StopGroupBean groupB = groups.get(1);
    NameBean nameA = groupA.getName();
    assertEquals("destination", nameA.getType());
    assertEquals("Destination A", nameA.getName());
    List<String> stopIdsA = groupA.getStopIds();
    assertEquals(3, stopIdsA.size());
    assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
    NameBean nameB = groupB.getName();
    assertEquals("destination", nameB.getType());
    assertEquals("Destination B", nameB.getName());
    List<String> stopIdsB = groupB.getStopIds();
    assertEquals(2, stopIdsB.size());
    assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) HashSet(java.util.HashSet) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) NameBean(org.onebusaway.transit_data.model.NameBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Test(org.junit.Test)

Example 42 with StopBean

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

Example 43 with StopBean

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

the class SearchServiceImpl method tryAsStopName.

// use LUCENE index to search on stop name
private void tryAsStopName(SearchResultCollection results, String q, SearchResultFactory resultFactory) {
    StopsBean beans = _transitDataService.getStopsByName(q);
    int count = 0;
    if (beans == null || beans.getStops() == null)
        return;
    for (StopBean stopBean : beans.getStops()) {
        String agencyId = AgencyAndIdLibrary.convertFromString(stopBean.getId()).getAgencyId();
        // filter out stops not in service
        if (_transitDataService.stopHasRevenueService(agencyId, stopBean.getId())) {
            // this is a fuzzy match so just a suggestion
            results.addSuggestion(resultFactory.getStopResult(stopBean, results.getRouteFilter()));
            count++;
        }
        if (count > MAX_STOPS) {
            break;
        }
    }
    return;
}
Also used : StopBean(org.onebusaway.transit_data.model.StopBean) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 44 with StopBean

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

the class SearchServiceImpl method tryAsStop.

private void tryAsStop(SearchResultCollection results, String stopQuery, SearchResultFactory resultFactory) {
    if (stopQuery == null || StringUtils.isEmpty(stopQuery)) {
        return;
    }
    stopQuery = stopQuery.trim();
    // try to find a stop ID for all known agencies
    List<StopBean> matches = stopsForId(stopQuery);
    if (// support multiple agency stop matches
    matches.size() > 0)
        for (StopBean stopBean : matches) {
            String agencyId = AgencyAndIdLibrary.convertFromString(stopBean.getId()).getAgencyId();
            if (_transitDataService.stopHasRevenueService(agencyId, stopBean.getId())) {
                results.addMatch(resultFactory.getStopResult(stopBean, results.getRouteFilter()));
            }
        }
    else {
        for (StopBean match : matches) {
            String agencyId = AgencyAndIdLibrary.convertFromString(match.getId()).getAgencyId();
            if (_transitDataService.stopHasRevenueService(agencyId, match.getId())) {
                results.addSuggestion(resultFactory.getStopResult(match, results.getRouteFilter()));
            }
        }
    }
}
Also used : StopBean(org.onebusaway.transit_data.model.StopBean)

Example 45 with StopBean

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

the class SearchServiceImpl method refreshCachesIfNecessary.

// we keep an internal cache of route short/long names because if we moved
// this into the
// transit data federation, we'd also have to move the model factory and
// some other agency-specific
// conventions, which wouldn't be pretty.
// 
// long-term FIXME: figure out how to split apart the model creation a bit
// more from the actual
// search process.
public void refreshCachesIfNecessary() {
    String currentBundleId = _transitDataService.getActiveBundleId();
    if ((_bundleIdForCaches != null && _bundleIdForCaches.equals(currentBundleId)) || currentBundleId == null) {
        return;
    }
    _routeShortNameToRouteBeanMap.clear();
    _routeIdToRouteBeanMap.clear();
    _routeLongNameToRouteBeanMap.clear();
    _stopCodeToStopIdMap.clear();
    for (AgencyWithCoverageBean agency : _transitDataService.getAgenciesWithCoverage()) {
        for (RouteBean routeBean : _transitDataService.getRoutesForAgencyId(agency.getAgency().getId()).getList()) {
            if (routeBean.getShortName() != null)
                if (_routeShortNameToRouteBeanMap.containsKey(routeBean.getShortName().toUpperCase())) {
                    _routeShortNameToRouteBeanMap.get(routeBean.getShortName().toUpperCase()).add(routeBean);
                } else {
                    _routeShortNameToRouteBeanMap.put(routeBean.getShortName().toUpperCase(), new ArrayList<RouteBean>(Arrays.asList(routeBean)));
                }
            if (routeBean.getLongName() != null)
                if (_routeLongNameToRouteBeanMap.containsKey(routeBean.getLongName())) {
                    _routeLongNameToRouteBeanMap.get(routeBean.getLongName()).add(routeBean);
                } else {
                    _routeLongNameToRouteBeanMap.put(routeBean.getLongName(), new ArrayList<RouteBean>(Arrays.asList(routeBean)));
                }
            _routeIdToRouteBeanMap.put(routeBean.getId(), routeBean);
        }
        List<StopBean> stopsList = _transitDataService.getAllRevenueStops(agency);
        for (StopBean stop : stopsList) {
            _stopCodeToStopIdMap.put(agency.getAgency().getId() + "_" + stop.getCode().toUpperCase(), stop.getId());
        }
    }
    _bundleIdForCaches = currentBundleId;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean)

Aggregations

StopBean (org.onebusaway.transit_data.model.StopBean)69 ArrayList (java.util.ArrayList)34 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 RouteBean (org.onebusaway.transit_data.model.RouteBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)17 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)15 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)15 HashMap (java.util.HashMap)12 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)9 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)9 NameBean (org.onebusaway.transit_data.model.NameBean)9 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)8 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashSet (java.util.HashSet)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 List (java.util.List)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 Test (org.junit.Test)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)5