use of org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters in project onebusaway-application-modules by camsys.
the class StopMonitoringV2Action method index.
/*
@Override
public String execute() {
*/
public DefaultHttpHeaders index() throws IOException {
long responseTimestamp = getTime();
// _monitoringActionSupport.setupGoogleAnalytics(_request,
// _configurationService);
processGoogleAnalytics();
_realtimeService.setTime(responseTimestamp);
String detailLevelParam = _request.getParameter(STOP_MONITORING_DETAIL_LEVEL);
// 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;
}
// User Parameters
String lineRef = _request.getParameter(LINE_REF);
String monitoringRef = _request.getParameter(MONITORING_REF);
String directionId = _request.getParameter(DIRECTION_REF);
String agencyId = _request.getParameter(OPERATOR_REF);
String maxOnwardCallsParam = _request.getParameter(MAX_ONWARD_CALLS);
String maxStopVisitsParam = _request.getParameter(MAX_STOP_VISITS);
String minStopVisitsParam = _request.getParameter(MIN_STOP_VISITS);
// Error Strings
String routeIdsErrorString = "";
String stopIdsErrorString = "";
/*
* 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<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
List<AgencyAndId> stopIds = new ArrayList<AgencyAndId>();
List<String> agencyIds = processAgencyIds(agencyId);
stopIdsErrorString = processStopIds(monitoringRef, stopIds, agencyIds);
routeIdsErrorString = processRouteIds(lineRef, routeIds, agencyIds);
int maximumOnwardCalls = 0;
if (detailLevel.equals(DetailLevel.CALLS)) {
maximumOnwardCalls = SiriSupportV2.convertToNumeric(maxOnwardCallsParam, Integer.MAX_VALUE);
}
// Google Analytics code used by nyc
// if (_monitoringActionSupport
// .canReportToGoogleAnalytics(_configurationService)) {
// _monitoringActionSupport.reportToGoogleAnalytics(_request,
// "Stop Monitoring", StringUtils.join(stopIds, ","),
// _configurationService);
// }
// Setup Filters
Map<Filters, String> filters = new HashMap<Filters, String>();
filters.put(Filters.DIRECTION_REF, directionId);
filters.put(Filters.MAX_STOP_VISITS, maxStopVisitsParam);
filters.put(Filters.MIN_STOP_VISITS, minStopVisitsParam);
// Monitored Stop Visits
List<MonitoredStopVisitStructure> visits = new ArrayList<MonitoredStopVisitStructure>();
for (AgencyAndId stopId : stopIds) {
if (!stopId.hasValues())
continue;
// Stop ids can only be valid here because we only added valid ones
// to stopIds.
List<MonitoredStopVisitStructure> visitsForStop = _realtimeService.getMonitoredStopVisitsForStop(stopId.toString(), maximumOnwardCalls, detailLevel, responseTimestamp, routeIds, filters);
if (visitsForStop != null)
visits.addAll(visitsForStop);
}
Exception error = null;
if (stopIds.size() == 0 || (lineRef != null && routeIds.size() == 0)) {
String errorString = (stopIdsErrorString + " " + routeIdsErrorString).trim();
error = new Exception(errorString);
}
_response = generateSiriResponse(visits, stopIds, error, responseTimestamp);
try {
this._servletResponse.getWriter().write(getStopMonitoring());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters in project onebusaway-application-modules by camsys.
the class StopPointsV2Action 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(STOP_POINTS_DETAIL_LEVEL);
// 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 (bounds == null) {
if (routeIds.size() > 0) {
useLineRefOnly = true;
} else {
boundsErrorString += ERROR_REQUIRED_PARAMS;
}
}
// Setup Filters
Map<Filters, String> filters = new HashMap<Filters, String>();
filters.put(Filters.DIRECTION_REF, directionId);
filters.put(Filters.UPCOMING_SCHEDULED_SERVICE, hasUpcomingScheduledService);
// Annotated Stop Points
List<AnnotatedStopPointStructure> stopPoints = new ArrayList<AnnotatedStopPointStructure>();
Map<Boolean, List<AnnotatedStopPointStructure>> stopPointsMap;
// Error Handler
Exception error = null;
if ((bounds == null && !useLineRefOnly) || (_request.getParameter(LINE_REF) != null && routeIds.size() == 0) || !validBoundDistance) {
String errorString = (boundsErrorString + " " + routeIdsErrorString).trim();
error = new Exception(errorString);
} else {
if (useLineRefOnly) {
stopPointsMap = _realtimeService.getAnnotatedStopPointStructures(agencyIds, routeIds, detailLevel, responseTimestamp, filters);
} else {
stopPointsMap = _realtimeService.getAnnotatedStopPointStructures(bounds, agencyIds, routeIds, detailLevel, responseTimestamp, filters);
}
for (Map.Entry<Boolean, List<AnnotatedStopPointStructure>> entry : stopPointsMap.entrySet()) {
if (entry.getValue().size() > 0)
upcomingServiceAllStops = entry.getKey();
stopPoints.addAll(entry.getValue());
}
}
_response = generateSiriResponse(stopPoints, upcomingServiceAllStops, error, responseTimestamp);
try {
this._servletResponse.getWriter().write(getStopPoints());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters in project onebusaway-application-modules by camsys.
the class RealtimeServiceTest method testStopPointsByBounds.
@Test
public void testStopPointsByBounds() throws Exception {
// MOCKS
// Coordinate Bounds
CoordinateBounds bounds = new CoordinateBounds(Double.parseDouble("47.612813"), Double.parseDouble("-122.339662"), Double.parseDouble("47.608813"), Double.parseDouble("-122.337662"));
// Stops For Bounds
StopsBean stopsBean = new StopsBean();
stopsBean.setStops(stops);
when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean);
when(transitDataService.getStops(any(SearchQueryBean.class))).thenReturn(stopsBean);
when(transitDataService.getStopsForRoute("1_100194")).thenReturn(stopsForRouteBean);
when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
// EXPECTED
LineDirectionStructure lds = new LineDirectionStructure();
DirectionRefStructure drs = new DirectionRefStructure();
LineRefStructure lrs = new LineRefStructure();
lds.setDirectionRef(drs);
lds.setLineRef(lrs);
drs.setValue("0");
lrs.setValue("1_100194");
LocationStructure ls = new LocationStructure();
BigDecimal lat = new BigDecimal(47.610813);
BigDecimal lon = new BigDecimal(-122.338662);
ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue("3rd Ave & Pine St");
List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
stopNames.add(stopName);
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue("1_430");
Boolean monitored = true;
AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
mockStopPoint.setLocation(ls);
mockStopPoint.getStopName().add(stopName);
mockStopPoint.setStopPointRef(stopPointRef);
mockStopPoint.setMonitored(monitored);
// REALTIME ARGUMENTS
// Agency Ids
List<String> agencyIds = new ArrayList<String>();
String agencyId = "1";
agencyIds.add(agencyId);
// Route Ids
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
AgencyAndId routeId = AgencyAndIdLibrary.convertFromString("1_100194");
routeIds.add(routeId);
// Detail Level
DetailLevel detailLevel = DetailLevel.NORMAL;
// Time
long time = System.currentTimeMillis();
// Filters
Map<Filters, String> filters = new HashMap<Filters, String>();
Map<Boolean, List<AnnotatedStopPointStructure>> actualResult = realtimeService.getAnnotatedStopPointStructures(bounds, agencyIds, routeIds, detailLevel, time, filters);
AnnotatedStopPointStructure actualStopPoint = actualResult.get(true).get(0);
assertTrue(isEqual(mockStopPoint, actualStopPoint));
}
use of org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters in project onebusaway-application-modules by camsys.
the class RealtimeServiceTest method testStopPointsByRoute.
@Test
public void testStopPointsByRoute() throws Exception {
when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean);
when(transitDataService.getStopsForRoute("1_100194")).thenReturn(stopsForRouteBean);
when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
LineDirectionStructure lds = new LineDirectionStructure();
DirectionRefStructure drs = new DirectionRefStructure();
LineRefStructure lrs = new LineRefStructure();
lds.setDirectionRef(drs);
lds.setLineRef(lrs);
drs.setValue("0");
lrs.setValue("1_100194");
LocationStructure ls = new LocationStructure();
BigDecimal lat = new BigDecimal(47.610813);
BigDecimal lon = new BigDecimal(-122.338662);
ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue("3rd Ave & Pine St");
List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
stopNames.add(stopName);
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue("1_430");
Boolean monitored = true;
AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
mockStopPoint.setLocation(ls);
mockStopPoint.getStopName().add(stopName);
mockStopPoint.setStopPointRef(stopPointRef);
mockStopPoint.setMonitored(monitored);
// REALTIME ARGUMENTS
// Agency Ids
List<String> agencyIds = new ArrayList<String>();
String agencyId = "1";
agencyIds.add(agencyId);
// Route Ids
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
AgencyAndId routeId = AgencyAndIdLibrary.convertFromString("1_100194");
routeIds.add(routeId);
// Detail Level
DetailLevel detailLevel = DetailLevel.NORMAL;
// Time
long time = System.currentTimeMillis();
// Filters
Map<Filters, String> filters = new HashMap<Filters, String>();
Map<Boolean, List<AnnotatedStopPointStructure>> actualResult = realtimeService.getAnnotatedStopPointStructures(agencyIds, routeIds, detailLevel, time, filters);
AnnotatedStopPointStructure actualStopPoint = actualResult.get(true).get(0);
assertTrue(isEqual(mockStopPoint, actualStopPoint));
}
use of org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters 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