Search in sources :

Example 11 with SituationAffectsBean

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

the class ServiceAlertsTestSupport method addAffects.

public static SituationAffectsBean addAffects(String route, String direction) {
    SituationAffectsBean sab = new SituationAffectsBean();
    sab.setRouteId(route);
    sab.setDirectionId(direction);
    return sab;
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)

Example 12 with SituationAffectsBean

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

the class BeanFactoryV2 method isSituationExcludedForApplication.

public boolean isSituationExcludedForApplication(ServiceAlertBean situation) {
    List<SituationAffectsBean> affects = situation.getAllAffects();
    if (affects == null)
        return false;
    Set<String> applicationIds = new HashSet<String>();
    for (SituationAffectsBean affect : affects) {
        if (affect.getApplicationId() != null)
            applicationIds.add(affect.getApplicationId());
    }
    if (CollectionsLibrary.isEmpty(applicationIds))
        return false;
    if (_applicationKey == null)
        return true;
    return !_applicationKey.contains(_applicationKey);
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) HashSet(java.util.HashSet)

Example 13 with SituationAffectsBean

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

the class ServiceAlertAffectsAction method update.

public String update() throws IOException, JSONException {
    if (_id == null || _index == -1) {
        return INPUT;
    }
    ServiceAlertBean alert = null;
    try {
        alert = _transitDataService.getServiceAlertForId(_id);
    } catch (RuntimeException e) {
        _log.error("Error retrieving Service Alerts", e);
        throw e;
    }
    if (alert == null) {
        return INPUT;
    }
    List<SituationAffectsBean> allAffects = alert.getAllAffects();
    if (allAffects == null || _index >= allAffects.size()) {
        return INPUT;
    }
    _model.setAgencyId(string(_model.getAgencyId()));
    _model.setRouteId(string(_model.getRouteId()));
    _model.setDirectionId(string(_model.getDirectionId()));
    _model.setTripId(string(_model.getTripId()));
    _model.setStopId(string(_model.getStopId()));
    allAffects.set(_index, _model);
    try {
        _transitDataService.updateServiceAlert(alert);
    } catch (RuntimeException e) {
        _log.error("Error updating Service Alert Affects clause", e);
        throw e;
    }
    return SUCCESS;
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 14 with SituationAffectsBean

use of org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean 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 15 with SituationAffectsBean

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

the class AlertsAction method fillSituationAffects.

private void fillSituationAffects(Alert.Builder alert, List<SituationAffectsBean> affectsList) {
    for (SituationAffectsBean affects : affectsList) {
        EntitySelector.Builder entitySelector = EntitySelector.newBuilder();
        if (affects.getAgencyId() != null)
            entitySelector.setAgencyId(affects.getAgencyId());
        if (affects.getRouteId() != null) {
            entitySelector.setRouteId(id(agencyId, sanitize(affects.getRouteId())));
        }
        if (affects.getTripId() != null) {
            TripDescriptor.Builder trip = TripDescriptor.newBuilder();
            trip.setTripId(id(agencyId, sanitize(affects.getTripId())));
            entitySelector.setTrip(trip);
        }
        if (affects.getStopId() != null)
            entitySelector.setStopId(id(agencyId, sanitize(affects.getStopId())));
        alert.addInformedEntity(entitySelector);
    }
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)

Aggregations

SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)15 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)6 ArrayList (java.util.ArrayList)5 NaturalLanguageStringBean (org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean)3 TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)3 Alert (com.google.transit.realtime.GtfsRealtime.Alert)2 EntitySelector (com.google.transit.realtime.GtfsRealtime.EntitySelector)2 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)2 TimeRange (com.google.transit.realtime.GtfsRealtime.TimeRange)2 Test (org.junit.Test)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)1 TranslatedString (com.google.transit.realtime.GtfsRealtime.TranslatedString)1 Translation (com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation)1 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 NotificationServiceImpl (org.onebusaway.admin.service.impl.NotificationServiceImpl)1 ResponseBean (org.onebusaway.api.model.ResponseBean)1 SituationAffectsV2Bean (org.onebusaway.api.model.transit.service_alerts.SituationAffectsV2Bean)1