Search in sources :

Example 21 with StopBean

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

the class StopsWithinBoundsAction method execute.

@Override
public String execute() {
    if (_bounds == null) {
        return SUCCESS;
    }
    SearchQueryBean queryBean = new SearchQueryBean();
    queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
    queryBean.setBounds(_bounds);
    queryBean.setMaxCount(200);
    StopsBean stops = null;
    try {
        stops = _transitDataService.getStops(queryBean);
    } catch (OutOfServiceAreaServiceException e) {
        _log.error(" invalid results: ", e);
        return SUCCESS;
    }
    for (StopBean stop : stops.getStops()) {
        String agencyId = AgencyAndIdLibrary.convertFromString(stop.getId()).getAgencyId();
        if (_transitDataService.stopHasRevenueService(agencyId, stop.getId())) {
            _stops.add(new StopOnRoute(stop));
        }
    }
    return SUCCESS;
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 22 with StopBean

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

the class StopsForRouteAction method execute.

@Override
@Actions({ @Action(value = "/where/iphone/stops-for-route") })
public String execute() throws ServiceException {
    if (_id == null || _id.length() == 0)
        return INPUT;
    _route = _transitDataService.getRouteForId(_id);
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(_id);
    Map<String, StopGroupingBean> groupingsByType = MappingLibrary.mapToValue(stopsForRoute.getStopGroupings(), "type", String.class);
    StopGroupingBean byDirection = groupingsByType.get(TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
    if (_groupIndex == -1) {
        if (byDirection != null) {
            for (StopGroupBean group : byDirection.getStopGroups()) _directionNames.add(group.getName());
        }
        _stops = stopsForRoute.getStops();
        Collections.sort(_stops, _stopNameComparator);
    } else {
        if (byDirection == null)
            return INPUT;
        List<StopGroupBean> groups = byDirection.getStopGroups();
        if (_groupIndex < 0 && groups.size() <= _groupIndex)
            return INPUT;
        Map<String, StopBean> stopById = MappingLibrary.mapToValue(stopsForRoute.getStops(), "id", String.class);
        StopGroupBean stopGroup = groups.get(_groupIndex);
        _stops = new ArrayList<StopBean>();
        for (String stopId : stopGroup.getStopIds()) _stops.add(stopById.get(stopId));
    }
    return SUCCESS;
}
Also used : StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopBean(org.onebusaway.transit_data.model.StopBean) Actions(org.apache.struts2.convention.annotation.Actions)

Example 23 with StopBean

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

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

the class NameBasedNotificationStrategyImpl method summarizeStop.

@Override
public String summarizeStop(String stopIdStr) {
    // return the stop name
    try {
        AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(stopIdStr);
        StopBean stop = _tds.getStop(routeId.toString());
        if (stop == null || stop.getName() == null)
            return stopIdStr;
        return stop.getName();
    } catch (IllegalStateException ise) {
        // invalid id -- return it as is
        return stopIdStr;
    } catch (NoSuchStopServiceException nsse) {
        // something went wrong
        _log.error("couldn't find stop for stopId=|" + stopIdStr + "|");
        return stopIdStr;
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchStopServiceException(org.onebusaway.exceptions.NoSuchStopServiceException) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 25 with StopBean

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

the class BeanFactoryV2 method getStopWithArrivalAndDepartures.

public StopWithArrivalsAndDeparturesV2Bean getStopWithArrivalAndDepartures(StopWithArrivalsAndDeparturesBean sad) {
    StopWithArrivalsAndDeparturesV2Bean bean = new StopWithArrivalsAndDeparturesV2Bean();
    bean.setStopId(sad.getStop().getId());
    addToReferences(sad.getStop());
    List<ArrivalAndDepartureV2Bean> ads = new ArrayList<ArrivalAndDepartureV2Bean>();
    for (ArrivalAndDepartureBean ad : sad.getArrivalsAndDepartures()) ads.add(getArrivalAndDeparture(ad));
    bean.setArrivalsAndDepartures(ads);
    List<String> nearbyStopIds = new ArrayList<String>();
    for (StopBean nearbyStop : sad.getNearbyStops()) {
        nearbyStopIds.add(nearbyStop.getId());
        addToReferences(nearbyStop);
    }
    bean.setNearbyStopIds(nearbyStopIds);
    List<ServiceAlertBean> situations = sad.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            addToReferences(situation);
            situationIds.add(situation.getId());
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

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