use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class PredictionsForMultiStopsAction method isValid.
private boolean isValid(Body<Predictions> body) {
if (!isValidAgency(body, agencyId)) {
return false;
}
if (stops == null) {
body.getErrors().add(new BodyError(ErrorMsg.STOP_STOPS_NULL.getDescription()));
return false;
}
for (String stop : stops) {
String[] stopArray = stop.split("\\|");
if (stopArray.length < 2) {
String error = "The stop " + stop + " is invalid because it did not contain a route, optional dir, and stop tag";
body.getErrors().add(new BodyError(error));
return false;
}
try {
String stopId = _tdsMappingService.getStopIdFromStopCode(stopArray[1]);
StopBean stopBean;
try {
stopBean = _transitDataService.getStop(stopId);
} catch (ServiceException se) {
// The user didn't provide an agency id in stopId, so use provided
// agency
String stopIdVal = new AgencyAndId(agencyId, stopId).toString();
stopBean = _transitDataService.getStop(stopIdVal);
}
boolean routeExists = false;
for (RouteBean routeBean : stopBean.getRoutes()) {
if (routeBean.getId().equals(_tdsMappingService.getRouteIdFromShortName(stopArray[0]))) {
routeExists = true;
break;
}
}
if (!routeExists) {
String error = "For agency=" + getA() + " route r=" + stopArray[0] + " is not currently available. It might be initializing still.";
body.getErrors().add(new BodyError(error));
return false;
}
String routeTag = getIdNoAgency(_tdsMappingService.getRouteIdFromShortName(stopArray[0]));
String routeStop = getIdNoAgency(_tdsMappingService.getStopIdFromStopCode(stopArray[1]));
mappedStops.add(routeTag + "|" + routeStop);
} catch (ServiceException se) {
String error = "For agency=" + getA() + " stop s=" + stopArray[1] + " is on none of the directions for r=" + stopArray[0] + " so cannot determine which stop to provide data for.";
body.getErrors().add(new BodyError(error));
return false;
}
}
return true;
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class PredictionsForMultiStopsAction method getStopIdParams.
private String getStopIdParams() {
StringBuilder sb = new StringBuilder();
for (String stopId : stops) {
StopBean stopBean = _transitDataService.getStop(stopId);
for (RouteBean routeBean : stopBean.getRoutes()) {
sb.append("rs=");
sb.append(routeBean.getId());
sb.append("|");
sb.append(stopId);
sb.append("&");
}
}
return sb.toString();
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class MultipleRoutesFoundTemplate method buildTemplate.
@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
ValueStack vs = context.getValueStack();
List<RouteBean> routes = (List<RouteBean>) vs.findValue("routes");
int index = 1;
addMessage(Messages.MULTIPLE_ROUTES_WERE_FOUND);
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);
AgiActionName action = addAction(key, "/search/tree");
action.putParam("route", route);
}
addMessage(Messages.HOW_TO_GO_BACK);
addAction("\\*", "/back");
addMessage(Messages.TO_REPEAT);
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesForRouteAction method execute.
@Override
public String execute() throws Exception {
Set<String> routeIds = getRouteIdsForMatchingRoutes();
List<ArrivalAndDepartureBean> arrivals = new ArrayList<ArrivalAndDepartureBean>();
StopsWithArrivalsAndDeparturesBean m = _model.getResult();
for (ArrivalAndDepartureBean pab : m.getArrivalsAndDepartures()) {
RouteBean route = pab.getTrip().getRoute();
if (routeIds.contains(route.getId()) || _route.equals(route.getShortName())) {
arrivals.add(pab);
}
}
m = new StopsWithArrivalsAndDeparturesBean(m.getStops(), arrivals, m.getNearbyStops(), m.getSituations());
_model.setResult(m);
return SUCCESS;
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class RouteNameComponent method end.
@Override
public boolean end(Writer writer, String body) {
if (_value == null)
_value = "top";
Object obj = findValue(_value);
if (obj instanceof TripBean) {
TripBean trip = (TripBean) obj;
String routeShortName = trip.getRouteShortName();
if (routeShortName != null) {
try {
writer.write(routeShortName);
} catch (IOException e) {
LOG.error("Could not write out Text tag", e);
}
} else {
obj = trip.getRoute();
}
}
if (obj instanceof RouteBean) {
RouteBean route = (RouteBean) obj;
String name = RoutePresenter.getNameForRoute(route);
try {
writer.write(name);
} catch (IOException e) {
LOG.error("Could not write out Text tag", e);
}
}
return super.end(writer, "");
}
Aggregations