Search in sources :

Example 51 with ServiceAlertBean

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

the class NotifyResourceTest method testToTweet.

@Test
public void testToTweet() {
    ServiceAlertBean bean = null;
    NotificationServiceImpl nsi = new NotificationServiceImpl();
    NotificationStrategy ns = new TestNotificationStrategy();
    nsi.setNotificationStrategy(ns);
    NotifyResource resource = new NotifyResource();
    resource.setNotificationService(nsi);
    assertNull(resource.toTweet(bean));
    bean = new ServiceAlertBean();
    assertNull(resource.toTweet(bean));
    bean.setSummaries(new ArrayList<NaturalLanguageStringBean>());
    bean.getSummaries().add(createNLS("Snow Routes in Affect"));
    // service alert has no affects clause, nothing to do
    assertEquals(null, resource.toTweet(bean));
    SituationAffectsBean affects = new SituationAffectsBean();
    affects.setAgencyId("ACTA");
    bean.setAllAffects(new ArrayList<SituationAffectsBean>());
    bean.getAllAffects().add(affects);
    // we don't include agency in tweet -- it will be obvious from the twitter handle
    assertEquals("Snow Routes in Affect", resource.toTweet(bean));
    // add a single route
    affects.setRouteId("A1");
    assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1", resource.toTweet(bean));
    // add a stop
    affects = new SituationAffectsBean();
    affects.setAgencyId("ACTA");
    bean.getAllAffects().add(affects);
    affects.setStopId("Water and Blowers");
    try {
        assertEquals("Snow Routes in Affect affecting route(s) A1 and stop(s) Water and Blowers", resource.toTweet(bean));
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException iae) {
    // pass
    }
    affects.setStopId("ACTA_6968");
    assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1 and stop(s) ACTA_6968", resource.toTweet(bean));
    // add another route
    affects = new SituationAffectsBean();
    affects.setAgencyId("ACTA");
    bean.getAllAffects().add(affects);
    affects.setRouteId("B2");
    assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1, ACTA_B2 and stop(s) ACTA_6968", resource.toTweet(bean));
    // add another stop
    affects = new SituationAffectsBean();
    affects.setAgencyId("ACTA");
    bean.getAllAffects().add(affects);
    affects.setStopId("ACTA_4370");
    assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1, ACTA_B2 and stop(s) ACTA_6968, ACTA_4370", resource.toTweet(bean));
    // clear out routes, add a single stop
    affects = new SituationAffectsBean();
    affects.setAgencyId("ACTA");
    bean.setAllAffects(new ArrayList<SituationAffectsBean>());
    bean.getAllAffects().add(affects);
    affects.setStopId("ACTA_4370");
    assertEquals("Snow Routes in Affect affecting stop(s) ACTA_4370", resource.toTweet(bean));
    // add another stop
    affects = new SituationAffectsBean();
    affects.setAgencyId("ACTA");
    bean.getAllAffects().add(affects);
    affects.setStopId("ACTA_6968");
    assertEquals("Snow Routes in Affect affecting stop(s) ACTA_4370, ACTA_6968", resource.toTweet(bean));
// we don't support trip level tweets
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) NaturalLanguageStringBean(org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) NotificationStrategy(org.onebusaway.presentation.impl.service_alerts.NotificationStrategy) NotificationServiceImpl(org.onebusaway.admin.service.impl.NotificationServiceImpl) Test(org.junit.Test)

Example 52 with ServiceAlertBean

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

the class AlertsAction method getModel.

@Override
public FeedMessage getModel() {
    FeedMessage cachedAlerts = _cache.getAlerts();
    if (cachedAlerts != null) {
        return cachedAlerts;
    } else {
        FeedMessage.Builder feedMessage = createFeedWithDefaultHeader();
        List<String> agencyIds = new ArrayList<String>();
        if (agencyId != null) {
            agencyIds.add(agencyId);
        } else {
            Map<String, List<CoordinateBounds>> agencies = _transitDataService.getAgencyIdsWithCoverageArea();
            agencyIds.addAll(agencies.keySet());
        }
        for (String agencyId : agencyIds) {
            ListBean<ServiceAlertBean> serviceAlertBeans = _transitDataService.getAllServiceAlertsForAgencyId(agencyId);
            for (ServiceAlertBean serviceAlert : serviceAlertBeans.getList()) {
                try {
                    Alert.Builder alert = Alert.newBuilder();
                    fillAlertHeader(alert, serviceAlert.getSummaries());
                    fillAlertDescriptions(alert, serviceAlert.getDescriptions());
                    fillActiveWindows(alert, serviceAlert.getActiveWindows());
                    fillSituationAffects(alert, serviceAlert.getAllAffects());
                    FeedEntity.Builder feedEntity = FeedEntity.newBuilder();
                    feedEntity.setAlert(alert);
                    feedEntity.setId(id(agencyId, serviceAlert.getId()));
                    feedMessage.addEntity(feedEntity);
                } catch (Exception e) {
                    _log.error("Unable to process service alert", e);
                }
            }
        }
        FeedMessage builtFeedMessage = feedMessage.build();
        _cache.putAlerts(builtFeedMessage);
        return builtFeedMessage;
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 53 with ServiceAlertBean

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

the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.

public StopWithArrivalsAndDeparturesBean getArrivalsAndDeparturesByStopId(AgencyAndId id, ArrivalsAndDeparturesQueryBean query) {
    StopBean stop = _stopBeanService.getStopForId(id);
    if (stop == null)
        return null;
    List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
    List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stop, 100);
    List<StopBean> nearbyStops = new ArrayList<StopBean>();
    for (AgencyAndId nearbyStopId : nearbyStopIds) nearbyStops.add(_stopBeanService.getStopForId(nearbyStopId));
    List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
    return new StopWithArrivalsAndDeparturesBean(stop, arrivalsAndDepartures, nearbyStops, situations);
}
Also used : StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Example 54 with ServiceAlertBean

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

the class TripStatusBeanServiceImpl method getBlockLocationAsStatusBean.

@Override
public TripStatusBean getBlockLocationAsStatusBean(BlockLocation blockLocation, long time) {
    TripStatusBean bean = new TripStatusBean();
    bean.setStatus("default");
    BlockInstance blockInstance = blockLocation.getBlockInstance();
    long serviceDate = blockInstance.getServiceDate();
    bean.setServiceDate(serviceDate);
    bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
    bean.setLastLocationUpdateTime(blockLocation.getLastLocationUpdateTime());
    bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
    bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
    bean.setLocation(blockLocation.getLocation());
    bean.setOrientation(blockLocation.getOrientation());
    bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
    if (blockLocation.isLastKnownOrientationSet())
        bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
    bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
    BlockTripInstance activeTripInstance = blockLocation.getActiveTripInstance();
    if (activeTripInstance != null) {
        BlockTripEntry activeBlockTrip = activeTripInstance.getBlockTrip();
        bean.setScheduledDistanceAlongTrip(blockLocation.getScheduledDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        bean.setDistanceAlongTrip(blockLocation.getDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        TripEntry activeTrip = activeBlockTrip.getTrip();
        bean.setTotalDistanceAlongTrip(activeTrip.getTotalTripDistance());
        TripBean activeTripBean = _tripBeanService.getTripForId(activeTrip.getId());
        bean.setActiveTrip(activeTripBean);
        bean.setBlockTripSequence(activeBlockTrip.getSequence());
        if (blockLocation.isLastKnownDistanceAlongBlockSet()) {
            bean.setLastKnownDistanceAlongTrip(blockLocation.getLastKnownDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        }
        FrequencyEntry frequencyLabel = activeTripInstance.getFrequencyLabel();
        if (frequencyLabel != null) {
            FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
            bean.setFrequency(fb);
        }
    } else {
        _log.warn("no active block trip for block location: blockInstance=" + blockLocation.getBlockInstance() + " time=" + time);
    }
    BlockStopTimeEntry closestStop = blockLocation.getClosestStop();
    if (closestStop != null) {
        StopTimeEntry stopTime = closestStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setClosestStop(stopBean);
        bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
    }
    BlockStopTimeEntry nextStop = blockLocation.getNextStop();
    if (nextStop != null) {
        StopTimeEntry stopTime = nextStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setNextStop(stopBean);
        bean.setNextStopTimeOffset(blockLocation.getNextStopTimeOffset());
        bean.setNextStopDistanceFromVehicle(blockLocation.getNextStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
    }
    BlockStopTimeEntry previousStop = blockLocation.getPreviousStop();
    if (previousStop != null) {
        StopTimeEntry stopTime = previousStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setPreviousStop(stopBean);
        bean.setPreviousStopTimeOffset(blockLocation.getPreviousStopTimeOffset());
        bean.setPreviousStopDistanceFromVehicle(blockLocation.getPreviousStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
    }
    EVehiclePhase phase = blockLocation.getPhase();
    if (phase != null)
        bean.setPhase(phase.toLabel());
    String status = blockLocation.getStatus();
    if (status != null)
        bean.setStatus(status);
    if (blockLocation.getVehicleType() != null)
        bean.setVehicleType(blockLocation.getVehicleType().toLabel());
    bean.setPredicted(blockLocation.isPredicted());
    AgencyAndId vid = blockLocation.getVehicleId();
    if (vid != null)
        bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
    if (activeTripInstance != null) {
        List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, activeTripInstance, blockLocation.getVehicleId());
        if (!situations.isEmpty())
            bean.setSituations(situations);
    }
    if (blockLocation.getTimepointPredictions() != null && blockLocation.getTimepointPredictions().size() > 0) {
        List<TimepointPredictionBean> timepointPredictions = new ArrayList<TimepointPredictionBean>();
        for (TimepointPredictionRecord tpr : blockLocation.getTimepointPredictions()) {
            TimepointPredictionBean tpb = new TimepointPredictionBean();
            tpb.setTimepointId(tpr.getTimepointId().toString());
            tpb.setTripId(tpr.getTripId().toString());
            tpb.setStopSequence(tpr.getStopSequence());
            tpb.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
            tpb.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
            timepointPredictions.add(tpb);
        }
        bean.setTimepointPredictions(timepointPredictions);
    }
    return bean;
}
Also used : TimepointPredictionBean(org.onebusaway.transit_data.model.trips.TimepointPredictionBean) BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) EVehiclePhase(org.onebusaway.realtime.api.EVehiclePhase) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

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