Search in sources :

Example 36 with RouteBean

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());
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) Test(org.junit.Test)

Example 37 with RouteBean

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>.*"));
}
Also used : OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) RouteBean(org.onebusaway.transit_data.model.RouteBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) SiriXmlSerializer(org.onebusaway.transit_data_federation.siri.SiriXmlSerializer) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 38 with RouteBean

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);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteAtStop(org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) StopResult(org.onebusaway.enterprise.webapp.actions.api.model.StopResult)

Example 39 with RouteBean

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;
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteAtStop(org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) StopResult(org.onebusaway.enterprise.webapp.actions.api.model.StopResult)

Example 40 with RouteBean

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);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean)

Aggregations

RouteBean (org.onebusaway.transit_data.model.RouteBean)63 ArrayList (java.util.ArrayList)35 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)24 StopBean (org.onebusaway.transit_data.model.StopBean)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 TripBean (org.onebusaway.transit_data.model.trips.TripBean)14 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)12 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)12 List (java.util.List)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 NameBean (org.onebusaway.transit_data.model.NameBean)7 Date (java.util.Date)6 Test (org.junit.Test)6 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)6 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)6 IOException (java.io.IOException)5 Matchers.anyString (org.mockito.Matchers.anyString)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5