use of org.onebusaway.transit_data.model.StopBean 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.StopBean 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.StopBean in project onebusaway-application-modules by camsys.
the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesForStopIds.
public StopsWithArrivalsAndDeparturesBean getArrivalsAndDeparturesForStopIds(Set<AgencyAndId> ids, ArrivalsAndDeparturesQueryBean query) throws NoSuchStopServiceException {
List<StopBean> stops = new ArrayList<StopBean>();
List<ArrivalAndDepartureBean> allArrivalsAndDepartures = new ArrayList<ArrivalAndDepartureBean>();
Set<AgencyAndId> allNearbyStopIds = new HashSet<AgencyAndId>();
Map<String, ServiceAlertBean> situationsById = new HashMap<String, ServiceAlertBean>();
Counter<TimeZone> timeZones = new Counter<TimeZone>();
for (AgencyAndId id : ids) {
StopBean stopBean = _stopBeanService.getStopForId(id);
stops.add(stopBean);
List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
allArrivalsAndDepartures.addAll(arrivalsAndDepartures);
List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stopBean, 100);
allNearbyStopIds.addAll(nearbyStopIds);
TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(id.getAgencyId());
timeZones.increment(timeZone);
List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
for (ServiceAlertBean situation : situations) situationsById.put(situation.getId(), situation);
}
allNearbyStopIds.removeAll(ids);
List<StopBean> nearbyStops = new ArrayList<StopBean>();
for (AgencyAndId id : allNearbyStopIds) {
StopBean stop = _stopBeanService.getStopForId(id);
nearbyStops.add(stop);
}
TimeZone timeZone = timeZones.getMax();
if (timeZone == null)
timeZone = TimeZone.getDefault();
StopsWithArrivalsAndDeparturesBean result = new StopsWithArrivalsAndDeparturesBean();
result.setStops(stops);
result.setArrivalsAndDepartures(allArrivalsAndDepartures);
result.setNearbyStops(nearbyStops);
result.setSituations(new ArrayList<ServiceAlertBean>(situationsById.values()));
result.setTimeZone(timeZone.getID());
return result;
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class StopsBeanServiceImpl method getStopsByBounds.
private StopsBean getStopsByBounds(SearchQueryBean queryBean) throws ServiceException {
CoordinateBounds bounds = queryBean.getBounds();
List<AgencyAndId> stopIds = _geospatialBeanService.getStopsByBounds(bounds);
boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopIds, queryBean.getMaxCount());
List<StopBean> stopBeans = new ArrayList<StopBean>();
for (AgencyAndId stopId : stopIds) {
StopBean stopBean = _stopBeanService.getStopForId(stopId);
if (stopBean == null)
throw new ServiceException();
/**
* If the stop doesn't have any routes actively serving it, don't include
* it in the results
*/
if (stopBean.getRoutes().isEmpty())
continue;
stopBeans.add(stopBean);
}
return constructResult(stopBeans, limitExceeded);
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class TripStopTimesBeanServiceImpl method getStopTimesForTrip.
/**
**
* Private Methods
***
*/
private TripStopTimesBean getStopTimesForTrip(TripEntry trip) {
AgencyAndId tripId = trip.getId();
TripStopTimesBean bean = new TripStopTimesBean();
TimeZone tz = _agencyService.getTimeZoneForAgencyId(tripId.getAgencyId());
bean.setTimeZone(tz.getID());
for (StopTimeEntry stopTime : trip.getStopTimes()) {
TripStopTimeBean stBean = new TripStopTimeBean();
stBean.setArrivalTime(stopTime.getArrivalTime());
stBean.setDepartureTime(stopTime.getDepartureTime());
StopEntry stopEntry = stopTime.getStop();
StopBean stopBean = _stopBeanService.getStopForId(stopEntry.getId());
stBean.setStop(stopBean);
stBean.setDistanceAlongTrip(stopTime.getShapeDistTraveled());
bean.addStopTime(stBean);
}
return bean;
}
Aggregations