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