use of org.onebusaway.nextbus.model.transiTime.Predictions 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;
}
use of org.onebusaway.nextbus.model.transiTime.Predictions 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