use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImplTest method testGetRouteForId.
@Test
public void testGetRouteForId() {
AgencyAndId routeId = new AgencyAndId("1", "route");
RouteCollectionNarrative.Builder routeBuilder = RouteCollectionNarrative.builder();
routeBuilder.setColor("blue");
routeBuilder.setDescription("route desc");
routeBuilder.setLongName("route long name");
routeBuilder.setShortName("route short name");
routeBuilder.setTextColor("red");
routeBuilder.setType(3);
routeBuilder.setUrl("http://wwww.route.com");
RouteCollectionNarrative route = routeBuilder.create();
AgencyBean agency = new AgencyBean();
Mockito.when(_agencyBeanService.getAgencyForId("1")).thenReturn(agency);
Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(route);
RouteBean bean = _service.getRouteForId(routeId);
assertEquals(route.getColor(), bean.getColor());
assertEquals(route.getDescription(), bean.getDescription());
assertEquals(AgencyAndIdLibrary.convertToString(routeId), bean.getId());
assertEquals(route.getLongName(), bean.getLongName());
assertEquals(route.getShortName(), bean.getShortName());
assertEquals(route.getTextColor(), bean.getTextColor());
assertEquals(route.getType(), bean.getType());
assertEquals(route.getUrl(), bean.getUrl());
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class VehicleMonitoringActionTest method testExecuteByRouteNoActivity.
@Test
public void testExecuteByRouteNoActivity() throws Exception {
when(request.getParameter(eq("LineRef"))).thenReturn("40_100479");
when(request.getParameter(eq("OperatorRef"))).thenReturn("1");
PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {
@Override
public void write(int b) throws IOException {
// Do nothing
}
});
when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
List<VehicleActivityStructure> vehicleActivities = new ArrayList<VehicleActivityStructure>();
when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities);
ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1");
when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean);
RouteBean routeBean = RouteBean.builder().create();
when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean);
ListBean<ServiceAlertBean> serviceAlertListBean = new ListBean<ServiceAlertBean>();
List<ServiceAlertBean> list = new ArrayList<ServiceAlertBean>();
list.add(serviceAlertBean);
serviceAlertListBean.setList(list);
when(transitDataService.getServiceAlerts(any(SituationQueryBean.class))).thenReturn(serviceAlertListBean);
SiriXmlSerializer serializer = new SiriXmlSerializer();
when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
action.setServletRequest(request);
action.setServletResponse(servletResponse);
action.index();
String monitoring = action.getVehicleMonitoring();
assertTrue("Result XML does not match expected", monitoring.matches("(?s).*<SituationExchangeDelivery><Situations><PtSituationElement><SituationNumber>1_1</SituationNumber><Summary xml:lang=\"EN\">summary</Summary><Description xml:lang=\"EN\">description</Description><Affects><VehicleJourneys><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney></VehicleJourneys></Affects></PtSituationElement></Situations></SituationExchangeDelivery></ServiceDelivery></Siri>.*"));
}
use of org.onebusaway.transit_data.model.RouteBean 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);
}
use of org.onebusaway.transit_data.model.RouteBean 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;
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesPresentaion method getTripHeadsign.
public String getTripHeadsign(ArrivalAndDepartureBean bean) {
if (bean.getTripHeadsign() != null)
return bean.getTripHeadsign();
TripBean trip = bean.getTrip();
if (trip.getTripHeadsign() != null)
return trip.getTripHeadsign();
RouteBean route = trip.getRoute();
return RoutePresenter.getDescriptionForRoute(route);
}
Aggregations