Search in sources :

Example 1 with Body

use of org.onebusaway.nextbus.model.nextbus.Body in project onebusaway-application-modules by camsys.

the class PredictionsForMultiStopsAction method getModel.

public Body<Predictions> getModel() {
    Body<Predictions> body = new Body<Predictions>();
    if (isValid(body)) {
        String serviceUrl = getServiceUrl() + agencyId + PREDICTIONS_COMMAND + "?";
        String routeStopIds = getStopParams();
        String uri = serviceUrl + routeStopIds + "format=" + REQUEST_TYPE;
        try {
            int timeout = _configUtil.getHttpTimeoutSeconds();
            JsonArray predictionsJson = _httpUtil.getJsonObject(uri, timeout).getAsJsonArray("predictions");
            Type listType = new TypeToken<List<Predictions>>() {
            }.getType();
            List<Predictions> predictions = new Gson().fromJson(predictionsJson, listType);
            modifyJSONObject(predictions);
            body.getResponse().addAll(predictions);
        } catch (Exception e) {
            body.getErrors().add(new BodyError("No valid results found."));
        }
    }
    return body;
}
Also used : Gson(com.google.gson.Gson) ServiceException(org.onebusaway.exceptions.ServiceException) JsonArray(com.google.gson.JsonArray) Type(java.lang.reflect.Type) BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) Predictions(org.onebusaway.nextbus.model.transiTime.Predictions) ArrayList(java.util.ArrayList) List(java.util.List) Body(org.onebusaway.nextbus.model.nextbus.Body)

Example 2 with Body

use of org.onebusaway.nextbus.model.nextbus.Body 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 3 with Body

use of org.onebusaway.nextbus.model.nextbus.Body 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 4 with Body

use of org.onebusaway.nextbus.model.nextbus.Body in project onebusaway-application-modules by camsys.

the class AgencyListAction method getModel.

@Override
public Body<Agency> getModel() {
    Body<Agency> body = new Body<Agency>();
    try {
        List<AgencyWithCoverageBean> agencies = _service.getAgenciesWithCoverage();
        for (AgencyWithCoverageBean agencyBean : agencies) {
            Agency agency = new Agency();
            agency.setTag(agencyBean.getAgency().getId());
            agency.setTitle(agencyBean.getAgency().getName());
            agency.setRegionTitle(agencyBean.getAgency().getName());
            body.getResponse().add(agency);
        }
    } catch (ServiceException e) {
        body.getErrors().add(new BodyError(ErrorMsg.SERVICE_ERROR.getDescription()));
    }
    return body;
}
Also used : Agency(org.onebusaway.nextbus.model.nextbus.Agency) ServiceException(org.onebusaway.exceptions.ServiceException) BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) Body(org.onebusaway.nextbus.model.nextbus.Body)

Example 5 with Body

use of org.onebusaway.nextbus.model.nextbus.Body in project onebusaway-application-modules by camsys.

the class MessagesAction method getModel.

@Override
public Body<Message> getModel() {
    Body<Message> body = new Body<Message>();
    List<String> agencyIds = processAgencyIds(getA());
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    if (processRouteIds(routeId, routeIds, agencyIds, body)) {
        for (AgencyAndId routeId : routeIds) {
            body.getResponse().addAll(getMessagesForRoute(agencyId, routeId.toString()));
        }
    }
    return body;
}
Also used : Message(org.onebusaway.nextbus.model.nextbus.Message) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) Body(org.onebusaway.nextbus.model.nextbus.Body)

Aggregations

Body (org.onebusaway.nextbus.model.nextbus.Body)9 ArrayList (java.util.ArrayList)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 Gson (com.google.gson.Gson)3 JsonArray (com.google.gson.JsonArray)3 Type (java.lang.reflect.Type)3 List (java.util.List)3 BodyError (org.onebusaway.nextbus.model.nextbus.BodyError)3 ServiceException (org.onebusaway.exceptions.ServiceException)2 DisplayRoute (org.onebusaway.nextbus.model.nextbus.DisplayRoute)2 DisplayStop (org.onebusaway.nextbus.model.nextbus.DisplayStop)2 Predictions (org.onebusaway.nextbus.model.transiTime.Predictions)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)2 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)2 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)2 AlphanumComparator (org.onebusaway.util.comparators.AlphanumComparator)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1