Search in sources :

Example 1 with RouteBean

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

the class RouteConfigAction method getModel.

@Override
public Body<Route> getModel() {
    Body<Route> body = new Body<Route>();
    if (isValid(body)) {
        List<String> agencyIds = processAgencyIds(agencyId);
        List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
        List<RouteBean> routeBeans = new ArrayList<RouteBean>();
        int routes_count = 1;
        if (processRouteIds(routeId, routeIds, agencyIds, body)) {
            for (AgencyAndId routeId : routeIds) {
                routeBeans.add(_transitDataService.getRouteForId(routeId.toString()));
            }
        } else if (routeId == null) {
            routeBeans = _transitDataService.getRoutesForAgencyId(agencyId).getList();
        }
        Collections.sort(routeBeans, new Comparator<RouteBean>() {

            AlphanumComparator alphaComparator = new AlphanumComparator();

            public int compare(RouteBean arg0, RouteBean arg1) {
                return alphaComparator.compare(arg0.getId(), arg1.getId());
            }
        });
        for (RouteBean routeBean : routeBeans) {
            // Limit Number of Routes Returned
            if (routes_count > MAX_ROUTES)
                break;
            Route route = new Route();
            route.setTag(getIdNoAgency(routeBean.getId()));
            route.setTitle(route.getTag() + " " + routeBean.getLongName());
            route.setShortTitle(routeBean.getShortName());
            route.setColor(routeBean.getColor());
            route.setOppositeColor(routeBean.getTextColor());
            StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
            // Stops
            for (StopBean stopBean : stopsForRoute.getStops()) {
                Stop stop = new Stop();
                stop.setTag(getIdNoAgency(stopBean.getId()));
                stop.setTitle(stopBean.getName());
                stop.setLat(stopBean.getLat());
                stop.setLon(stopBean.getLon());
                stop.setStopId(stopBean.getCode());
                route.getStops().add(stop);
            }
            // Directions
            for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
                for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                    Direction direction = new Direction();
                    direction.setTag(stopGroupBean.getId());
                    direction.setTitle(stopGroupBean.getName().getName());
                    for (String stopId : stopGroupBean.getStopIds()) {
                        direction.getStops().add(new DisplayStop(getIdNoAgency(stopId)));
                    }
                    route.getDirections().add(direction);
                }
            }
            // PolyLines
            for (EncodedPolylineBean polyline : stopsForRoute.getPolylines()) {
                Path path = new Path();
                List<CoordinatePoint> coordinatePoints = PolylineEncoder.decode(polyline);
                for (CoordinatePoint coordinatePoint : coordinatePoints) {
                    path.getPoints().add(new Point(coordinatePoint.getLat(), coordinatePoint.getLon()));
                }
                route.getPaths().add(path);
            }
            body.getResponse().add(route);
            routes_count++;
        }
    }
    return body;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) Stop(org.onebusaway.nextbus.model.nextbus.Stop) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Direction(org.onebusaway.nextbus.model.nextbus.Direction) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) Body(org.onebusaway.nextbus.model.nextbus.Body) Route(org.onebusaway.nextbus.model.nextbus.Route) DisplayRoute(org.onebusaway.nextbus.model.nextbus.DisplayRoute) Path(org.onebusaway.nextbus.model.nextbus.Path) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) AlphanumComparator(org.onebusaway.util.comparators.AlphanumComparator) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 2 with RouteBean

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

the class RouteListAction method getModel.

@Override
public Body<DisplayRoute> getModel() {
    Body<DisplayRoute> body = new Body<DisplayRoute>();
    if (isValid(body)) {
        List<RouteBean> routeBeans = _transitDataService.getRoutesForAgencyId(agencyId).getList();
        Collections.sort(routeBeans, new Comparator<RouteBean>() {

            AlphanumComparator alphaComparator = new AlphanumComparator();

            public int compare(RouteBean arg0, RouteBean arg1) {
                return alphaComparator.compare(arg0.getId(), arg1.getId());
            }
        });
        for (RouteBean routeBean : routeBeans) {
            DisplayRoute route = new DisplayRoute();
            route.setTag(getIdNoAgency(routeBean.getId()));
            route.setTitle(routeBean.getShortName() + " " + routeBean.getLongName());
            body.getResponse().add(route);
        }
    }
    return body;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AlphanumComparator(org.onebusaway.util.comparators.AlphanumComparator) Body(org.onebusaway.nextbus.model.nextbus.Body) DisplayRoute(org.onebusaway.nextbus.model.nextbus.DisplayRoute)

Example 3 with RouteBean

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

the class PredictionsAction method isValid.

private boolean isValid(Body body, List<AgencyAndId> stopIds, List<AgencyAndId> routeIds) {
    if (!isValidAgency(body, agencyId))
        return false;
    List<String> agencies = new ArrayList<String>();
    agencies.add(agencyId);
    if (!processStopIds(stopId, stopIds, agencies, body))
        return false;
    StopBean stopBean = getCachedStopBean(stopIds.get(0).toString());
    if (routeTag == null) {
        for (RouteBean routeBean : stopBean.getRoutes()) {
            routeIds.add(AgencyAndId.convertFromString(routeBean.getId()));
        }
    } else {
        if (!processRouteIds(routeTag, routeIds, agencies, body))
            return false;
        boolean stopServesRoute = false;
        for (RouteBean routeBean : stopBean.getRoutes()) {
            if (routeIds.contains(AgencyAndId.convertFromString(routeBean.getId())))
                stopServesRoute = true;
        }
        if (!stopServesRoute) {
            body.getErrors().add(new BodyError(ErrorMsg.ROUTE_UNAVAILABLE.getDescription(), agencyId, routeTag));
            return false;
        }
    }
    return true;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 4 with RouteBean

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

the class RouteForNameAction method execute.

@Override
public String execute() throws Exception {
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null)
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    if (_routeName == null || _routeName.length() == 0)
        return INPUT;
    SearchQueryBean routesQuery = new SearchQueryBean();
    routesQuery.setBounds(bounds);
    routesQuery.setMaxCount(10);
    routesQuery.setQuery(_routeName);
    routesQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
    RoutesBean routesBean = _transitDataService.getRoutes(routesQuery);
    List<RouteBean> routes = routesBean.getRoutes();
    if (routes.size() == 0) {
        return "noRoutesFound";
    } else if (routes.size() == 1) {
        _route = routes.get(0);
        return SUCCESS;
    } else {
        _routes = routes;
        return "multipleRoutesFound";
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 5 with RouteBean

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

the class StopScheduleBeanServiceImpl method applyContinuesAsStopTimeGroups.

private void applyContinuesAsStopTimeGroups(StopTimeByDirectionEntry stopTimesForDirection, List<StopTimeGroupBean> groups) {
    Counter<ContinuesAsStopTimeGroupKey> keyCounts = stopTimesForDirection.getContinuesAsKeyCounts();
    List<ContinuesAsStopTimeGroupKey> sortedKeys = keyCounts.getSortedKeys();
    for (ContinuesAsStopTimeGroupKey key : sortedKeys) {
        AgencyAndId lineId = key.getLineId();
        if (lineId == null)
            continue;
        StopTimeGroupBean group = new StopTimeGroupBean();
        String groupId = Integer.toString(groups.size());
        group.setId(groupId);
        RouteBean route = _routeBeanService.getRouteForId(lineId);
        group.setContinuesAs(route);
        applyGroupIdForGroupKey(stopTimesForDirection, key, groupId);
        groups.add(group);
    }
}
Also used : StopTimeGroupBean(org.onebusaway.transit_data.model.StopTimeGroupBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId)

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