Search in sources :

Example 6 with TripDetailsBean

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

the class TripsForAgencyAction method show.

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

Example 7 with TripDetailsBean

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

the class TripsForRouteAction method show.

public DefaultHttpHeaders show() throws IOException, ServiceException {
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    if (hasErrors())
        return setValidationErrorsResponse();
    long time = SystemTime.currentTimeMillis();
    if (_time != 0)
        time = _time;
    TripsForRouteQueryBean query = new TripsForRouteQueryBean();
    query.setRouteId(_id);
    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.getTripsForRoute(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) TripsForRouteQueryBean(org.onebusaway.transit_data.model.trips.TripsForRouteQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 8 with TripDetailsBean

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

the class RealtimeServiceImpl method getVehicleActivityForVehicle.

@Override
public VehicleActivityStructure getVehicleActivityForVehicle(String vehicleId, int maximumOnwardCalls, long currentTime, String tripId) {
    TripForVehicleQueryBean query = new TripForVehicleQueryBean();
    query.setTime(new Date(currentTime));
    query.setVehicleId(vehicleId);
    TripDetailsInclusionBean inclusion = new TripDetailsInclusionBean();
    inclusion.setIncludeTripStatus(true);
    inclusion.setIncludeTripBean(true);
    query.setInclusion(inclusion);
    TripDetailsBean tripDetailsForCurrentTrip = _transitDataService.getTripDetailsForVehicleAndTime(query);
    if (tripDetailsForCurrentTrip == null) {
        TripDetailsQueryBean detailsQuery = new TripDetailsQueryBean();
        detailsQuery.setTime(currentTime);
        detailsQuery.setTripId(tripId);
        tripDetailsForCurrentTrip = _transitDataService.getSingleTripDetails(detailsQuery);
    }
    if (tripDetailsForCurrentTrip == null || !_presentationService.include(tripDetailsForCurrentTrip.getStatus()))
        return null;
    VehicleActivityStructure output = new VehicleActivityStructure();
    // Check for Realtime Data
    if (!tripDetailsForCurrentTrip.getStatus().isPredicted()) {
        output.setRecordedAtTime(new Date(getTime()));
    } else {
        output.setRecordedAtTime(new Date(tripDetailsForCurrentTrip.getStatus().getLastUpdateTime()));
    }
    List<TimepointPredictionRecord> timePredictionRecords = null;
    timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(vehicleId).getAgencyId(), tripDetailsForCurrentTrip.getStatus());
    output.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
    SiriSupport.fillMonitoredVehicleJourney(output.getMonitoredVehicleJourney(), tripDetailsForCurrentTrip.getTrip(), tripDetailsForCurrentTrip.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetailsForCurrentTrip.getStatus().isPredicted(), currentTime, false);
    return output;
}
Also used : TripForVehicleQueryBean(org.onebusaway.transit_data.model.trips.TripForVehicleQueryBean) TripDetailsQueryBean(org.onebusaway.transit_data.model.trips.TripDetailsQueryBean) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) Date(java.util.Date) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) MonitoredVehicleJourney(uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney)

Example 9 with TripDetailsBean

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

the class RealtimeServiceImpl method getVehicleActivityForRoute.

/**
 * SIRI METHODS
 */
@Override
public List<VehicleActivityStructure> getVehicleActivityForRoute(String routeId, String directionId, int maximumOnwardCalls, long currentTime, boolean showRawLocation) {
    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 (tripDetails.getTrip().getDirectionId() != null) {
            if (directionId != null && !tripDetails.getTrip().getDirectionId().equals(directionId)) {
                continue;
            }
        }
        if (!_presentationService.include(tripDetails.getStatus()))
            continue;
        VehicleActivityStructure activity = new VehicleActivityStructure();
        // Check for Realtime Data
        if (!tripDetails.getStatus().isPredicted()) {
            activity.setRecordedAtTime(new Date(getTime()));
        } else {
            activity.setRecordedAtTime(new Date(tripDetails.getStatus().getLastUpdateTime()));
        }
        List<TimepointPredictionRecord> timePredictionRecords = null;
        timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(routeId).getAgencyId(), tripDetails.getStatus());
        activity.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
        SiriSupport.fillMonitoredVehicleJourney(activity.getMonitoredVehicleJourney(), tripDetails.getTrip(), tripDetails.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetails.getStatus().isPredicted(), currentTime, showRawLocation);
        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;
}
Also used : ArrayList(java.util.ArrayList) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) Date(java.util.Date) MonitoredVehicleJourney(uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney)

Example 10 with TripDetailsBean

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

the class ClosestStopForVehicleController method index.

@RequestMapping()
public ModelAndView index(@RequestParam() String vehicleId, @RequestParam() long time, @RequestParam(required = false) String format) {
    AgencyAndId vid = AgencyAndIdLibrary.convertFromString(vehicleId);
    if (time == 0)
        time = SystemTime.currentTimeMillis();
    if (time < 0)
        time = SystemTime.currentTimeMillis() - time * 1000;
    TripDetailsInclusionBean inclusion = new TripDetailsInclusionBean();
    inclusion.setIncludeTripBean(false);
    inclusion.setIncludeTripSchedule(false);
    inclusion.setIncludeTripStatus(true);
    TripDetailsBean details = _service.getTripForVehicle(vid, time, inclusion);
    if ("html".equals(format))
        return new ModelAndView("closest-stop-for-vehicle-html.jspx", "stopTime", details);
    else
        return new ModelAndView("closest-stop-for-vehicle-xml.jspx", "stopTime", details);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ModelAndView(org.springframework.web.servlet.ModelAndView) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)16 TripDetailsInclusionBean (org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean)10 ArrayList (java.util.ArrayList)6 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)4 Date (java.util.Date)3 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)3 TripForVehicleQueryBean (org.onebusaway.transit_data.model.trips.TripForVehicleQueryBean)3 TripDetailsV2Bean (org.onebusaway.api.model.transit.TripDetailsV2Bean)2 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2 ListBean (org.onebusaway.transit_data.model.ListBean)2 TripDetailsQueryBean (org.onebusaway.transit_data.model.trips.TripDetailsQueryBean)2 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)2 TripsForBoundsQueryBean (org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean)2 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 SiriExtensionWrapper (org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper)2 VehicleActivityStructure (uk.org.siri.siri.VehicleActivityStructure)2