use of org.onebusaway.transit_data.model.trips.TripDetailsBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getVehicleActivityForRoute.
/**
* SIRI METHODS
*/
@Override
public List<VehicleActivityStructure> getVehicleActivityForRoute(String routeId, String directionId, int maximumOnwardCalls, DetailLevel detailLevel, long currentTime) {
List<VehicleActivityStructure> output = new ArrayList<VehicleActivityStructure>();
ListBean<TripDetailsBean> trips = getAllTripsForRoute(routeId, currentTime);
for (TripDetailsBean tripDetails : trips.getList()) {
// filter out interlined routes
if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId))
continue;
// filtered out by user
if (directionId != null && !tripDetails.getTrip().getDirectionId().equals(directionId))
continue;
if (!_presentationService.include(tripDetails.getStatus()))
continue;
VehicleActivityStructure activity = new VehicleActivityStructure();
activity.setRecordedAtTime(DateUtil.toXmlGregorianCalendar(tripDetails.getStatus().getLastUpdateTime()));
List<TimepointPredictionRecord> timePredictionRecords = null;
timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(routeId).getAgencyId(), tripDetails.getStatus());
activity.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
SiriSupportV2.fillMonitoredVehicleJourney(activity.getMonitoredVehicleJourney(), tripDetails.getTrip(), tripDetails.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetails.getStatus().isPredicted(), detailLevel, currentTime, null);
output.add(activity);
}
Collections.sort(output, new Comparator<VehicleActivityStructure>() {
public int compare(VehicleActivityStructure arg0, VehicleActivityStructure arg1) {
try {
SiriExtensionWrapper wrapper0 = (SiriExtensionWrapper) arg0.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
SiriExtensionWrapper wrapper1 = (SiriExtensionWrapper) arg1.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
return wrapper0.getDistances().getDistanceFromCall().compareTo(wrapper1.getDistances().getDistanceFromCall());
} catch (Exception e) {
return -1;
}
}
});
return output;
}
use of org.onebusaway.transit_data.model.trips.TripDetailsBean in project onebusaway-application-modules by camsys.
the class TripDetailsAction method show.
public DefaultHttpHeaders show() throws ServiceException {
if (!isVersion(V2))
return setUnknownVersionResponse();
if (hasErrors())
return setValidationErrorsResponse();
TripDetailsQueryBean query = new TripDetailsQueryBean();
query.setTripId(_id);
if (_serviceDate != null)
query.setServiceDate(_serviceDate.getTime());
query.setTime(_time.getTime());
query.setVehicleId(_vehicleId);
TripDetailsInclusionBean inclusion = query.getInclusion();
inclusion.setIncludeTripBean(_includeTrip);
inclusion.setIncludeTripSchedule(_includeSchedule);
inclusion.setIncludeTripStatus(_includeStatus);
TripDetailsBean trip = _service.getSingleTripDetails(query);
if (trip == null)
return setResourceNotFoundResponse();
BeanFactoryV2 factory = getBeanFactoryV2();
EntryWithReferencesBean<TripDetailsV2Bean> response = factory.getResponse(trip);
return setOkResponse(response);
}
use of org.onebusaway.transit_data.model.trips.TripDetailsBean in project onebusaway-application-modules by camsys.
the class TripForVehicleAction method show.
public DefaultHttpHeaders show() throws ServiceException {
if (!isVersion(V2))
return setUnknownVersionResponse();
if (hasErrors())
return setValidationErrorsResponse();
TripForVehicleQueryBean query = new TripForVehicleQueryBean();
query.setVehicleId(_id);
query.setTime(_time);
TripDetailsInclusionBean inclusion = query.getInclusion();
inclusion.setIncludeTripBean(_includeTrip);
inclusion.setIncludeTripSchedule(_includeSchedule);
inclusion.setIncludeTripStatus(_includeStatus);
TripDetailsBean trip = _service.getTripDetailsForVehicleAndTime(query);
if (trip == null)
return setResourceNotFoundResponse();
BeanFactoryV2 factory = getBeanFactoryV2();
EntryWithReferencesBean<TripDetailsV2Bean> response = factory.getResponse(trip);
return setOkResponse(response);
}
use of org.onebusaway.transit_data.model.trips.TripDetailsBean 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));
}
}
use of org.onebusaway.transit_data.model.trips.TripDetailsBean 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();
}
Aggregations