Search in sources :

Example 61 with StopBean

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

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

the class StopTimeBeanServiceImpl method getStopTimeAsBean.

@Override
public StopTimeBean getStopTimeAsBean(StopTimeEntry stopTime) {
    StopTimeBean bean = new StopTimeBean();
    bean.setArrivalTime(stopTime.getArrivalTime());
    bean.setDepartureTime(stopTime.getDepartureTime());
    bean.setDropOffType(stopTime.getDropOffType());
    bean.setPickupType(stopTime.getPickupType());
    StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
    bean.setStop(stopBean);
    return bean;
}
Also used : StopBean(org.onebusaway.transit_data.model.StopBean) StopTimeBean(org.onebusaway.transit_data.model.schedule.StopTimeBean)

Example 63 with StopBean

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

the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.

public StopWithArrivalsAndDeparturesBean getArrivalsAndDeparturesByStopId(AgencyAndId id, ArrivalsAndDeparturesQueryBean query) {
    StopBean stop = _stopBeanService.getStopForId(id);
    if (stop == null)
        return null;
    List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
    List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stop, 100);
    List<StopBean> nearbyStops = new ArrayList<StopBean>();
    for (AgencyAndId nearbyStopId : nearbyStopIds) nearbyStops.add(_stopBeanService.getStopForId(nearbyStopId));
    List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
    return new StopWithArrivalsAndDeparturesBean(stop, arrivalsAndDepartures, nearbyStops, situations);
}
Also used : StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Example 64 with StopBean

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

Example 65 with StopBean

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

the class StopsBeanServiceImpl method getStopsByBoundsAndQuery.

private StopsBean getStopsByBoundsAndQuery(SearchQueryBean queryBean) throws ServiceException {
    CoordinateBounds bounds = queryBean.getBounds();
    String query = queryBean.getQuery();
    int maxCount = queryBean.getMaxCount();
    CoordinatePoint center = SphericalGeometryLibrary.getCenterOfBounds(bounds);
    SearchResult<AgencyAndId> stops;
    try {
        stops = _searchService.searchForStopsByCode(query, 10, MIN_SCORE);
    } catch (ParseException e) {
        throw new InvalidArgumentServiceException("query", "queryParseError");
    } catch (IOException e) {
        _log.error("error executing stop search: query=" + query, e);
        e.printStackTrace();
        throw new ServiceException();
    }
    Min<StopBean> closest = new Min<StopBean>();
    List<StopBean> stopBeans = new ArrayList<StopBean>();
    for (AgencyAndId aid : stops.getResults()) {
        StopBean stopBean = _stopBeanService.getStopForId(aid);
        if (bounds.contains(stopBean.getLat(), stopBean.getLon()))
            stopBeans.add(stopBean);
        double distance = SphericalGeometryLibrary.distance(center.getLat(), center.getLon(), stopBean.getLat(), stopBean.getLon());
        closest.add(distance, stopBean);
    }
    boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopBeans, maxCount);
    // If nothing was found in range, add the closest result
    if (stopBeans.isEmpty() && !closest.isEmpty())
        stopBeans.add(closest.getMinElement());
    return constructResult(stopBeans, limitExceeded);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Min(org.onebusaway.collections.Min) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) ParseException(org.apache.lucene.queryParser.ParseException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Aggregations

StopBean (org.onebusaway.transit_data.model.StopBean)69 ArrayList (java.util.ArrayList)34 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 RouteBean (org.onebusaway.transit_data.model.RouteBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)17 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)15 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)15 HashMap (java.util.HashMap)12 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)9 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)9 NameBean (org.onebusaway.transit_data.model.NameBean)9 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)8 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashSet (java.util.HashSet)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 List (java.util.List)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 Test (org.junit.Test)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)5