Search in sources :

Example 11 with SearchQueryBean

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

the class RouteForNameAction method execute.

public String execute() throws Exception {
    _log.debug("in RouteForName with routeName " + _routeName);
    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();
    sessionMap.put("navState", new Integer(DISPLAY_DATA));
    logUserInteraction("route", _routeName);
    if (routes.size() == 0) {
        sessionMap.put("messageFromAction", getText(Messages.NO_ROUTES_WERE_FOUND));
        sessionMap.put("backAction", "search-index");
        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 12 with SearchQueryBean

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

the class RealtimeServiceV2Impl method getRoutesForBounds.

private List<RouteBean> getRoutesForBounds(CoordinateBounds bounds) {
    if (bounds != null) {
        SearchQueryBean queryBean = new SearchQueryBean();
        queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
        queryBean.setBounds(bounds);
        queryBean.setMaxCount(Integer.MAX_VALUE);
        RoutesBean routes = _transitDataService.getRoutes(queryBean);
        return routes.getRoutes();
    }
    return new ArrayList<RouteBean>();
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) ArrayList(java.util.ArrayList)

Example 13 with SearchQueryBean

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

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

the class StopByNumberAction method execute.

@Override
public String execute() throws ServiceException {
    if (_text != null)
        _text.trim();
    if (_text == null || _text.length() == 0)
        return INPUT;
    String[] tokens = _text.trim().split("\\s+");
    if (tokens.length == 0)
        return INPUT;
    CoordinateBounds serviceArea = _serviceAreaService.getServiceArea();
    if (serviceArea == null) {
        pushNextAction("stop-by-number", "text", _text);
        return "query-default-search-location";
    }
    _stopQuery = tokens[0];
    SearchQueryBean searchQuery = new SearchQueryBean();
    searchQuery.setBounds(serviceArea);
    searchQuery.setMaxCount(5);
    searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
    searchQuery.setQuery(_stopQuery);
    StopsBean results = _transitDataService.getStops(searchQuery);
    _stops = results.getStops();
    int stopIndex = 0;
    if (_stops.isEmpty()) {
        return "noStopsFound";
    } else if (_stops.size() > 1) {
        if (0 <= _selectedIndex && _selectedIndex < _stops.size()) {
            stopIndex = _selectedIndex;
        } else {
            pushNextAction("stop-by-number", "text", _text);
            pushNextAction("handle-multi-selection");
            return "multipleStopsFound";
        }
    }
    StopBean stop = _stops.get(stopIndex);
    _stopId = stop.getId();
    _args = new String[tokens.length - 1];
    System.arraycopy(tokens, 1, _args, 0, _args.length);
    return "arrivals-and-departures";
}
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 15 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 {
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null)
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    if (_stopCode == null || _stopCode.length() == 0)
        return INPUT;
    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();
    if (_stops.size() == 0) {
        return "noStopsFound";
    } else if (_stops.size() == 1) {
        StopBean stop = _stops.get(0);
        _stopIds = Arrays.asList(stop.getId());
        return SUCCESS;
    } else {
        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)

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