Search in sources :

Example 1 with LastTime

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();
}
Also used : BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) LastTime(org.onebusaway.nextbus.model.nextbus.LastTime) JsonRootName(com.fasterxml.jackson.annotation.JsonRootName)

Example 2 with LastTime

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;
}
Also used : Vehicle(org.onebusaway.nextbus.model.nextbus.Vehicle) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) Body(org.onebusaway.nextbus.model.nextbus.Body) LastTime(org.onebusaway.nextbus.model.nextbus.LastTime)

Aggregations

LastTime (org.onebusaway.nextbus.model.nextbus.LastTime)2 JsonRootName (com.fasterxml.jackson.annotation.JsonRootName)1 ArrayList (java.util.ArrayList)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Body (org.onebusaway.nextbus.model.nextbus.Body)1 BodyError (org.onebusaway.nextbus.model.nextbus.BodyError)1 Vehicle (org.onebusaway.nextbus.model.nextbus.Vehicle)1