use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.
the class StopsOnRouteForDirectionAction method execute.
@Override
public String execute() {
if (_routeId == null) {
return SUCCESS;
}
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(_routeId);
// create stop ID->stop bean map
Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
for (StopBean stopBean : stopsForRoute.getStops()) {
stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
}
// break up stops into destinations
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") || !stopGroupBean.getId().equals(_directionId))
continue;
if (!stopGroupBean.getStopIds().isEmpty()) {
for (String stopId : stopGroupBean.getStopIds()) {
String agencyId = AgencyAndIdLibrary.convertFromString(_routeId).getAgencyId();
if (_transitDataService.stopHasRevenueServiceOnRoute(agencyId, stopId, stopsForRoute.getRoute().getId(), stopGroupBean.getId())) {
_stops.add(new StopOnRoute(stopIdToStopBeanMap.get(stopId)));
}
}
}
}
}
return SUCCESS;
}
use of org.onebusaway.transit_data.model.StopsForRouteBean 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.StopsForRouteBean 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.StopsForRouteBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getStopsForRoute.
public StopsForRouteV2Bean getStopsForRoute(StopsForRouteBean stopsForRoute, boolean includePolylines) {
StopsForRouteV2Bean bean = new StopsForRouteV2Bean();
RouteBean route = stopsForRoute.getRoute();
if (route != null) {
addToReferences(route);
bean.setRouteId(route.getId());
}
List<String> stopIds = new ArrayList<String>();
for (StopBean stop : stopsForRoute.getStops()) {
stopIds.add(stop.getId());
addToReferences(stop);
}
bean.setStopIds(stopIds);
bean.setStopGroupings(stopsForRoute.getStopGroupings());
if (!includePolylines) {
for (StopGroupingBean grouping : stopsForRoute.getStopGroupings()) {
for (StopGroupBean group : grouping.getStopGroups()) group.setPolylines(null);
}
}
if (includePolylines)
bean.setPolylines(stopsForRoute.getPolylines());
return bean;
}
use of org.onebusaway.transit_data.model.StopsForRouteBean 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);
}
Aggregations