OBATraverseOptions options) {
TransitLegBuilder b = new TransitLegBuilder();
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(transitLeg.getTrip().getId());
TripEntry trip = _transitGraphDao.getTripEntryForId(tripId);
if (trip == null)
throw new NoSuchTripServiceException(transitLeg.getTrip().getId());
long serviceDate = transitLeg.getServiceDate();
AgencyAndId vehicleId = null;
if (transitLeg.getVehicleId() != null)
vehicleId = AgencyAndIdLibrary.convertFromString(transitLeg.getVehicleId());
if (transitLeg.getFromStop() != null
&& transitLeg.getFromStop().getId() != null) {
AgencyAndId fromStopId = AgencyAndIdLibrary.convertFromString(transitLeg.getFromStop().getId());
StopEntry fromStop = _transitGraphDao.getStopEntryForId(fromStopId, true);
int fromStopSequence = transitLeg.getFromStopSequence();
ArrivalAndDepartureQuery query = new ArrivalAndDepartureQuery();
query.setStop(fromStop);
query.setStopSequence(fromStopSequence);
query.setTrip(trip);
query.setServiceDate(serviceDate);
query.setVehicleId(vehicleId);
query.setTime(options.currentTime);
ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
b.setFromStop(instance);
b.setBlockTripInstanceFrom(instance.getBlockTripInstance());
b.setScheduledDepartureTime(instance.getScheduledDepartureTime());
b.setPredictedDepartureTime(instance.getPredictedDepartureTime());
}
if (transitLeg.getToStop() != null
&& transitLeg.getToStop().getId() != null) {
AgencyAndId toStopId = AgencyAndIdLibrary.convertFromString(transitLeg.getToStop().getId());
StopEntry toStop = _transitGraphDao.getStopEntryForId(toStopId, true);
int toStopSequence = transitLeg.getToStopSequence();
ArrivalAndDepartureQuery query = new ArrivalAndDepartureQuery();
query.setStop(toStop);
query.setStopSequence(toStopSequence);
query.setTrip(trip);
query.setServiceDate(serviceDate);
query.setVehicleId(vehicleId);
query.setTime(options.currentTime);
ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
b.setToStop(instance);
b.setBlockTripInstanceTo(instance.getBlockTripInstance());
b.setScheduledArrivalTime(instance.getScheduledArrivalTime());
b.setPredictedArrivalTime(instance.getPredictedArrivalTime());
}
if (b.getBlockTripInstanceFrom() == null) {
BlockEntry block = trip.getBlock();
BlockInstance blockInstance = _blockCalendarService.getBlockInstance(
block.getId(), serviceDate);
BlockTripInstance tripInstance = BlockTripInstanceLibrary.getBlockTripInstance(
blockInstance, trip.getId());
b.setBlockTripInstanceFrom(tripInstance);
}
return createTransitLegFromBuilder(b);
}