Search in sources :

Example 26 with ServiceAlertBean

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

the class BeanFactoryV2 method getTripDetails.

public TripDetailsV2Bean getTripDetails(TripDetailsBean tripDetails) {
    TripDetailsV2Bean bean = new TripDetailsV2Bean();
    bean.setTripId(tripDetails.getTripId());
    bean.setServiceDate(tripDetails.getServiceDate());
    if (tripDetails.getFrequency() != null)
        bean.setFrequency(getFrequency(tripDetails.getFrequency()));
    TripBean trip = tripDetails.getTrip();
    if (trip != null)
        addToReferences(trip);
    TripStopTimesBean stopTimes = tripDetails.getSchedule();
    if (stopTimes != null)
        bean.setSchedule(getTripStopTimes(stopTimes));
    TripStatusBean status = tripDetails.getStatus();
    if (status != null)
        bean.setStatus(getTripStatus(status));
    List<ServiceAlertBean> situations = tripDetails.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            addToReferences(situation);
            situationIds.add(situation.getId());
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean)

Example 27 with ServiceAlertBean

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

the class BeanFactoryV2 method getArrivalAndDeparture.

public ArrivalAndDepartureV2Bean getArrivalAndDeparture(ArrivalAndDepartureBean ad) {
    TripBean trip = ad.getTrip();
    RouteBean route = trip.getRoute();
    StopBean stop = ad.getStop();
    ArrivalAndDepartureV2Bean bean = new ArrivalAndDepartureV2Bean();
    bean.setTripId(trip.getId());
    addToReferences(trip);
    bean.setServiceDate(ad.getServiceDate());
    bean.setVehicleId(ad.getVehicleId());
    bean.setStopId(stop.getId());
    addToReferences(stop);
    bean.setStopSequence(ad.getStopSequence());
    bean.setBlockTripSequence(ad.getBlockTripSequence());
    bean.setTotalStopsInTrip(ad.getTotalStopsInTrip());
    bean.setRouteId(route.getId());
    addToReferences(route);
    String routeShortName = ad.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
        routeShortName = trip.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
        routeShortName = route.getShortName();
    bean.setRouteShortName(routeShortName);
    bean.setRouteLongName(route.getLongName());
    String tripHeadsign = ad.getTripHeadsign();
    if (tripHeadsign == null || tripHeadsign.isEmpty())
        tripHeadsign = trip.getTripHeadsign();
    bean.setTripHeadsign(tripHeadsign);
    bean.setArrivalEnabled(ad.isArrivalEnabled());
    bean.setDepartureEnabled(ad.isDepartureEnabled());
    bean.setScheduledArrivalTime(ad.getScheduledArrivalTime());
    bean.setScheduledDepartureTime(ad.getScheduledDepartureTime());
    bean.setPredictedArrivalTime(ad.getPredictedArrivalTime());
    bean.setPredictedDepartureTime(ad.getPredictedDepartureTime());
    bean.setScheduledArrivalInterval(getTimeInterval(ad.getScheduledArrivalInterval()));
    bean.setScheduledDepartureInterval(getTimeInterval(ad.getScheduledDepartureInterval()));
    bean.setPredictedArrivalInterval(getTimeInterval(ad.getPredictedArrivalInterval()));
    bean.setPredictedDepartureInterval(getTimeInterval(ad.getPredictedDepartureInterval()));
    if (ad.getFrequency() != null)
        bean.setFrequency(getFrequency(ad.getFrequency()));
    bean.setStatus(ad.getStatus());
    if (ad.isDistanceFromStopSet())
        bean.setDistanceFromStop(ad.getDistanceFromStop());
    bean.setNumberOfStopsAway(ad.getNumberOfStopsAway());
    TripStatusBean tripStatus = ad.getTripStatus();
    if (tripStatus != null)
        bean.setTripStatus(getTripStatus(tripStatus));
    bean.setPredicted(ad.isPredicted());
    bean.setLastUpdateTime(ad.getLastUpdateTime());
    List<ServiceAlertBean> situations = ad.getSituations();
    if (situations != null && !situations.isEmpty()) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            situationIds.add(situation.getId());
            addToReferences(situation);
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 28 with ServiceAlertBean

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

the class AlertsForAgencyAction method fillFeedMessage.

@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
    ListBean<ServiceAlertBean> alerts = _service.getAllServiceAlertsForAgencyId(agencyId);
    for (ServiceAlertBean serviceAlert : alerts.getList()) {
        FeedEntity.Builder entity = feed.addEntityBuilder();
        entity.setId(Integer.toString(feed.getEntityCount()));
        Alert.Builder alert = entity.getAlertBuilder();
        fillTranslations(serviceAlert.getSummaries(), alert.getHeaderTextBuilder());
        fillTranslations(serviceAlert.getDescriptions(), alert.getDescriptionTextBuilder());
        if (serviceAlert.getActiveWindows() != null) {
            for (TimeRangeBean range : serviceAlert.getActiveWindows()) {
                TimeRange.Builder timeRange = alert.addActivePeriodBuilder();
                if (range.getFrom() != 0) {
                    timeRange.setStart(range.getFrom() / 1000);
                }
                if (range.getTo() != 0) {
                    timeRange.setEnd(range.getTo() / 1000);
                }
            }
        }
        if (serviceAlert.getAllAffects() != null) {
            for (SituationAffectsBean affects : serviceAlert.getAllAffects()) {
                EntitySelector.Builder entitySelector = alert.addInformedEntityBuilder();
                if (affects.getAgencyId() != null) {
                    entitySelector.setAgencyId(affects.getAgencyId());
                }
                if (affects.getRouteId() != null) {
                    entitySelector.setRouteId(normalizeId(affects.getRouteId()));
                }
                if (affects.getTripId() != null) {
                    TripDescriptor.Builder trip = entitySelector.getTripBuilder();
                    trip.setTripId(normalizeId(affects.getTripId()));
                    entitySelector.setTrip(trip);
                }
                if (affects.getStopId() != null) {
                    AgencyAndId stopId = modifiedStopId(agencyId, affects.getStopId());
                    if (stopId.getAgencyId().equals(agencyId)) {
                        entitySelector.setStopId(normalizeId(stopId.toString()));
                    }
                }
            }
        }
    }
}
Also used : EntitySelector(com.google.transit.realtime.GtfsRealtime.EntitySelector) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) TimeRange(com.google.transit.realtime.GtfsRealtime.TimeRange) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) Alert(com.google.transit.realtime.GtfsRealtime.Alert) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity)

Example 29 with ServiceAlertBean

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

the class RealtimeServiceImpl method getServiceAlertsForRouteAndDirection.

@Override
public List<ServiceAlertBean> getServiceAlertsForRouteAndDirection(String routeId, String directionId) {
    SituationQueryBean query = new SituationQueryBean();
    SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
    query.getAffects().add(affects);
    affects.setRouteId(routeId);
    if (directionId != null) {
        affects.setDirectionId(directionId);
    } else {
        /*
       * TODO
       * The route index is not currently being populated correctly; query by route and direction,
       * and supply both directions if not present
       */
        SituationQueryBean.AffectsBean affects1 = new SituationQueryBean.AffectsBean();
        query.getAffects().add(affects1);
        affects1.setRouteId(routeId);
        affects1.setDirectionId("0");
        SituationQueryBean.AffectsBean affects2 = new SituationQueryBean.AffectsBean();
        query.getAffects().add(affects2);
        affects2.setRouteId(routeId);
        affects2.setDirectionId("1");
    }
    ListBean<ServiceAlertBean> serviceAlerts = _transitDataService.getServiceAlerts(query);
    return serviceAlerts.getList();
}
Also used : SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 30 with ServiceAlertBean

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

the class SiriSupport method fillSituations.

private static void fillSituations(MonitoredVehicleJourneyStructure monitoredVehicleJourney, TripStatusBean tripStatus) {
    if (tripStatus == null || tripStatus.getSituations() == null || tripStatus.getSituations().isEmpty()) {
        return;
    }
    List<SituationRefStructure> situationRef = monitoredVehicleJourney.getSituationRef();
    for (ServiceAlertBean situation : tripStatus.getSituations()) {
        SituationRefStructure sitRef = new SituationRefStructure();
        SituationSimpleRefStructure sitSimpleRef = new SituationSimpleRefStructure();
        sitSimpleRef.setValue(situation.getId());
        sitRef.setSituationSimpleRef(sitSimpleRef);
        situationRef.add(sitRef);
    }
}
Also used : SituationRefStructure(uk.org.siri.siri.SituationRefStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) SituationSimpleRefStructure(uk.org.siri.siri.SituationSimpleRefStructure)

Aggregations

ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)54 ArrayList (java.util.ArrayList)22 SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)11 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)8 StopBean (org.onebusaway.transit_data.model.StopBean)8 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)8 HashMap (java.util.HashMap)7 List (java.util.List)5 RouteBean (org.onebusaway.transit_data.model.RouteBean)5 TripBean (org.onebusaway.transit_data.model.trips.TripBean)5 Test (org.junit.Test)4 NaturalLanguageStringBean (org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean)4 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)4 PtSituationElementStructure (uk.org.siri.siri.PtSituationElementStructure)4 PtSituationElementStructure (uk.org.siri.siri_2.PtSituationElementStructure)4 HashSet (java.util.HashSet)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)3 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)3 TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)3