Search in sources :

Example 1 with ServiceAlertLocalizedString

use of org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertLocalizedString in project onebusaway-application-modules by camsys.

the class GtfsRealtimeServiceImpl method getAlerts.

@Override
public FeedMessage getAlerts() {
    FeedMessage.Builder feedMessage = createFeedWithDefaultHeader();
    List<ServiceAlertRecord> serviceAlerts = _serviceAlertsService.getAllServiceAlerts();
    for (ServiceAlertRecord serviceAlert : serviceAlerts) {
        Alert.Builder alert = Alert.newBuilder();
        if (serviceAlert.getSummaries() != null) {
            for (ServiceAlertLocalizedString string : serviceAlert.getSummaries()) {
                TranslatedString translated = convertTranslatedString(string);
                alert.setHeaderText(translated);
            }
        }
        if (serviceAlert.getDescriptions() != null) {
            for (ServiceAlertLocalizedString string : serviceAlert.getDescriptions()) {
                TranslatedString translated = convertTranslatedString(string);
                alert.setDescriptionText(translated);
            }
        }
        for (ServiceAlertTimeRange range : serviceAlert.getActiveWindows()) {
            com.google.transit.realtime.GtfsRealtime.TimeRange.Builder timeRange = com.google.transit.realtime.GtfsRealtime.TimeRange.newBuilder();
            if (range.getFromValue() != null)
                timeRange.setStart(range.getFromValue());
            if (range.getToValue() != null)
                timeRange.setEnd(range.getToValue());
            alert.addActivePeriod(timeRange);
        }
        /**
         * What does this situation affect?
         */
        for (ServiceAlertsSituationAffectsClause affects : serviceAlert.getAllAffects()) {
            EntitySelector.Builder entitySelector = EntitySelector.newBuilder();
            if (affects.getAgencyId() != null)
                entitySelector.setAgencyId(affects.getAgencyId());
            if (affects.getRouteId() != null)
                entitySelector.setRouteId(id(serviceAlert.getAgencyId(), affects.getRouteId()));
            if (affects.getTripId() != null) {
                TripDescriptor.Builder trip = TripDescriptor.newBuilder();
                trip.setTripId(id(serviceAlert.getAgencyId(), affects.getTripId()));
                entitySelector.setTrip(trip);
            }
            if (affects.getStopId() != null)
                entitySelector.setStopId(id(serviceAlert.getAgencyId(), affects.getStopId()));
            alert.addInformedEntity(entitySelector);
        }
        FeedEntity.Builder feedEntity = FeedEntity.newBuilder();
        feedEntity.setAlert(alert);
        feedEntity.setId(id(serviceAlert.getAgencyId(), serviceAlert.getServiceAlertId()));
        feedMessage.addEntity(feedEntity);
    }
    return feedMessage.build();
}
Also used : ServiceAlertsSituationAffectsClause(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertsSituationAffectsClause) ServiceAlertLocalizedString(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertLocalizedString) ServiceAlertRecord(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertRecord) ServiceAlertTimeRange(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertTimeRange) ServiceAlertTimeRange(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertTimeRange)

Example 2 with ServiceAlertLocalizedString

use of org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertLocalizedString in project onebusaway-application-modules by camsys.

the class GtfsRealtimeSource method handleAlerts.

private void handleAlerts(FeedMessage alerts) {
    for (FeedEntity entity : alerts.getEntityList()) {
        Alert alert = entity.getAlert();
        if (alert == null) {
            _log.warn("epxected a FeedEntity with an Alert");
            continue;
        }
        AgencyAndId id = createId(entity.getId());
        if (entity.getIsDeleted()) {
            _alertsById.remove(id);
            _serviceAlertService.removeServiceAlert(id);
        } else {
            ServiceAlert.Builder serviceAlertBuilder = _alertLibrary.getAlertAsServiceAlert(id, alert, _alertAgencyIdMap);
            ServiceAlert serviceAlert = serviceAlertBuilder.build();
            ServiceAlert existingAlert = _alertsById.get(id);
            if (existingAlert == null || !existingAlert.equals(serviceAlert)) {
                _alertsById.put(id, serviceAlert);
                ServiceAlertRecord serviceAlertRecord = new ServiceAlertRecord();
                serviceAlertRecord.setAgencyId(_agencyIds.get(0));
                serviceAlertRecord.setActiveWindows(new HashSet<ServiceAlertTimeRange>());
                if (serviceAlert.getActiveWindowList() != null) {
                    for (ServiceAlerts.TimeRange timeRange : serviceAlert.getActiveWindowList()) {
                        ServiceAlertTimeRange serviceAlertTimeRange = new ServiceAlertTimeRange();
                        serviceAlertTimeRange.setFromValue(timeRange.getStart());
                        serviceAlertTimeRange.setToValue(timeRange.getEnd());
                        serviceAlertRecord.getActiveWindows().add(serviceAlertTimeRange);
                    }
                }
                serviceAlertRecord.setAllAffects(new HashSet<ServiceAlertsSituationAffectsClause>());
                if (serviceAlert.getAffectsList() != null) {
                    for (ServiceAlerts.Affects affects : serviceAlertBuilder.getAffectsList()) {
                        ServiceAlertsSituationAffectsClause serviceAlertsSituationAffectsClause = new ServiceAlertsSituationAffectsClause();
                        serviceAlertsSituationAffectsClause.setAgencyId(affects.getAgencyId());
                        serviceAlertsSituationAffectsClause.setApplicationId(affects.getApplicationId());
                        serviceAlertsSituationAffectsClause.setDirectionId(affects.getDirectionId());
                        serviceAlertsSituationAffectsClause.setRouteId(affects.getRouteId().getId());
                        serviceAlertsSituationAffectsClause.setStopId(affects.getStopId().getId());
                        serviceAlertsSituationAffectsClause.setTripId(affects.getTripId().getId());
                        serviceAlertRecord.getAllAffects().add(serviceAlertsSituationAffectsClause);
                    }
                }
                serviceAlertRecord.setCause(getECause(serviceAlert.getCause()));
                serviceAlertRecord.setConsequences(new HashSet<ServiceAlertSituationConsequenceClause>());
                if (serviceAlert.getConsequenceList() != null) {
                    for (ServiceAlerts.Consequence consequence : serviceAlert.getConsequenceList()) {
                        ServiceAlertSituationConsequenceClause serviceAlertSituationConsequenceClause = new ServiceAlertSituationConsequenceClause();
                        serviceAlertSituationConsequenceClause.setDetourPath(consequence.getDetourPath());
                        serviceAlertSituationConsequenceClause.setDetourStopIds(new HashSet<String>());
                        if (consequence.getDetourStopIdsList() != null) {
                            for (ServiceAlerts.Id stopId : consequence.getDetourStopIdsList()) {
                                serviceAlertSituationConsequenceClause.getDetourStopIds().add(stopId.getId());
                            }
                        }
                        serviceAlertRecord.getConsequences().add(serviceAlertSituationConsequenceClause);
                    }
                }
                serviceAlertRecord.setCreationTime(serviceAlert.getCreationTime());
                serviceAlertRecord.setDescriptions(new HashSet<ServiceAlertLocalizedString>());
                if (serviceAlert.getDescription() != null) {
                    for (ServiceAlerts.TranslatedString.Translation translation : serviceAlert.getDescription().getTranslationList()) {
                        ServiceAlertLocalizedString string = new ServiceAlertLocalizedString();
                        string.setValue(translation.getText());
                        string.setLanguage(translation.getLanguage());
                        serviceAlertRecord.getDescriptions().add(string);
                    }
                }
                serviceAlertRecord.setModifiedTime(serviceAlert.getModifiedTime());
                serviceAlertRecord.setPublicationWindows(new HashSet<ServiceAlertTimeRange>());
                serviceAlertRecord.setServiceAlertId(serviceAlert.getId().getId());
                serviceAlertRecord.setSeverity(getESeverity(serviceAlert.getSeverity()));
                serviceAlertRecord.setSummaries(new HashSet<ServiceAlertLocalizedString>());
                if (serviceAlert.getSummary() != null) {
                    for (ServiceAlerts.TranslatedString.Translation translation : serviceAlert.getSummary().getTranslationList()) {
                        ServiceAlertLocalizedString string = new ServiceAlertLocalizedString();
                        string.setValue(translation.getText());
                        string.setLanguage(translation.getLanguage());
                        serviceAlertRecord.getSummaries().add(string);
                    }
                }
                serviceAlertRecord.setUrls(new HashSet<ServiceAlertLocalizedString>());
                if (serviceAlert.getUrl() != null) {
                    for (ServiceAlerts.TranslatedString.Translation translation : serviceAlert.getUrl().getTranslationList()) {
                        ServiceAlertLocalizedString string = new ServiceAlertLocalizedString();
                        string.setValue(translation.getText());
                        string.setLanguage(translation.getLanguage());
                        serviceAlertRecord.getUrls().add(string);
                    }
                }
                _serviceAlertService.createOrUpdateServiceAlert(serviceAlertRecord);
            }
        }
    }
}
Also used : ServiceAlertsSituationAffectsClause(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertsSituationAffectsClause) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceAlerts(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts) ServiceAlertLocalizedString(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertLocalizedString) ServiceAlertRecord(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertRecord) ServiceAlertTimeRange(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertTimeRange) ServiceAlertLocalizedString(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertLocalizedString) ServiceAlert(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert) ServiceAlert(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert) Alert(com.google.transit.realtime.GtfsRealtime.Alert) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) ServiceAlertSituationConsequenceClause(org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertSituationConsequenceClause)

Aggregations

ServiceAlertLocalizedString (org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertLocalizedString)2 ServiceAlertRecord (org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertRecord)2 ServiceAlertTimeRange (org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertTimeRange)2 ServiceAlertsSituationAffectsClause (org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertsSituationAffectsClause)2 Alert (com.google.transit.realtime.GtfsRealtime.Alert)1 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ServiceAlertSituationConsequenceClause (org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertSituationConsequenceClause)1 ServiceAlerts (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts)1 ServiceAlert (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert)1