Search in sources :

Example 1 with SearchQueryBean

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

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

the class RealtimeServiceV2Impl method getStopsForBounds.

private List<StopBean> getStopsForBounds(CoordinateBounds bounds) {
    if (bounds != null) {
        SearchQueryBean queryBean = new SearchQueryBean();
        queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
        queryBean.setBounds(bounds);
        queryBean.setMaxCount(Integer.MAX_VALUE);
        StopsBean stops = _transitDataService.getStops(queryBean);
        return stops.getStops();
    }
    return new ArrayList<StopBean>();
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) ArrayList(java.util.ArrayList) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 3 with SearchQueryBean

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

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

the class StopForCodeAction method execute.

public String execute() throws Exception {
    _log.info("in stop for code");
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null)
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    if (_stopCode == null || _stopCode.length() == 0)
        return INPUT;
    if (_stop != null) {
        _stops = Arrays.asList(_stop);
    } else {
        _log.info("searching on stopCode=" + _stopCode);
        SearchQueryBean searchQuery = new SearchQueryBean();
        searchQuery.setBounds(bounds);
        searchQuery.setMaxCount(5);
        searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
        searchQuery.setQuery(_stopCode);
        StopsBean stopsBean = _transitDataService.getStops(searchQuery);
        _stops = stopsBean.getStops();
    }
    logUserInteraction("query", _stopCode);
    if (_stops.size() == 0) {
        sessionMap.put("messageFromAction", getText(Messages.NO_STOPS_WERE_FOUND));
        sessionMap.put("backAction", "stops-index");
        return "noStopsFound";
    } else if (_stops.size() == 1) {
        StopBean stop = _stops.get(0);
        _stopIds = Arrays.asList(stop.getId());
        return SUCCESS;
    } else {
        sessionMap.put("stops", _stops);
        return "multipleStopsFound";
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 5 with SearchQueryBean

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

the class StopsWithinBoundsAction method execute.

@Override
public String execute() {
    if (_bounds == null) {
        return SUCCESS;
    }
    SearchQueryBean queryBean = new SearchQueryBean();
    queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
    queryBean.setBounds(_bounds);
    queryBean.setMaxCount(200);
    StopsBean stops = null;
    try {
        stops = _transitDataService.getStops(queryBean);
    } catch (OutOfServiceAreaServiceException e) {
        _log.error(" invalid results: ", e);
        return SUCCESS;
    }
    for (StopBean stop : stops.getStops()) {
        String agencyId = AgencyAndIdLibrary.convertFromString(stop.getId()).getAgencyId();
        if (_transitDataService.stopHasRevenueService(agencyId, stop.getId())) {
            _stops.add(new StopOnRoute(stop));
        }
    }
    return SUCCESS;
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Aggregations

SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)15 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)11 StopsBean (org.onebusaway.transit_data.model.StopsBean)8 RoutesBean (org.onebusaway.transit_data.model.RoutesBean)7 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)5 RouteBean (org.onebusaway.transit_data.model.RouteBean)5 StopBean (org.onebusaway.transit_data.model.StopBean)5 ArrayList (java.util.ArrayList)3 SearchResultCollection (org.onebusaway.presentation.model.SearchResultCollection)3 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)3 Actions (org.apache.struts2.convention.annotation.Actions)2 SearchResult (org.onebusaway.presentation.model.SearchResult)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 StopOnRoute (org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute)1 RouteComparator (org.onebusaway.presentation.impl.RouteComparator)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1