use of org.onebusaway.nextbus.model.nextbus.BodyError in project onebusaway-application-modules by camsys.
the class BodyErrorConverter method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
BodyError error = new BodyError();
error.setContent(reader.getValue());
error.setShouldRetry(Boolean.parseBoolean(reader.getAttribute("shouldRetry")));
return error;
}
use of org.onebusaway.nextbus.model.nextbus.BodyError in project onebusaway-application-modules by camsys.
the class PredictionsForMultiStopsAction method isValid.
private boolean isValid(Body<Predictions> body) {
if (!isValidAgency(body, agencyId)) {
return false;
}
if (stops == null) {
body.getErrors().add(new BodyError(ErrorMsg.STOP_STOPS_NULL.getDescription()));
return false;
}
for (String stop : stops) {
String[] stopArray = stop.split("\\|");
if (stopArray.length < 2) {
String error = "The stop " + stop + " is invalid because it did not contain a route, optional dir, and stop tag";
body.getErrors().add(new BodyError(error));
return false;
}
try {
String stopId = _tdsMappingService.getStopIdFromStopCode(stopArray[1]);
StopBean stopBean;
try {
stopBean = _transitDataService.getStop(stopId);
} catch (ServiceException se) {
// The user didn't provide an agency id in stopId, so use provided
// agency
String stopIdVal = new AgencyAndId(agencyId, stopId).toString();
stopBean = _transitDataService.getStop(stopIdVal);
}
boolean routeExists = false;
for (RouteBean routeBean : stopBean.getRoutes()) {
if (routeBean.getId().equals(_tdsMappingService.getRouteIdFromShortName(stopArray[0]))) {
routeExists = true;
break;
}
}
if (!routeExists) {
String error = "For agency=" + getA() + " route r=" + stopArray[0] + " is not currently available. It might be initializing still.";
body.getErrors().add(new BodyError(error));
return false;
}
String routeTag = getIdNoAgency(_tdsMappingService.getRouteIdFromShortName(stopArray[0]));
String routeStop = getIdNoAgency(_tdsMappingService.getStopIdFromStopCode(stopArray[1]));
mappedStops.add(routeTag + "|" + routeStop);
} catch (ServiceException se) {
String error = "For agency=" + getA() + " stop s=" + stopArray[1] + " is on none of the directions for r=" + stopArray[0] + " so cannot determine which stop to provide data for.";
body.getErrors().add(new BodyError(error));
return false;
}
}
return true;
}
use of org.onebusaway.nextbus.model.nextbus.BodyError 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;
}
use of org.onebusaway.nextbus.model.nextbus.BodyError in project onebusaway-application-modules by camsys.
the class BodyErrorConverter method marshal.
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
BodyError error = (BodyError) source;
writer.addAttribute("shouldRetry", Boolean.toString(error.isShouldRetry()));
writer.setValue(error.getContent());
}
Aggregations