use of org.onebusaway.nextbus.model.nextbus.LastTime in project onebusaway-application-modules by camsys.
the class BodySerializer method serialize.
@Override
public void serialize(Body<T> value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
List<T> response = value.getResponse();
List<BodyError> errors = value.getErrors();
String copyright = value.getCopyright();
LastTime lastTime = value.getLastTime();
gen.writeStartObject();
// Copyright
if (StringUtils.isNotBlank(copyright))
gen.writeStringField("copyright", copyright);
// Error
if (errors != null && errors.size() > 0) {
for (BodyError error : errors) error.setContent(error.getContent().replace("\\", ""));
gen.writeObjectField("Error", errors);
}
// Response
if (response != null && response.size() > 0) {
JsonRootName jsonRootName = response.get(0).getClass().getAnnotation(JsonRootName.class);
if (jsonRootName != null)
gen.writeObjectField(jsonRootName.value(), response);
else
gen.writeObjectField("response", response);
}
// LastTime
if (lastTime != null)
gen.writeObjectField("lastTime", lastTime);
gen.writeEndObject();
}
use of org.onebusaway.nextbus.model.nextbus.LastTime 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;
}
Aggregations