Search in sources :

Example 1 with RoutesBean

use of org.onebusaway.transit_data.model.RoutesBean in project onebusaway-application-modules by camsys.

the class RouteForNameAction method execute.

@Override
public String execute() throws Exception {
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null)
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    if (_routeName == null || _routeName.length() == 0)
        return INPUT;
    SearchQueryBean routesQuery = new SearchQueryBean();
    routesQuery.setBounds(bounds);
    routesQuery.setMaxCount(10);
    routesQuery.setQuery(_routeName);
    routesQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
    RoutesBean routesBean = _transitDataService.getRoutes(routesQuery);
    List<RouteBean> routes = routesBean.getRoutes();
    if (routes.size() == 0) {
        return "noRoutesFound";
    } else if (routes.size() == 1) {
        _route = routes.get(0);
        return SUCCESS;
    } else {
        _routes = routes;
        return "multipleRoutesFound";
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 2 with RoutesBean

use of org.onebusaway.transit_data.model.RoutesBean in project onebusaway-application-modules by camsys.

the class RoutesBeanServiceImpl method constructResult.

private RoutesBean constructResult(List<RouteBean> routeBeans, boolean limitExceeded) {
    Collections.sort(routeBeans, new RouteBeanIdComparator());
    RoutesBean result = new RoutesBean();
    result.setRoutes(routeBeans);
    result.setLimitExceeded(limitExceeded);
    return result;
}
Also used : RoutesBean(org.onebusaway.transit_data.model.RoutesBean)

Example 3 with RoutesBean

use of org.onebusaway.transit_data.model.RoutesBean in project onebusaway-application-modules by camsys.

the class RoutesForLocationAction 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 routesQuery = new SearchQueryBean();
    if (_query != null)
        routesQuery.setQuery(_query);
    routesQuery.setBounds(bounds);
    routesQuery.setMaxCount(maxCount);
    routesQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
    try {
        RoutesBean result = _service.getRoutes(routesQuery);
        return transformResult(result);
    } catch (OutOfServiceAreaServiceException ex) {
        return transformOutOfRangeResult();
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 4 with RoutesBean

use of org.onebusaway.transit_data.model.RoutesBean in project onebusaway-application-modules by camsys.

the class RoutesAction method execute.

@Override
@Actions({ @Action(value = "/where/iphone/routes") })
public String execute() throws ServiceException {
    if (_query == null || _query.length() == 0)
        return INPUT;
    CoordinateBounds bounds = getServiceArea();
    if (bounds == null) {
        pushNextAction("routes", "query", _query);
        return "query-default-search-location";
    }
    SearchQueryBean query = new SearchQueryBean();
    query.setBounds(bounds);
    query.setMaxCount(5);
    query.setQuery(_query);
    query.setType(EQueryType.BOUNDS_OR_CLOSEST);
    RoutesBean routesResult = _transitDataService.getRoutes(query);
    _routes = routesResult.getRoutes();
    if (_routes.size() == 0) {
        return "noRoutesFound";
    } else if (_routes.size() > 1) {
        return "multipleRoutesFound";
    } else {
        _route = _routes.get(0);
        return "singleRouteFound";
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Actions(org.apache.struts2.convention.annotation.Actions)

Example 5 with RoutesBean

use of org.onebusaway.transit_data.model.RoutesBean 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)

Aggregations

RoutesBean (org.onebusaway.transit_data.model.RoutesBean)8 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)7 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)5 RouteBean (org.onebusaway.transit_data.model.RouteBean)4 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)3 SearchResultCollection (org.onebusaway.presentation.model.SearchResultCollection)2 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)2 ArrayList (java.util.ArrayList)1 Actions (org.apache.struts2.convention.annotation.Actions)1 RouteComparator (org.onebusaway.presentation.impl.RouteComparator)1 SearchResult (org.onebusaway.presentation.model.SearchResult)1