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;
}
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;
}
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;
}
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;
}
}
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;
}
Aggregations