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());
}
}
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));
}
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;
}
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);
}
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;
}
Aggregations