Search in sources :

Example 6 with OutOfServiceAreaServiceException

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;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) SearchResultCollection(org.onebusaway.presentation.model.SearchResultCollection) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) SearchResult(org.onebusaway.presentation.model.SearchResult) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 7 with OutOfServiceAreaServiceException

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) {
            }
        }
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matcher(java.util.regex.Matcher) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException)

Example 8 with OutOfServiceAreaServiceException

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;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) RouteComparator(org.onebusaway.presentation.impl.RouteComparator) SearchResultCollection(org.onebusaway.presentation.model.SearchResultCollection) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException)

Example 9 with OutOfServiceAreaServiceException

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();
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 10 with OutOfServiceAreaServiceException

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));
    }
}
Also used : OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripsForBoundsQueryBean(org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Aggregations

OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)11 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)4 RouteBean (org.onebusaway.transit_data.model.RouteBean)3 RoutesBean (org.onebusaway.transit_data.model.RoutesBean)3 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)3 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)3 TripDetailsInclusionBean (org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean)3 SearchResultCollection (org.onebusaway.presentation.model.SearchResultCollection)2 StopsBean (org.onebusaway.transit_data.model.StopsBean)2 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)2 Matcher (java.util.regex.Matcher)1 StopOnRoute (org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute)1 RouteComparator (org.onebusaway.presentation.impl.RouteComparator)1 SearchResult (org.onebusaway.presentation.model.SearchResult)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 TripsForAgencyQueryBean (org.onebusaway.transit_data.model.trips.TripsForAgencyQueryBean)1 TripsForBoundsQueryBean (org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean)1 TripsForRouteQueryBean (org.onebusaway.transit_data.model.trips.TripsForRouteQueryBean)1