use of org.onebusaway.nextbus.model.nextbus.DisplayStop 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.nextbus.model.nextbus.DisplayStop in project onebusaway-application-modules by camsys.
the class ScheduleAction method getModel.
@Override
public Body<ScheduleRoute> getModel() {
Body<ScheduleRoute> body = new Body<ScheduleRoute>();
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
if (this.isValid(body, routeIds)) {
AgencyBean agency = _transitDataService.getAgency(agencyId);
List<HashMap<String, HashSet<ScheduleStop>>> blockStopsMapList = new ArrayList<HashMap<String, HashSet<ScheduleStop>>>();
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
// Get All the Stops for a specific route
for (AgencyAndId routeId : routeIds) {
String route = AgencyAndId.convertToString(routeId);
StopsForRouteBean stopsForRoute = _service.getStopsForRoute(route);
for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
// Weekday Trips
for (Long weekdayTime : DateUtil.getWeekdayDateTimes(agency.getTimezone())) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(weekdayTime);
query.setMinutesBefore(0);
query.setMinutesAfter(MINUTES_IN_DAY);
StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
// Filter Arrivals and Departures By Route
if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
ScheduleStop scheduleStop = new ScheduleStop();
scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
addStopByBlockId(blockStopsMapList.get(0), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
} else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
addStopByBlockId(blockStopsMapList.get(1), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
}
}
}
}
// Weekend Trips
for (Long weekendTime : DateUtil.getWeekendDateTimes(agency.getTimezone())) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(weekendTime);
query.setMinutesBefore(0);
query.setMinutesAfter(MINUTES_IN_DAY);
StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
// Filter Arrivals and Departures By Route
if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
ScheduleStop scheduleStop = new ScheduleStop();
scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
addStopByBlockId(blockStopsMapList.get(2), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
} else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
addStopByBlockId(blockStopsMapList.get(3), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
}
}
}
}
}
}
// Routes
for (int n = 0; n < blockStopsMapList.size(); n++) {
HashMap<String, HashSet<ScheduleStop>> blockStopsMap = blockStopsMapList.get(n);
ScheduleRoute scheduleRoute = new ScheduleRoute();
scheduleRoute.setTitle(stopsForRoute.getRoute().getLongName());
scheduleRoute.setDirection(Integer.toString(n % 2));
scheduleRoute.setTag(getIdNoAgency(stopsForRoute.getRoute().getId()));
scheduleRoute.setServiceClass(n < 3 ? "wkd" : "wkend");
// Blocks
for (Entry<String, HashSet<ScheduleStop>> entry : blockStopsMap.entrySet()) {
int tripStopTimeCounter = 0;
String blockId = entry.getKey();
HashSet<ScheduleStop> blockStops = entry.getValue();
ScheduleTableRow scheduleTr = new ScheduleTableRow(getIdNoAgency(blockId));
// Stop Times
for (ScheduleStop stop : blockStops) {
if (tripStopTimeCounter == 0) {
DisplayStop displayStop = new DisplayStop();
displayStop.setTag(stop.getTag());
displayStop.setValue(stop.getStopName());
scheduleRoute.getStops().add(displayStop);
}
// scheduleStop.setValue(value);
scheduleTr.getStops().add(stop);
}
scheduleRoute.getScheduleTableRow().add(scheduleTr);
}
body.getResponse().add(scheduleRoute);
}
}
}
return body;
}
Aggregations