use of org.onebusaway.gtfs_realtime.archiver.service.GtfsRealtimeRetriever.EntityType in project onebusaway-application-modules by camsys.
the class GtfsRealtimePlaybackController method tripUpdates.
@RequestMapping(value = "/gtfs-realtime/{path:trip-updates|vehicle-positions}")
public void tripUpdates(ServletRequest request, HttpServletResponse response, @RequestParam(value = "key", required = true) String key, @RequestParam(value = "timestamp", required = false) Long timestampInSeconds, @RequestParam(value = "time", required = false) String simpleDate, @RequestParam(value = "interval", required = false, defaultValue = "30") long interval, @PathVariable String path) throws IOException {
Status status = isAllowed(key);
if (Status.RATE_EXCEEDED == status) {
response.sendError(TOO_MANY_REQUESTS);
return;
}
if (Status.AUTHORIZED != status) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
if (simpleDate != null) {
Date parsed;
try {
parsed = DATE_FORMAT.parse(simpleDate);
timestampInSeconds = parsed.getTime() / 1000;
} catch (ParseException e) {
// bury
}
}
if (timestampInSeconds == null) {
response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "time or timestamp parameters required");
return;
}
EntityType type = path.equals("trip-updates") ? EntityType.TRIP : EntityType.VEHICLE;
// will not create new session if time is the same
Date requestedDate = new Date(timestampInSeconds * 1000);
_timeService.setCurrentTime(key, requestedDate);
Date endDate = _timeService.getCurrentTime(key);
Date startDate = new Date((endDate.getTime() - (interval * 1000)));
FeedMessage tripUpdates = _gtfsRealtimeRetriever.getFeedMessage(type, startDate, endDate);
render(request, response, tripUpdates);
}
Aggregations