Search in sources :

Example 1 with TripsForBoundsQueryBean

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

the class TripsForLocationAction method index.

public DefaultHttpHeaders index() throws IOException, ServiceException {
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    if (hasErrors())
        return setValidationErrorsResponse();
    CoordinateBounds bounds = _searchBoundsFactory.createBounds();
    long time = SystemTime.currentTimeMillis();
    if (_time != 0)
        time = _time;
    TripsForBoundsQueryBean query = new TripsForBoundsQueryBean();
    query.setBounds(bounds);
    query.setTime(time);
    query.setMaxCount(_maxCount.getMaxCount());
    TripDetailsInclusionBean inclusion = query.getInclusion();
    inclusion.setIncludeTripBean(_includeTrip);
    inclusion.setIncludeTripSchedule(_includeSchedule);
    inclusion.setIncludeTripStatus(_includeStatus);
    BeanFactoryV2 factory = getBeanFactoryV2();
    try {
        ListBean<TripDetailsBean> trips = _service.getTripsForBounds(query);
        return setOkResponse(factory.getTripDetailsResponse(trips));
    } catch (OutOfServiceAreaServiceException ex) {
        return setOkResponse(factory.getEmptyList(TripDetailsV2Bean.class, true));
    }
}
Also used : OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripsForBoundsQueryBean(org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 2 with TripsForBoundsQueryBean

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

the class MetricResource method getScheduledTrips.

protected int getScheduledTrips(String agencyId, String routeId) {
    Set<TripDetailsBean> agencyTrips = new HashSet<TripDetailsBean>();
    TripsForBoundsQueryBean query = new TripsForBoundsQueryBean();
    List<CoordinateBounds> allBounds = getTDS().getAgencyIdsWithCoverageArea().get(agencyId);
    for (CoordinateBounds bounds : allBounds) {
        query.setBounds(bounds);
        query.setTime(SystemTime.currentTimeMillis());
        query.setMaxCount(Integer.MAX_VALUE);
        TripDetailsInclusionBean inclusion = query.getInclusion();
        inclusion.setIncludeTripBean(true);
        ListBean<TripDetailsBean> allTrips = getTDS().getTripsForBounds(query);
        if (allTrips == null) {
            continue;
        }
        _log.debug("allTrips size=" + allTrips.getList().size());
        AgencyAndId routeAndId = new AgencyAndId(agencyId, routeId);
        for (TripDetailsBean trip : allTrips.getList()) {
            if (trip.getTripId().startsWith(agencyId)) {
                if (routeId == null || routeAndId.toString().equals(trip.getTrip().getRoute().getId())) {
                    agencyTrips.add(trip);
                }
            }
        }
    }
    return agencyTrips.size();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripsForBoundsQueryBean(org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) HashSet(java.util.HashSet) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Aggregations

CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)2 TripDetailsInclusionBean (org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean)2 TripsForBoundsQueryBean (org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean)2 HashSet (java.util.HashSet)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1