use of org.onebusaway.transit_data.model.StopGroupingBean 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.StopGroupingBean 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.StopGroupingBean in project onebusaway-application-modules by camsys.
the class StopSelectionServiceImpl method getStopsForRouteAsStopSelectionTree.
/**
**
* Private Methods
***
*/
private StopSelectionTreeBean getStopsForRouteAsStopSelectionTree(StopsForRouteBean stopsForRoute) {
StopSelectionTreeBean tree = new StopSelectionTreeBean();
StopGroupingBean byDirection = getGroupingByType(stopsForRoute, TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
Map<String, StopBean> stopsById = getStopsById(stopsForRoute);
if (byDirection != null) {
groupByDirection(tree, stopsForRoute, byDirection, stopsById);
} else {
groupByStop(tree, stopsForRoute.getStops());
}
return tree;
}
use of org.onebusaway.transit_data.model.StopGroupingBean 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);
}
use of org.onebusaway.transit_data.model.StopGroupingBean in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImpl method getStopResult.
@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
List<RouteAtStop> routesAtStop = new ArrayList<RouteAtStop>();
for (RouteBean routeBean : stopBean.getRoutes()) {
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;
List<String> polylines = new ArrayList<String>();
for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
polylines.add(polyline.getPoints());
}
Boolean hasUpcomingScheduledService = null;
// We do this to prevent checking if there is service in a direction that does not even serve this stop.
if (stopGroupBean.getStopIds().contains(stopBean.getId())) {
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"
Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForStopAndRoute(stopBean.getId(), routeBean.getId(), SystemTime.currentTimeMillis());
if (routeHasVehiclesInService) {
hasUpcomingScheduledService = true;
}
}
directions.add(new RouteDirection(stopGroupBean, polylines, null, hasUpcomingScheduledService));
}
}
RouteAtStop routeAtStop = new RouteAtStop(routeBean, directions);
routesAtStop.add(routeAtStop);
}
return new StopResult(stopBean, routesAtStop);
}
Aggregations