Search in sources :

Example 56 with RouteBean

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;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) ServiceException(org.onebusaway.exceptions.ServiceException) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 57 with RouteBean

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

Example 58 with RouteBean

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);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ValueStack(com.opensymphony.xwork2.util.ValueStack) List(java.util.List) AgiActionName(org.onebusaway.probablecalls.AgiActionName)

Example 59 with RouteBean

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;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrayList(java.util.ArrayList) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Example 60 with RouteBean

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

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