use of org.onebusaway.exceptions.OutOfServiceAreaServiceException in project onebusaway-application-modules by camsys.
the class SearchServiceImpl method findRoutesStoppingNearPoint.
@Override
public SearchResultCollection findRoutesStoppingNearPoint(Double latitude, Double longitude, SearchResultFactory resultFactory) {
CoordinateBounds bounds = SphericalGeometryLibrary.bounds(latitude, longitude, DISTANCE_TO_ROUTES);
SearchResultCollection results = new SearchResultCollection();
SearchQueryBean queryBean = new SearchQueryBean();
queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
queryBean.setBounds(bounds);
queryBean.setMaxCount(100);
RoutesBean routes = null;
try {
routes = _transitDataService.getRoutes(queryBean);
} catch (OutOfServiceAreaServiceException e) {
return results;
}
Collections.sort(routes.getRoutes(), new RouteDistanceFromPointComparator(latitude, longitude));
for (RouteBean route : routes.getRoutes()) {
SearchResult result = resultFactory.getRouteResult(route);
results.addMatch(result);
if (results.getMatches().size() > MAX_ROUTES) {
break;
}
}
return results;
}
use of org.onebusaway.exceptions.OutOfServiceAreaServiceException in project onebusaway-application-modules by camsys.
the class SearchServiceImpl method tryAsRoute.
private void tryAsRoute(SearchResultCollection results, String routeQueryMixedCase, SearchResultFactory resultFactory) {
String routeQuery = new String(routeQueryMixedCase);
if (routeQuery == null || StringUtils.isEmpty(routeQuery)) {
return;
}
routeQuery = routeQuery.toUpperCase().trim();
if (routeQuery.length() < 1) {
return;
}
// agency + route id matching (from direct links) as exact case
if (_routeIdToRouteBeanMap.get(routeQueryMixedCase) != null) {
RouteBean routeBean = _routeIdToRouteBeanMap.get(routeQueryMixedCase);
results.addMatch(resultFactory.getRouteResult(routeBean));
// if we've matched, assume no others
return;
}
// agency + route id matching (from direct links) as upper case
if (_routeIdToRouteBeanMap.get(routeQuery) != null) {
RouteBean routeBean = _routeIdToRouteBeanMap.get(routeQuery);
results.addMatch(resultFactory.getRouteResult(routeBean));
// if we've matched, assume no others
return;
}
// short name matching
if (_routeShortNameToRouteBeanMap.get(routeQuery) != null) {
for (RouteBean routeBean : _routeShortNameToRouteBeanMap.get(routeQuery)) {
results.addMatch(resultFactory.getRouteResult(routeBean));
}
}
for (String routeShortName : _routeShortNameToRouteBeanMap.keySet()) {
// if the route short name ends or starts with our query, and
// whatever's left over
// matches the regex
String leftOvers = routeShortName.replace(routeQuery, "");
Matcher matcher = leftOverMatchPattern.matcher(leftOvers);
Boolean leftOversAreDiscardable = matcher.find();
if (!routeQuery.equals(routeShortName) && ((routeShortName.startsWith(routeQuery) && leftOversAreDiscardable) || (routeShortName.endsWith(routeQuery) && leftOversAreDiscardable))) {
try {
for (RouteBean routeBean : _routeShortNameToRouteBeanMap.get(routeShortName)) {
results.addSuggestion(resultFactory.getRouteResult(routeBean));
}
continue;
} catch (OutOfServiceAreaServiceException oosase) {
}
}
}
// long name matching
for (String routeLongName : _routeLongNameToRouteBeanMap.keySet()) {
if (routeLongName.contains(routeQuery + " ") || routeLongName.contains(" " + routeQuery)) {
try {
for (RouteBean routeBean : _routeLongNameToRouteBeanMap.get(routeLongName)) {
results.addSuggestion(resultFactory.getRouteResult(routeBean));
}
} catch (OutOfServiceAreaServiceException oosase) {
}
}
}
}
use of org.onebusaway.exceptions.OutOfServiceAreaServiceException in project onebusaway-application-modules by camsys.
the class SearchServiceImpl method findRoutesStoppingWithinRegion.
@Override
public SearchResultCollection findRoutesStoppingWithinRegion(CoordinateBounds bounds, SearchResultFactory resultFactory) {
SearchResultCollection results = new SearchResultCollection();
SearchQueryBean queryBean = new SearchQueryBean();
queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
queryBean.setBounds(bounds);
queryBean.setMaxCount(100);
RoutesBean routes = null;
try {
routes = _transitDataService.getRoutes(queryBean);
} catch (OutOfServiceAreaServiceException e) {
return results;
}
Collections.sort(routes.getRoutes(), new RouteComparator());
for (RouteBean route : routes.getRoutes()) {
results.addMatch(resultFactory.getRouteResultForRegion(route));
}
return results;
}
use of org.onebusaway.exceptions.OutOfServiceAreaServiceException in project onebusaway-application-modules by camsys.
the class StopsForLocationAction method index.
public DefaultHttpHeaders index() throws IOException, ServiceException {
int maxCount = _maxCount.getMaxCount();
if (maxCount <= 0)
addFieldError("maxCount", "must be greater than zero");
if (hasErrors())
return setValidationErrorsResponse();
CoordinateBounds bounds = getSearchBounds();
SearchQueryBean searchQuery = new SearchQueryBean();
searchQuery.setBounds(bounds);
searchQuery.setMaxCount(maxCount);
searchQuery.setType(EQueryType.BOUNDS);
if (_query != null) {
searchQuery.setQuery(_query);
searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
}
try {
StopsBean result = _service.getStops(searchQuery);
return transformResult(result);
} catch (OutOfServiceAreaServiceException ex) {
return transformOutOfRangeResult();
}
}
use of org.onebusaway.exceptions.OutOfServiceAreaServiceException in project onebusaway-application-modules by camsys.
the class TripsForLocationAction method index.
public DefaultHttpHeaders index() throws IOException, ServiceException {
if (!isVersion(V2))
return setUnknownVersionResponse();
if (hasErrors())
return setValidationErrorsResponse();
CoordinateBounds bounds = _searchBoundsFactory.createBounds();
long time = SystemTime.currentTimeMillis();
if (_time != 0)
time = _time;
TripsForBoundsQueryBean query = new TripsForBoundsQueryBean();
query.setBounds(bounds);
query.setTime(time);
query.setMaxCount(_maxCount.getMaxCount());
TripDetailsInclusionBean inclusion = query.getInclusion();
inclusion.setIncludeTripBean(_includeTrip);
inclusion.setIncludeTripSchedule(_includeSchedule);
inclusion.setIncludeTripStatus(_includeStatus);
BeanFactoryV2 factory = getBeanFactoryV2();
try {
ListBean<TripDetailsBean> trips = _service.getTripsForBounds(query);
return setOkResponse(factory.getTripDetailsResponse(trips));
} catch (OutOfServiceAreaServiceException ex) {
return setOkResponse(factory.getEmptyList(TripDetailsV2Bean.class, true));
}
}
Aggregations