use of org.onebusaway.api.actions.siri.model.DetailLevel in project onebusaway-application-modules by camsys.
the class LinesRequestV2Action method index.
public DefaultHttpHeaders index() throws IOException {
long responseTimestamp = getTime();
processGoogleAnalytics();
_realtimeService.setTime(responseTimestamp);
boolean useLineRefOnly = false;
Boolean upcomingServiceAllStops = null;
CoordinateBounds bounds = null;
boolean validBoundDistance = true;
// User Parameters
String boundingBox = _request.getParameter(BOUNDING_BOX);
String circle = _request.getParameter(CIRCLE);
String lineRef = _request.getParameter(LINE_REF);
String directionId = _request.getParameter(DIRECTION_REF);
String agencyId = _request.getParameter(OPERATOR_REF);
String hasUpcomingScheduledService = _request.getParameter(UPCOMING_SCHEDULED_SERVICE);
String detailLevelParam = _request.getParameter(LINES_DETAIL_LEVEL);
String includePolylines = _request.getParameter(INCLUDE_POLYLINES);
// get the detail level parameter or set it to default if not specified
DetailLevel detailLevel;
if (DetailLevel.contains(detailLevelParam)) {
detailLevel = DetailLevel.valueOf(detailLevelParam.toUpperCase());
} else {
detailLevel = DetailLevel.NORMAL;
}
// Error Strings
String routeIdsErrorString = "";
String boundsErrorString = "";
/*
* We need to support the user providing no agency id which means 'all
* agencies'. So, this array will hold a single agency if the user
* provides it or all agencies if the user provides none. We'll iterate
* over them later while querying for vehicles and routes
*/
List<String> agencyIds = processAgencyIds(agencyId);
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
routeIdsErrorString = processRouteIds(lineRef, routeIds, agencyIds);
// Calculate Bounds
try {
if (StringUtils.isNotBlank(circle)) {
bounds = getCircleBounds(circle);
if (bounds != null && !isValidBoundsDistance(bounds, MAX_BOUNDS_RADIUS)) {
boundsErrorString += "Provided values exceed allowed search radius of " + MAX_BOUNDS_RADIUS + "m. ";
validBoundDistance = false;
}
} else if (StringUtils.isNotBlank(boundingBox)) {
bounds = getBoxBounds(boundingBox);
if (bounds != null && !isValidBoundBoxDistance(bounds, MAX_BOUNDS_DISTANCE)) {
boundsErrorString += "Provided values exceed allowed search distance of " + MAX_BOUNDS_DISTANCE + "m. ";
validBoundDistance = false;
}
}
} catch (NumberFormatException nfe) {
boundsErrorString += ERROR_NON_NUMERIC;
}
// Check for case where only LineRef was provided
if (routeIds.size() > 0) {
useLineRefOnly = true;
} else if (bounds == null) {
boundsErrorString += ERROR_REQUIRED_PARAMS;
}
// Setup Filters
Map<Filters, String> filters = new HashMap<Filters, String>();
filters.put(Filters.DIRECTION_REF, directionId);
filters.put(Filters.LINE_REF, lineRef);
filters.put(Filters.INCLUDE_POLYLINES, includePolylines);
filters.put(Filters.UPCOMING_SCHEDULED_SERVICE, hasUpcomingScheduledService);
// Annotated Lines
List<AnnotatedLineStructure> lines = new ArrayList<AnnotatedLineStructure>();
Map<Boolean, List<AnnotatedLineStructure>> linesMap;
// Error Handler
Exception error = null;
if ((bounds == null && !useLineRefOnly) || (lineRef != null && routeIds.size() == 0) || !validBoundDistance) {
String errorString = (boundsErrorString + " " + routeIdsErrorString).trim();
error = new Exception(errorString);
} else {
if (useLineRefOnly) {
linesMap = _realtimeService.getAnnotatedLineStructures(agencyIds, routeIds, detailLevel, responseTimestamp, filters);
} else {
linesMap = _realtimeService.getAnnotatedLineStructures(agencyIds, bounds, detailLevel, responseTimestamp, filters);
}
for (Map.Entry<Boolean, List<AnnotatedLineStructure>> entry : linesMap.entrySet()) {
upcomingServiceAllStops = entry.getKey();
lines.addAll(entry.getValue());
}
}
_response = generateSiriResponse(lines, upcomingServiceAllStops, error, responseTimestamp);
try {
this._servletResponse.getWriter().write(getLines());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Aggregations