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";
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations