Search in sources :

Example 6 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class VehicleMonitoringAction method index.

// @Override
public String index() {
    processGoogleAnalytics();
    long currentTimestamp = getTime();
    _realtimeService.setTime(currentTimestamp);
    String directionId = _request.getParameter("DirectionRef");
    String tripId = _request.getParameter("TripId");
    boolean showRawLocation = Boolean.valueOf(_request.getParameter("ShowRawLocation"));
    // We need to support the user providing no agency id which means 'all agencies'.
    // So, this array will hold a single agency if the user provides it or all
    // agencies if the user provides none. We'll iterate over them later while
    // querying for vehicles and routes
    List<String> agencyIds = new ArrayList<String>();
    String agencyId = _request.getParameter("OperatorRef");
    if (agencyId != null) {
        agencyIds.add(agencyId);
    } else {
        Map<String, List<CoordinateBounds>> agencies = _transitDataService.getAgencyIdsWithCoverageArea();
        agencyIds.addAll(agencies.keySet());
    }
    List<AgencyAndId> vehicleIds = new ArrayList<AgencyAndId>();
    if (_request.getParameter("VehicleRef") != null) {
        try {
            // If the user included an agency id as part of the vehicle id, ignore any OperatorRef arg
            // or lack of OperatorRef arg and just use the included one.
            AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(_request.getParameter("VehicleRef"));
            vehicleIds.add(vehicleId);
        } catch (Exception e) {
            // The user didn't provide an agency id in the VehicleRef, so use our list of operator refs
            for (String agency : agencyIds) {
                AgencyAndId vehicleId = new AgencyAndId(agency, _request.getParameter("VehicleRef"));
                vehicleIds.add(vehicleId);
            }
        }
    }
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    String routeIdErrorString = "";
    if (_request.getParameter("LineRef") != null) {
        try {
            // Same as above for vehicle id
            AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(_request.getParameter("LineRef"));
            if (isValidRoute(routeId)) {
                routeIds.add(routeId);
            } else {
                routeIdErrorString += "No such route: " + routeId.toString() + ".";
            }
        } catch (Exception e) {
            // Same as above for vehicle id
            for (String agency : agencyIds) {
                AgencyAndId routeId = new AgencyAndId(agency, _request.getParameter("LineRef"));
                if (isValidRoute(routeId)) {
                    routeIds.add(routeId);
                } else {
                    routeIdErrorString += "No such route: " + routeId.toString() + ". ";
                }
            }
        }
    }
    String detailLevel = _request.getParameter("VehicleMonitoringDetailLevel");
    int maximumOnwardCalls = 0;
    if (detailLevel != null && detailLevel.equals("calls")) {
        maximumOnwardCalls = Integer.MAX_VALUE;
        try {
            maximumOnwardCalls = Integer.parseInt(_request.getParameter("MaximumNumberOfCallsOnwards"));
        } catch (NumberFormatException e) {
            maximumOnwardCalls = Integer.MAX_VALUE;
        }
    }
    // *** CASE 1: single vehicle, ignore any other filters
    if (vehicleIds.size() > 0) {
        List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
        for (AgencyAndId vehicleId : vehicleIds) {
            VehicleActivityStructure activity = _realtimeService.getVehicleActivityForVehicle(vehicleId.toString(), maximumOnwardCalls, currentTimestamp, tripId);
            if (activity != null) {
                activities.add(activity);
            }
        }
        // No vehicle id validation, so we pass null for error
        _response = generateSiriResponse(activities, null, null, currentTimestamp);
    // *** CASE 2: by route, using direction id, if provided
    } else if (_request.getParameter("LineRef") != null) {
        List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
        for (AgencyAndId routeId : routeIds) {
            List<VehicleActivityStructure> activitiesForRoute = _realtimeService.getVehicleActivityForRoute(routeId.toString(), directionId, maximumOnwardCalls, currentTimestamp, showRawLocation);
            if (activitiesForRoute != null) {
                activities.addAll(activitiesForRoute);
            }
        }
        if (vehicleIds.size() > 0) {
            List<VehicleActivityStructure> filteredActivities = new ArrayList<VehicleActivityStructure>();
            for (VehicleActivityStructure activity : activities) {
                MonitoredVehicleJourneyStructure journey = activity.getMonitoredVehicleJourney();
                AgencyAndId thisVehicleId = AgencyAndIdLibrary.convertFromString(journey.getVehicleRef().getValue());
                // user filtering
                if (!vehicleIds.contains(thisVehicleId))
                    continue;
                filteredActivities.add(activity);
            }
            activities = filteredActivities;
        }
        Exception error = null;
        if (_request.getParameter("LineRef") != null && routeIds.size() == 0) {
            error = new Exception(routeIdErrorString.trim());
        }
        _response = generateSiriResponse(activities, routeIds, error, currentTimestamp);
    // *** CASE 3: all vehicles
    } else {
        try {
            int hashKey = _cacheService.hash(maximumOnwardCalls, agencyIds, _type);
            List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
            if (!_cacheService.containsKey(hashKey)) {
                for (String agency : agencyIds) {
                    ListBean<VehicleStatusBean> vehicles = _transitDataService.getAllVehiclesForAgency(agency, currentTimestamp);
                    for (VehicleStatusBean v : vehicles.getList()) {
                        VehicleActivityStructure activity = _realtimeService.getVehicleActivityForVehicle(v.getVehicleId(), maximumOnwardCalls, currentTimestamp, tripId);
                        if (activity != null) {
                            activities.add(activity);
                        }
                    }
                }
                // There is no input (route id) to validate, so pass null error
                _response = generateSiriResponse(activities, null, null, currentTimestamp);
                _cacheService.store(hashKey, getVehicleMonitoring());
            } else {
                _cachedResponse = _cacheService.retrieve(hashKey);
            }
        } catch (Exception e) {
            _log.error("vm all broke:", e);
            throw new RuntimeException(e);
        }
    }
    try {
        this._servletResponse.getWriter().write(getVehicleMonitoring());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) IOException(java.io.IOException) IOException(java.io.IOException) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) MonitoredVehicleJourneyStructure(uk.org.siri.siri.MonitoredVehicleJourneyStructure) ArrayList(java.util.ArrayList) List(java.util.List) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure)

Example 7 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class VehicleMonitoringV2Action method index.

public DefaultHttpHeaders index() throws IOException {
    long currentTimestamp = getTime();
    processGoogleAnalytics();
    // _monitoringActionSupport.setupGoogleAnalytics(_request, _configurationService);
    _realtimeService.setTime(currentTimestamp);
    String detailLevelParam = _request.getParameter(VEHICLE_MONITORING_DETAIL_LEVEL);
    // get the detail level parameter or set it to default if not specified
    DetailLevel detailLevel;
    if (DetailLevel.contains(detailLevelParam)) {
        detailLevel = DetailLevel.valueOf(detailLevelParam.toUpperCase());
    } else {
        detailLevel = DetailLevel.NORMAL;
    }
    // User Parameters
    String lineRef = _request.getParameter(LINE_REF);
    String vehicleRef = _request.getParameter(VEHICLE_REF);
    String directionId = _request.getParameter(DIRECTION_REF);
    String agencyId = _request.getParameter(OPERATOR_REF);
    String maxOnwardCallsParam = _request.getParameter(MAX_ONWARD_CALLS);
    String maxStopVisitsParam = _request.getParameter(MAX_STOP_VISITS);
    String minStopVisitsParam = _request.getParameter(MIN_STOP_VISITS);
    // Error Strings
    String routeIdsErrorString = "";
    /*
     * We need to support the user providing no agency id which means 'all agencies'.
    So, this array will hold a single agency if the user provides it or all
    agencies if the user provides none. We'll iterate over them later while 
    querying for vehicles and routes
    */
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    List<String> agencyIds = processAgencyIds(agencyId);
    List<AgencyAndId> vehicleIds = processVehicleIds(vehicleRef, agencyIds);
    routeIdsErrorString = processRouteIds(lineRef, routeIds, agencyIds);
    int maximumOnwardCalls = 0;
    if (detailLevel.equals(DetailLevel.CALLS)) {
        maximumOnwardCalls = SiriSupportV2.convertToNumeric(maxOnwardCallsParam, Integer.MAX_VALUE);
    }
    String gaLabel = null;
    // *** CASE 1: single vehicle, ignore any other filters
    if (vehicleIds.size() > 0) {
        gaLabel = vehicleRef;
        List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
        try {
            for (AgencyAndId vehicleId : vehicleIds) {
                VehicleActivityStructure activity = _realtimeService.getVehicleActivityForVehicle(vehicleId.toString(), maximumOnwardCalls, detailLevel, currentTimestamp);
                if (activity != null) {
                    activities.add(activity);
                }
            }
        } catch (Exception e) {
            _log.info(e.getMessage(), e);
        }
        // No vehicle id validation, so we pass null for error
        _response = generateSiriResponse(activities, null, null, currentTimestamp);
    // *** CASE 2: by route, using direction id, if provided
    } else if (lineRef != null) {
        gaLabel = lineRef;
        List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
        for (AgencyAndId routeId : routeIds) {
            List<VehicleActivityStructure> activitiesForRoute = _realtimeService.getVehicleActivityForRoute(routeId.toString(), directionId, maximumOnwardCalls, detailLevel, currentTimestamp);
            if (activitiesForRoute != null) {
                activities.addAll(activitiesForRoute);
            }
        }
        if (vehicleIds.size() > 0) {
            List<VehicleActivityStructure> filteredActivities = new ArrayList<VehicleActivityStructure>();
            for (VehicleActivityStructure activity : activities) {
                MonitoredVehicleJourneyStructure journey = activity.getMonitoredVehicleJourney();
                AgencyAndId thisVehicleId = AgencyAndIdLibrary.convertFromString(journey.getVehicleRef().getValue());
                // user filtering
                if (!vehicleIds.contains(thisVehicleId))
                    continue;
                filteredActivities.add(activity);
            }
            activities = filteredActivities;
        }
        Exception error = null;
        if (lineRef != null && routeIds.size() == 0) {
            error = new Exception(routeIdsErrorString.trim());
        }
        _response = generateSiriResponse(activities, routeIds, error, currentTimestamp);
    // *** CASE 3: all vehicles
    } else {
        try {
            gaLabel = "All Vehicles";
            // int hashKey = _siriCacheService.hash(maximumOnwardCalls, agencyIds, _type);
            List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
            // if (!_siriCacheService.containsKey(hashKey)) {
            for (String agency : agencyIds) {
                ListBean<VehicleStatusBean> vehicles = _transitDataService.getAllVehiclesForAgency(agency, currentTimestamp);
                for (VehicleStatusBean v : vehicles.getList()) {
                    VehicleActivityStructure activity = _realtimeService.getVehicleActivityForVehicle(v.getVehicleId(), maximumOnwardCalls, detailLevel, currentTimestamp);
                    if (activity != null) {
                        activities.add(activity);
                    }
                }
            }
            // There is no input (route id) to validate, so pass null error
            _response = generateSiriResponse(activities, null, null, currentTimestamp);
        // _siriCacheService.store(hashKey, getVehicleMonitoring());
        // } else {
        // _cachedResponse = _siriCacheService.retrieve(hashKey);
        // }
        } catch (Exception e) {
            _log.error("vm all broke:", e);
            throw new RuntimeException(e);
        }
    }
    try {
        this._servletResponse.getWriter().write(getVehicleMonitoring());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) IOException(java.io.IOException) IOException(java.io.IOException) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) MonitoredVehicleJourneyStructure(uk.org.siri.siri_2.MonitoredVehicleJourneyStructure) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) ArrayList(java.util.ArrayList) List(java.util.List) VehicleActivityStructure(uk.org.siri.siri_2.VehicleActivityStructure)

Example 8 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class VehiclePositionsForAgencyActionTest method test.

@Test
public void test() {
    long now = System.currentTimeMillis();
    List<VehicleStatusBean> vehicles = new ArrayList<VehicleStatusBean>();
    RouteBean.Builder routeBuilder = RouteBean.builder();
    routeBuilder.setId("1_r1");
    RouteBean route = routeBuilder.create();
    {
        VehicleStatusBean vehicle = new VehicleStatusBean();
        vehicles.add(vehicle);
        vehicle.setLastUpdateTime(1234 * 1000);
        vehicle.setVehicleId("1_v1");
        TripStatusBean tripStatus = new TripStatusBean();
        vehicle.setTripStatus(tripStatus);
        TripBean trip = new TripBean();
        trip.setId("1_t0");
        trip.setRoute(route);
        tripStatus.setActiveTrip(trip);
        vehicle.setLocation(new CoordinatePoint(47.0, -122.0));
    }
    {
        VehicleStatusBean vehicle = new VehicleStatusBean();
        vehicles.add(vehicle);
        vehicle.setLastUpdateTime(5678 * 1000);
        vehicle.setVehicleId("1_v2");
        TripStatusBean tripStatus = new TripStatusBean();
        vehicle.setTripStatus(tripStatus);
        TripBean trip = new TripBean();
        trip.setId("1_t1");
        trip.setRoute(route);
        tripStatus.setActiveTrip(trip);
        vehicle.setLocation(new CoordinatePoint(47.1, -122.1));
    }
    ListBean<VehicleStatusBean> bean = new ListBean<VehicleStatusBean>();
    bean.setList(vehicles);
    Mockito.when(_service.getAllVehiclesForAgency("1", now)).thenReturn(bean);
    _action.setId("1");
    _action.setTime(new Date(now));
    _action.show();
    ResponseBean model = _action.getModel();
    FeedMessage feed = (FeedMessage) model.getData();
    assertEquals(now / 1000, feed.getHeader().getTimestamp());
    assertEquals(2, feed.getEntityCount());
    {
        FeedEntity entity = feed.getEntity(0);
        assertEquals("1", entity.getId());
        VehiclePosition vehiclePosition = entity.getVehicle();
        assertEquals("t0", vehiclePosition.getTrip().getTripId());
        assertEquals("r1", vehiclePosition.getTrip().getRouteId());
        assertEquals("v1", vehiclePosition.getVehicle().getId());
        assertEquals(1234, vehiclePosition.getTimestamp());
        assertEquals(47.0, vehiclePosition.getPosition().getLatitude(), 0.01);
        assertEquals(-122.0, vehiclePosition.getPosition().getLongitude(), 0.01);
    }
    {
        FeedEntity entity = feed.getEntity(1);
        assertEquals("2", entity.getId());
        VehiclePosition vehiclePosition = entity.getVehicle();
        assertEquals("t1", vehiclePosition.getTrip().getTripId());
        assertEquals("r1", vehiclePosition.getTrip().getRouteId());
        assertEquals("v2", vehiclePosition.getVehicle().getId());
        assertEquals(5678, vehiclePosition.getTimestamp());
        assertEquals(47.1, vehiclePosition.getPosition().getLatitude(), 0.01);
        assertEquals(-122.1, vehiclePosition.getPosition().getLongitude(), 0.01);
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) Date(java.util.Date) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) ResponseBean(org.onebusaway.api.model.ResponseBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) Test(org.junit.Test)

Example 9 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class AlertsForAgencyActionTest method test.

@Test
public void test() {
    long now = System.currentTimeMillis();
    List<ServiceAlertBean> alerts = new ArrayList<ServiceAlertBean>();
    {
        ServiceAlertBean alert = new ServiceAlertBean();
        alerts.add(alert);
        TimeRangeBean range = new TimeRangeBean(1234 * 1000, 5678 * 1000);
        alert.setActiveWindows(Arrays.asList(range));
        SituationAffectsBean affects = new SituationAffectsBean();
        affects.setAgencyId("1");
        affects.setRouteId("1_r0");
        affects.setStopId("1_s0");
        affects.setTripId("1_t0");
        SituationAffectsBean alsoAffects = new SituationAffectsBean();
        alsoAffects.setAgencyId("2");
        alert.setAllAffects(Arrays.asList(affects, alsoAffects));
        alert.setSummaries(Arrays.asList(new NaturalLanguageStringBean("Name", "en"), new NaturalLanguageStringBean("Nombre", "es")));
        alert.setDescriptions(Arrays.asList(new NaturalLanguageStringBean("Description", "en"), new NaturalLanguageStringBean("DescripciĆ³n", "es")));
    }
    {
        ServiceAlertBean alert = new ServiceAlertBean();
        alerts.add(alert);
        TimeRangeBean range = new TimeRangeBean(5678 * 1000, 1234 * 1000);
        alert.setActiveWindows(Arrays.asList(range));
        SituationAffectsBean affects = new SituationAffectsBean();
        affects.setAgencyId("2");
        affects.setRouteId("1_r1");
        affects.setStopId("1_s1");
        affects.setTripId("1_t1");
        alert.setAllAffects(Arrays.asList(affects));
        alert.setSummaries(Arrays.asList(new NaturalLanguageStringBean("Name", "en")));
        alert.setDescriptions(Arrays.asList(new NaturalLanguageStringBean("Description", "en")));
    }
    ListBean<ServiceAlertBean> bean = new ListBean<ServiceAlertBean>();
    bean.setList(alerts);
    Mockito.when(_service.getAllServiceAlertsForAgencyId("1")).thenReturn(bean);
    _action.setId("1");
    _action.setTime(new Date(now));
    _action.show();
    ResponseBean model = _action.getModel();
    FeedMessage feed = (FeedMessage) model.getData();
    assertEquals(now / 1000, feed.getHeader().getTimestamp());
    assertEquals(2, feed.getEntityCount());
    {
        FeedEntity entity = feed.getEntity(0);
        assertEquals("1", entity.getId());
        Alert alert = entity.getAlert();
        assertEquals(1, alert.getActivePeriodCount());
        TimeRange range = alert.getActivePeriod(0);
        assertEquals(1234, range.getStart());
        assertEquals(5678, range.getEnd());
        assertEquals(2, alert.getInformedEntityCount());
        {
            EntitySelector affects = alert.getInformedEntity(0);
            assertEquals("1", affects.getAgencyId());
            assertEquals("r0", affects.getRouteId());
            assertEquals("t0", affects.getTrip().getTripId());
            assertEquals("s0", affects.getStopId());
        }
        {
            EntitySelector affects = alert.getInformedEntity(1);
            assertEquals("2", affects.getAgencyId());
        }
        TranslatedString header = alert.getHeaderText();
        assertEquals(2, header.getTranslationCount());
        {
            Translation translation = header.getTranslation(0);
            assertEquals("Name", translation.getText());
            assertEquals("en", translation.getLanguage());
        }
        {
            Translation translation = header.getTranslation(1);
            assertEquals("Nombre", translation.getText());
            assertEquals("es", translation.getLanguage());
        }
        TranslatedString description = alert.getDescriptionText();
        assertEquals(2, description.getTranslationCount());
        {
            Translation translation = description.getTranslation(0);
            assertEquals("Description", translation.getText());
            assertEquals("en", translation.getLanguage());
        }
        {
            Translation translation = description.getTranslation(1);
            assertEquals("DescripciĆ³n", translation.getText());
            assertEquals("es", translation.getLanguage());
        }
    }
    {
        FeedEntity entity = feed.getEntity(1);
        assertEquals("2", entity.getId());
        Alert alert = entity.getAlert();
        assertEquals(1, alert.getActivePeriodCount());
        TimeRange range = alert.getActivePeriod(0);
        assertEquals(5678, range.getStart());
        assertEquals(1234, range.getEnd());
        assertEquals(1, alert.getInformedEntityCount());
        {
            EntitySelector affects = alert.getInformedEntity(0);
            assertEquals("2", affects.getAgencyId());
            assertEquals("r1", affects.getRouteId());
            assertEquals("t1", affects.getTrip().getTripId());
            assertEquals("s1", affects.getStopId());
        }
    }
}
Also used : TranslatedString(com.google.transit.realtime.GtfsRealtime.TranslatedString) EntitySelector(com.google.transit.realtime.GtfsRealtime.EntitySelector) Translation(com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) Date(java.util.Date) TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) TimeRange(com.google.transit.realtime.GtfsRealtime.TimeRange) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) NaturalLanguageStringBean(org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean) ResponseBean(org.onebusaway.api.model.ResponseBean) Alert(com.google.transit.realtime.GtfsRealtime.Alert) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) Test(org.junit.Test)

Example 10 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class TripUpdatesForAgencyActionTest method test.

@Test
public void test() {
    long now = System.currentTimeMillis();
    List<VehicleStatusBean> vehicles = new ArrayList<VehicleStatusBean>();
    RouteBean.Builder routeBuilder = RouteBean.builder();
    routeBuilder.setId("1_r1");
    RouteBean route = routeBuilder.create();
    {
        VehicleStatusBean vehicle = new VehicleStatusBean();
        vehicles.add(vehicle);
        vehicle.setLastUpdateTime(1234 * 1000);
        vehicle.setVehicleId("1_v1");
        TripStatusBean tripStatus = new TripStatusBean();
        vehicle.setTripStatus(tripStatus);
        tripStatus.setScheduleDeviation(2 * 60);
        TripBean trip = new TripBean();
        trip.setId("1_t0");
        trip.setRoute(route);
        tripStatus.setActiveTrip(trip);
        StopBean stop = new StopBean();
        stop.setId("1_s2");
        tripStatus.setNextStop(stop);
        tripStatus.setNextStopTimeOffset(5 * 60);
    }
    {
        VehicleStatusBean vehicle = new VehicleStatusBean();
        vehicles.add(vehicle);
        vehicle.setLastUpdateTime(5678 * 1000);
        vehicle.setVehicleId("1_v2");
        TripStatusBean tripStatus = new TripStatusBean();
        vehicle.setTripStatus(tripStatus);
        tripStatus.setScheduleDeviation(3 * 60);
        TripBean trip = new TripBean();
        trip.setId("1_t1");
        trip.setRoute(route);
        tripStatus.setActiveTrip(trip);
        StopBean stop = new StopBean();
        stop.setId("1_s3");
        tripStatus.setNextStop(stop);
        tripStatus.setNextStopTimeOffset(10 * 60);
    }
    ListBean<VehicleStatusBean> bean = new ListBean<VehicleStatusBean>();
    bean.setList(vehicles);
    Mockito.when(_service.getAllVehiclesForAgency("1", now)).thenReturn(bean);
    _action.setId("1");
    _action.setTime(new Date(now));
    _action.show();
    ResponseBean model = _action.getModel();
    FeedMessage feed = (FeedMessage) model.getData();
    assertEquals(now / 1000, feed.getHeader().getTimestamp());
    assertEquals(2, feed.getEntityCount());
    {
        FeedEntity entity = feed.getEntity(0);
        assertEquals("1", entity.getId());
        TripUpdate tripUpdate = entity.getTripUpdate();
        assertEquals("t0", tripUpdate.getTrip().getTripId());
        assertEquals("r1", tripUpdate.getTrip().getRouteId());
        assertEquals("v1", tripUpdate.getVehicle().getId());
        assertEquals(1234, tripUpdate.getTimestamp());
        assertEquals(120, tripUpdate.getDelay());
        assertEquals(1, tripUpdate.getStopTimeUpdateCount());
        StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
        assertEquals("s2", stopTimeUpdate.getStopId());
        assertEquals(now / 1000 + 5 * 60, stopTimeUpdate.getDeparture().getTime());
    }
    {
        FeedEntity entity = feed.getEntity(1);
        assertEquals("2", entity.getId());
        TripUpdate tripUpdate = entity.getTripUpdate();
        assertEquals("t1", tripUpdate.getTrip().getTripId());
        assertEquals("r1", tripUpdate.getTrip().getRouteId());
        assertEquals("v2", tripUpdate.getVehicle().getId());
        assertEquals(5678, tripUpdate.getTimestamp());
        assertEquals(180, tripUpdate.getDelay());
        assertEquals(1, tripUpdate.getStopTimeUpdateCount());
        StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
        assertEquals("s3", stopTimeUpdate.getStopId());
        assertEquals(now / 1000 + 10 * 60, stopTimeUpdate.getDeparture().getTime());
    }
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) Date(java.util.Date) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) StopBean(org.onebusaway.transit_data.model.StopBean) ResponseBean(org.onebusaway.api.model.ResponseBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)17 ListBean (org.onebusaway.transit_data.model.ListBean)17 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)5 Date (java.util.Date)4 List (java.util.List)4 Test (org.junit.Test)4 RouteBean (org.onebusaway.transit_data.model.RouteBean)4 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)3 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)3 IOException (java.io.IOException)3 ResponseBean (org.onebusaway.api.model.ResponseBean)3 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)3 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)3 Map (java.util.Map)2 T2 (org.onebusaway.collections.tuple.T2)2 Cacheable (org.onebusaway.container.cache.Cacheable)2 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)2 TripBean (org.onebusaway.transit_data.model.trips.TripBean)2 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)2