use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method groupStopTimeInstancesByRouteCollectionId.
private void groupStopTimeInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> stopTimesByRouteCollectionId, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
Map<AgencyAndId, Set<FrequencyEntry>> frequencyLabelsByRouteCollectionId = new FactoryMap<AgencyAndId, Set<FrequencyEntry>>(new HashSet<FrequencyEntry>());
for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) {
ServiceIdActivation serviceIds = index.getServiceIds();
Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
if (!serviceDates.contains(date))
continue;
Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
for (BlockStopTimeEntry stopTime : index.getStopTimes()) {
BlockTripEntry blockTrip = stopTime.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
FrequencyEntry frequencyLabel = trip.getFrequencyLabel();
InstanceState state = new InstanceState(serviceDate.getTime(), frequencyLabel);
StopTimeInstance sti = new StopTimeInstance(stopTime, state);
if (frequencyLabel == null) {
stopTimesByRouteCollectionId.get(routeCollectionId).add(sti);
} else if (frequencyLabelsByRouteCollectionId.get(routeCollectionId).add(frequencyLabel)) {
frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
}
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class TripBeanServiceImpl method getTripForId.
@Cacheable
public TripBean getTripForId(AgencyAndId tripId) {
TripEntry tripEntry = _graph.getTripEntryForId(tripId);
if (tripEntry == null)
return null;
AgencyAndId routeId = tripEntry.getRouteCollection().getId();
RouteBean routeBean = _routeBeanService.getRouteForId(routeId);
TripNarrative tripNarrative = _narrativeService.getTripForId(tripId);
TripBean tripBean = new TripBean();
tripBean.setId(ApplicationBeanLibrary.getId(tripId));
tripBean.setTripShortName(tripNarrative.getTripShortName());
tripBean.setTripHeadsign(tripNarrative.getTripHeadsign());
tripBean.setRoute(routeBean);
tripBean.setRouteShortName(tripNarrative.getRouteShortName());
tripBean.setServiceId(ApplicationBeanLibrary.getId(tripEntry.getServiceId().getId()));
AgencyAndId shapeId = tripEntry.getShapeId();
if (shapeId != null && shapeId.hasValues())
tripBean.setShapeId(ApplicationBeanLibrary.getId(shapeId));
tripBean.setDirectionId(tripEntry.getDirectionId());
tripBean.setTotalTripDistance(tripEntry.getTotalTripDistance());
BlockEntry block = tripEntry.getBlock();
tripBean.setBlockId(ApplicationBeanLibrary.getId(block.getId()));
return tripBean;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getTripEntryAndBlockLocationAsTripDetails.
private TripDetailsBean getTripEntryAndBlockLocationAsTripDetails(BlockTripInstance blockTripInstance, BlockLocation blockLocation, TripDetailsInclusionBean inclusion, long time) {
TripBean trip = null;
long serviceDate = blockTripInstance.getServiceDate();
FrequencyBean frequency = null;
TripStopTimesBean stopTimes = null;
TripStatusBean status = null;
AgencyAndId vehicleId = null;
boolean missing = false;
FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
frequency = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
}
BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
TripEntry tripEntry = blockTrip.getTrip();
if (inclusion.isIncludeTripBean()) {
trip = _tripBeanService.getTripForId(tripEntry.getId());
if (trip == null)
missing = true;
}
if (inclusion.isIncludeTripSchedule()) {
stopTimes = _tripStopTimesBeanService.getStopTimesForBlockTrip(blockTripInstance);
if (stopTimes == null)
missing = true;
}
if (inclusion.isIncludeTripStatus() && blockLocation != null) {
status = getBlockLocationAsStatusBean(blockLocation, time);
if (status == null)
missing = true;
else
vehicleId = AgencyAndIdLibrary.convertFromString(status.getVehicleId());
}
List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, blockTripInstance, vehicleId);
if (missing)
return null;
String tripId = AgencyAndIdLibrary.convertToString(tripEntry.getId());
TripDetailsBean bean = new TripDetailsBean();
bean.setTripId(tripId);
bean.setServiceDate(serviceDate);
bean.setFrequency(frequency);
bean.setTrip(trip);
bean.setSchedule(stopTimes);
bean.setStatus(status);
bean.setSituations(situations);
return bean;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getTripsForId.
@Override
public ListBean<TripDetailsBean> getTripsForId(TripDetailsQueryBean query) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(query.getTripId());
long serviceDate = query.getServiceDate();
AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(query.getVehicleId());
long time = query.getTime();
TripEntry tripEntry = _transitGraphDao.getTripEntryForId(tripId);
if (tripEntry == null)
return new ListBean<TripDetailsBean>();
Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(tripEntry.getBlock().getId(), serviceDate, vehicleId, time);
List<TripDetailsBean> tripDetails = new ArrayList<TripDetailsBean>();
for (Map.Entry<BlockInstance, List<BlockLocation>> entry : locationsByInstance.entrySet()) {
BlockInstance blockInstance = entry.getKey();
List<BlockLocation> locations = entry.getValue();
BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstance, tripId);
if (blockTripInstance == null)
throw new IllegalStateException("expected blockTrip for trip=" + tripEntry + " and block=" + blockInstance);
/**
* If we have no locations for the specified block instance, it means the
* block is not currently active. But we can still attempt to construct a
* trip details
*/
if (locations.isEmpty()) {
TripDetailsBean details = getTripEntryAndBlockLocationAsTripDetails(blockTripInstance, null, query.getInclusion(), time);
tripDetails.add(details);
} else {
for (BlockLocation location : locations) {
TripDetailsBean details = getBlockLocationAsTripDetails(blockTripInstance, location, query.getInclusion(), time);
tripDetails.add(details);
}
}
}
return new ListBean<TripDetailsBean>(tripDetails, false);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockGeospatialServiceImpl method groupBlockSequenceIndicesByShapeIds.
/**
**
* Private Methods
***
*/
private void groupBlockSequenceIndicesByShapeIds() {
List<BlockSequenceIndex> indices = _blockIndexService.getAllBlockSequenceIndices();
for (BlockSequenceIndex index : indices) {
Set<AgencyAndId> shapeIdsForIndex = new HashSet<AgencyAndId>();
for (BlockSequence sequence : index.getSequences()) {
for (BlockStopTimeEntry bst : sequence.getStopTimes()) {
BlockTripEntry blockTrip = bst.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId shapeId = trip.getShapeId();
if (shapeId != null)
shapeIdsForIndex.add(shapeId);
}
}
for (AgencyAndId shapeId : shapeIdsForIndex) {
List<BlockSequenceIndex> list = _blockSequenceIndicesByShapeId.get(shapeId);
if (list == null) {
list = new ArrayList<BlockSequenceIndex>();
_blockSequenceIndicesByShapeId.put(shapeId, list);
}
list.add(index);
}
}
}
Aggregations