Search in sources :

Example 11 with StopsBean

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

Example 12 with StopsBean

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

the class StopsBeanServiceImpl method getStopsByName.

@Override
public StopsBean getStopsByName(String stopName) throws ServiceException {
    List<StopBean> stopBeans = new ArrayList<StopBean>();
    SearchResult<AgencyAndId> results = null;
    try {
        results = _searchService.searchForStopsByName(stopName, MAX_STOPS, NAME_MIN_SCORE);
        for (AgencyAndId aid : results.getResultsByTopScore()) {
            StopBean stopBean = _stopBeanService.getStopForId(aid);
            if (stopBean != null) {
                stopBeans.add(stopBean);
            }
        }
    } catch (Exception e) {
        _log.error("search failed!", e);
        // simply return no results, the search was not understood
        return new StopsBean();
    }
    if (results == null) {
        return new StopsBean();
    }
    return constructResult(stopBeans, results.size() == MAX_STOPS);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) ParseException(org.apache.lucene.queryParser.ParseException) ServiceException(org.onebusaway.exceptions.ServiceException) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) IOException(java.io.IOException) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Aggregations

StopsBean (org.onebusaway.transit_data.model.StopsBean)12 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)9 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 StopBean (org.onebusaway.transit_data.model.StopBean)7 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 List (java.util.List)2 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 ParseException (org.apache.lucene.queryParser.ParseException)1 Actions (org.apache.struts2.convention.annotation.Actions)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Filters (org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters)1 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)1 StopOnRoute (org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute)1 InvalidArgumentServiceException (org.onebusaway.exceptions.InvalidArgumentServiceException)1