Search in sources :

Example 6 with EntitySelector

use of com.google.transit.realtime.GtfsRealtime.EntitySelector in project onebusaway-application-modules by camsys.

the class FeedServiceImplTest method createAlert.

private FeedEntity createAlert(String alertId, String header, String desc, Alert.Cause cause, Alert.Effect effect, String url, long startTime, long endTime, String agency, String route, String stop) {
    Alert.Builder alertBldr = Alert.newBuilder();
    // Header
    Translation translation = Translation.newBuilder().setLanguage("en").setText(header).build();
    TranslatedString trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
    alertBldr.setHeaderText(trnStr);
    // Description
    translation = Translation.newBuilder().setLanguage("en").setText(desc).build();
    trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
    alertBldr.setDescriptionText(trnStr);
    // Cause
    alertBldr.setCause(cause);
    // Effect
    alertBldr.setEffect(effect);
    // URL
    translation = Translation.newBuilder().setLanguage("en").setText(url).build();
    trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
    alertBldr.setUrl(trnStr);
    // Build TimeRangeEntity
    TimeRange timeRange = createTimeRange(startTime, endTime);
    alertBldr.addActivePeriod(timeRange);
    // Build EntitySelectorEntity
    EntitySelector entitySelector = createEntitySelector(agency, route, stop);
    alertBldr.addInformedEntity(entitySelector);
    FeedEntity.Builder alertEntity = FeedEntity.newBuilder();
    alertEntity.setId(alertId);
    alertEntity.setAlert(alertBldr.build());
    return alertEntity.build();
}
Also used : TranslatedString(com.google.transit.realtime.GtfsRealtime.TranslatedString) TimeRange(com.google.transit.realtime.GtfsRealtime.TimeRange) Translation(com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation) EntitySelector(com.google.transit.realtime.GtfsRealtime.EntitySelector) Alert(com.google.transit.realtime.GtfsRealtime.Alert) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity)

Example 7 with EntitySelector

use of com.google.transit.realtime.GtfsRealtime.EntitySelector in project onebusaway-application-modules by camsys.

the class GtfsRealtimeAlertLibrary method getAlertAsServiceAlert.

public ServiceAlert.Builder getAlertAsServiceAlert(AgencyAndId id, Alert alert, Map agencyIdMap) {
    ServiceAlert.Builder b = ServiceAlert.newBuilder();
    b.setCreationTime(SystemTime.currentTimeMillis());
    b.setModifiedTime(SystemTime.currentTimeMillis());
    b.setId(ServiceAlertLibrary.id(id));
    for (GtfsRealtime.TimeRange range : alert.getActivePeriodList()) {
        ServiceAlerts.TimeRange.Builder rangeBuilder = ServiceAlerts.TimeRange.newBuilder();
        if (range.hasStart())
            rangeBuilder.setStart(range.getStart());
        if (range.hasEnd())
            rangeBuilder.setEnd(range.getEnd());
        b.addActiveWindow(rangeBuilder);
    }
    if (alert.hasCause())
        b.setCause(convertCause(alert.getCause()));
    if (alert.hasHeaderText())
        b.setSummary(convertTranslatedString(alert.getHeaderText()));
    if (alert.hasDescriptionText())
        b.setDescription(convertTranslatedString(alert.getDescriptionText()));
    if (alert.hasEffect()) {
        Consequence.Builder consequence = Consequence.newBuilder();
        consequence.setEffect(convertEffect(alert.getEffect()));
        b.addConsequence(consequence);
    }
    for (EntitySelector selector : alert.getInformedEntityList()) {
        Affects.Builder affects = getEntitySelectorAsAffects(selector, agencyIdMap);
        b.addAffects(affects);
    }
    if (alert.hasUrl())
        b.setUrl(convertTranslatedString(alert.getUrl()));
    return b;
}
Also used : ServiceAlert(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert) EntitySelector(com.google.transit.realtime.GtfsRealtime.EntitySelector) Consequence(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Consequence) Affects(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Affects) GtfsRealtime(com.google.transit.realtime.GtfsRealtime)

Aggregations

EntitySelector (com.google.transit.realtime.GtfsRealtime.EntitySelector)7 Alert (com.google.transit.realtime.GtfsRealtime.Alert)5 TimeRange (com.google.transit.realtime.GtfsRealtime.TimeRange)5 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)3 TranslatedString (com.google.transit.realtime.GtfsRealtime.TranslatedString)3 Translation (com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation)3 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 Date (java.util.Date)2 Test (org.junit.Test)2 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)2 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)2 TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)2 Affects (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Affects)2 Consequence (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Consequence)2 ServiceAlert (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert)2 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)1 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)1 ArrayList (java.util.ArrayList)1 ResponseBean (org.onebusaway.api.model.ResponseBean)1