Search in sources :

Example 1 with ListBean

use of org.onebusaway.transit_data.model.ListBean 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);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 2 with ListBean

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

the class TripStatusBeanServiceImpl method getBlockLocationsAsTripDetails.

/**
 **
 * Private Methods
 ***
 */
private ListBean<TripDetailsBean> getBlockLocationsAsTripDetails(List<BlockLocation> locations, TripDetailsInclusionBean inclusion, long time) {
    List<TripDetailsBean> tripDetails = new ArrayList<TripDetailsBean>();
    for (BlockLocation location : locations) {
        TripDetailsBean details = getBlockLocationAsTripDetails(location.getActiveTripInstance(), location, inclusion, time);
        tripDetails.add(details);
    }
    return new ListBean<TripDetailsBean>(tripDetails, false);
}
Also used : ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 3 with ListBean

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

the class VehicleStatusBeanServiceImpl method getAllVehiclesForAgency.

@Override
public ListBean<VehicleStatusBean> getAllVehiclesForAgency(String agencyId, long time) {
    List<VehicleStatus> statuses = _vehicleStatusService.getAllVehicleStatuses();
    List<VehicleStatusBean> beans = new ArrayList<VehicleStatusBean>();
    for (VehicleStatus status : statuses) {
        AgencyAndId vid = status.getVehicleId();
        if (!vid.getAgencyId().equals(agencyId))
            continue;
        VehicleStatusBean bean = getStatusAsBean(status, time);
        beans.add(bean);
    }
    return new ListBean<VehicleStatusBean>(beans, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) VehicleStatus(org.onebusaway.transit_data_federation.services.realtime.VehicleStatus) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean)

Example 4 with ListBean

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

the class VehicleStatusBeanServiceImpl method getVehicleLocations.

@Override
public ListBean<VehicleLocationRecordBean> getVehicleLocations(VehicleLocationRecordQueryBean query) {
    AgencyAndId blockId = AgencyAndIdLibrary.convertFromString(query.getBlockId());
    AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(query.getTripId());
    AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(query.getVehicleId());
    List<BlockLocationRecord> records = _blockLocationRecordDao.getBlockLocationRecords(blockId, tripId, vehicleId, query.getServiceDate(), query.getFromTime(), query.getToTime(), 1000);
    List<VehicleLocationRecordBean> beans = new ArrayList<VehicleLocationRecordBean>(records.size());
    for (BlockLocationRecord record : records) {
        VehicleLocationRecordBean bean = getBlockLocationRecordAsVehicleLocationRecord(record);
        beans.add(bean);
    }
    return new ListBean<VehicleLocationRecordBean>(beans, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockLocationRecord(org.onebusaway.transit_data_federation.impl.realtime.BlockLocationRecord) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) VehicleLocationRecordBean(org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)

Example 5 with ListBean

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

the class RoutesBeanServiceImpl method getRoutesForAgencyId.

@Cacheable
@Override
public ListBean<RouteBean> getRoutesForAgencyId(String agencyId) {
    AgencyEntry agency = _graphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<RouteBean> routes = new ArrayList<RouteBean>();
    for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
        AgencyAndId routeId = routeCollection.getId();
        RouteBean route = _routeBeanService.getRouteForId(routeId);
        routes.add(route);
    }
    return new ListBean<RouteBean>(routes, false);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Aggregations

ArrayList (java.util.ArrayList)17 ListBean (org.onebusaway.transit_data.model.ListBean)17 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)5 Date (java.util.Date)4 List (java.util.List)4 Test (org.junit.Test)4 RouteBean (org.onebusaway.transit_data.model.RouteBean)4 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)3 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)3 IOException (java.io.IOException)3 ResponseBean (org.onebusaway.api.model.ResponseBean)3 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)3 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)3 Map (java.util.Map)2 T2 (org.onebusaway.collections.tuple.T2)2 Cacheable (org.onebusaway.container.cache.Cacheable)2 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)2 TripBean (org.onebusaway.transit_data.model.trips.TripBean)2 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)2