Search in sources :

Example 16 with RouteBean

use of org.onebusaway.transit_data.model.RouteBean 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)

Example 17 with RouteBean

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

the class RoutesForAgencyAction method show.

public DefaultHttpHeaders show() {
    if (hasErrors())
        return setValidationErrorsResponse();
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    ListBean<RouteBean> routes = _service.getRoutesForAgencyId(_id);
    BeanFactoryV2 factory = getBeanFactoryV2();
    List<RouteV2Bean> beans = new ArrayList<RouteV2Bean>();
    for (RouteBean route : routes.getList()) beans.add(factory.getRoute(route));
    return setOkResponse(factory.list(beans, false));
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrayList(java.util.ArrayList) RouteV2Bean(org.onebusaway.api.model.transit.RouteV2Bean) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 18 with RouteBean

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

the class ArrivalsAndDeparturesAction method buildStopRouteAlertsMap.

private Map<StopRouteKey, List<ServiceAlertBean>> buildStopRouteAlertsMap() {
    List<StopBean> stops = (List<StopBean>) sessionMap.get("stops");
    Map<StopRouteKey, List<ServiceAlertBean>> stopRouteAlertsMap = new TreeMap<StopRouteKey, List<ServiceAlertBean>>();
    if (stops != null) {
        for (StopBean stop : stops) {
            List<ServiceAlertBean> stopAlerts = getServiceAlertsForStop(stop.getId());
            if (stopAlerts.size() > 0) {
                stopRouteAlertsMap.put(new StopRouteKey(stop.getId(), NO_ROUTE), stopAlerts);
            } else {
                for (RouteBean route : stop.getRoutes()) {
                    if (!stopRouteAlertsMap.containsKey(new StopRouteKey(stop.getId(), route.getId()))) {
                        List<ServiceAlertBean> routeAlerts = getServiceAlertsForRoute(route.getId());
                        if (routeAlerts.size() == 0) {
                            routeAlerts = getServiceAlertsForStopRoute(stop.getId(), route.getId());
                        }
                        stopRouteAlertsMap.put(new StopRouteKey(stop.getId(), route.getId()), routeAlerts);
                    }
                }
            }
        }
    }
    return stopRouteAlertsMap;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopBean(org.onebusaway.transit_data.model.StopBean) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 19 with RouteBean

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

the class ArrivalsAndDeparturesAction method buildPredictedArrivals.

protected void buildPredictedArrivals(List<ArrivalAndDepartureBean> arrivals, List<StopBean> list) {
    if (arrivals.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
    }
    Collections.sort(arrivals, new ArrivalAndDepartureComparator());
    long now = SystemTime.currentTimeMillis();
    boolean hasAlerts = stopsHaveAlerts(list);
    for (ArrivalAndDepartureBean adb : arrivals) {
        TripBean trip = adb.getTrip();
        RouteBean route = trip.getRoute();
        addMessage(Messages.ROUTE);
        String routeNumber = RoutePresenter.getNameForRoute(route);
        addText(_routeNumberPronunciation.modify(routeNumber));
        addText(", ");
        String headsign = trip.getTripHeadsign();
        if (headsign != null) {
            // addMessage(Messages.TO);
            String destination = _destinationPronunciation.modify(headsign);
            destination = destination.replaceAll("\\&", "and");
            addText(destination);
            addText(", ");
        }
        if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
            addText("is currently not in service");
            continue;
        }
        long t = adb.computeBestDepartureTime();
        boolean isPrediction = adb.hasPredictedDepartureTime();
        int min = (int) ((t - now) / 1000 / 60);
        if (min < 0) {
            min = -min;
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
                addMessage(message, min);
            }
        } else {
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
                addMessage(message, min);
            }
        }
        if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus())) {
            addText("but is currently on adverse weather re-route.");
        }
        addText(". ");
        if (!hasAlerts && adb.getSituations() != null && adb.getSituations().size() > 0) {
            hasAlerts = true;
        }
    }
    if (hasAlerts) {
        addText(getAlertPresentText());
    }
    addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
    List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
    if (!agencies.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
        for (int i = 0; i < agencies.size(); i++) {
            AgencyBean agency = agencies.get(i);
            if (i == agencies.size() - 1 && agencies.size() > 1)
                addText(Messages.AND);
            addText(agency.getName());
            addText(",");
        }
    }
    addMessage(Messages.STOP_FOUND_BOOKMARK_THIS_LOCATION);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureComparator(org.onebusaway.presentation.impl.ArrivalAndDepartureComparator) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 20 with RouteBean

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

the class MultipleRoutesFoundAction method execute.

@Override
public String execute() throws Exception {
    Integer navState = (Integer) sessionMap.get("navState");
    if (navState == null) {
        navState = DISPLAY_DATA;
    }
    _log.debug("MultipleRoutesFound, navState: " + navState);
    if (navState == DISPLAY_DATA) {
        ActionContext context = ActionContext.getContext();
        ValueStack vs = context.getValueStack();
        List<RouteBean> routes = (List<RouteBean>) vs.findValue("routes");
        int index = 1;
        addMessage(Messages.MULTIPLE_ROUTES_WERE_FOUND);
        // Keep a map of key options and their corresponding route beans
        Map<Integer, RouteBean> keyMapping = new HashMap<Integer, RouteBean>();
        for (RouteBean route : routes) {
            addMessage(Messages.FOR);
            addMessage(Messages.ROUTE);
            String routeNumber = route.getShortName();
            addText(_routeNumberPronunciation.modify(routeNumber));
            addMessage(Messages.OPERATED_BY);
            addText(route.getAgency().getName());
            addMessage(Messages.PLEASE_PRESS);
            String key = Integer.toString(index++);
            addText(key);
            keyMapping.put(new Integer(index - 1), route);
        }
        addMessage(Messages.HOW_TO_GO_BACK);
        // addAction("\\*", "/back");
        addMessage(Messages.TO_REPEAT);
        sessionMap.put("keyMapping", keyMapping);
        navState = DO_ROUTING;
        sessionMap.put("navState", navState);
        setNextAction("search/multiple-routes-found");
    } else {
        // Do the routing, matching the key pressed with the correct route bean.
        _log.debug("Handling selection of choice of routes.");
        // Handle "back" request ('*' key pressed)
        if (PREVIOUS_MENU_ITEM.equals(getInput())) {
            return "back";
        }
        int key = Integer.parseInt(getInput());
        Map<Integer, RouteBean> keyMapping = (Map<Integer, RouteBean>) sessionMap.get("keyMapping");
        _route = (RouteBean) keyMapping.get(key);
        navState = DISPLAY_DATA;
        sessionMap.put("navState", navState);
        _log.debug("Key " + key + " entered for route: " + _route.getId());
        return "route-selected";
    }
    return SUCCESS;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) List(java.util.List) ActionContext(com.opensymphony.xwork2.ActionContext) HashMap(java.util.HashMap) Map(java.util.Map)

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