use of org.onebusaway.nextbus.model.nextbus.Body 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;
}
use of org.onebusaway.nextbus.model.nextbus.Body in project onebusaway-application-modules by camsys.
the class ScheduleHorizAction method getModel.
public Body<List<ScheduleRoute>> getModel() {
Body<List<ScheduleRoute>> body = new Body<List<ScheduleRoute>>();
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
if (isValid(body, routeIds)) {
String serviceUrl = getServiceUrl() + agencyId + SCHEDULE_COMMAND + "?";
String route = "r=" + getIdNoAgency(routeId);
String uri = serviceUrl + route + "&format=" + REQUEST_TYPE;
try {
int timeout = _configUtil.getHttpTimeoutSeconds();
JsonArray scheduleJson = _httpUtil.getJsonObject(uri, timeout).getAsJsonArray("schedule");
Type listType = new TypeToken<List<ScheduleRoute>>() {
}.getType();
List<ScheduleRoute> schedules = new Gson().fromJson(scheduleJson, listType);
modifyJSONObject(schedules);
body.getResponse().add(schedules);
} catch (Exception e) {
_log.error(e.getMessage());
}
}
return body;
}
use of org.onebusaway.nextbus.model.nextbus.Body in project onebusaway-application-modules by camsys.
the class VehicleLocationsAction method getModel.
@Override
public Body<Vehicle> getModel() {
Body<Vehicle> body = new Body<Vehicle>();
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
List<String> agencies = new ArrayList<String>();
if (isValid(body)) {
agencies.add(agencyId);
processRouteIds(routeId, routeIds, agencies, body, false);
// Valid Route Specified
if (routeIds.size() > 0) {
for (AgencyAndId routeId : routeIds) {
body.getResponse().addAll(getVehiclesForRoute(routeId.toString(), getAllTripsForRoute(routeId.toString(), getT())));
}
} else // Invalid Route Specified, return results for first 100 results for agency
{
body.getResponse().addAll(getVehiclesForRoute(null, getAllTripsForAgency(agencyId, getT())));
}
body.setLastTime(new LastTime(SystemTime.currentTimeMillis()));
}
return body;
}
use of org.onebusaway.nextbus.model.nextbus.Body in project onebusaway-application-modules by camsys.
the class PredictionsAction method getModel.
public Body<Predictions> getModel() {
Body<Predictions> body = new Body<Predictions>();
List<AgencyAndId> stopIds = new ArrayList<AgencyAndId>();
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
if (isValid(body, stopIds, routeIds)) {
String serviceUrl = getServiceUrl() + agencyId + PREDICTIONS_COMMAND + "?";
String routeStop = "";
for (AgencyAndId routeId : routeIds) {
routeStop += "rs=" + getIdNoAgency(routeId.toString()) + "|" + getIdNoAgency(stopId) + "&";
}
String uri = serviceUrl + routeStop + "format=" + REQUEST_TYPE;
_log.info(uri);
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."));
_log.error(e.getMessage());
}
}
return body;
}
Aggregations