Search in sources :

Example 6 with SituationAffectsBean

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

the class ServiceAlertAffectsAction method delete.

public String delete() {
    if (_id == null || _index == -1) {
        return INPUT;
    }
    ServiceAlertBean alert = null;
    try {
        alert = _transitDataService.getServiceAlertForId(_id);
    } catch (RuntimeException e) {
        _log.error("Error retrieving Service Alert", e);
        throw e;
    }
    if (alert == null) {
        return INPUT;
    }
    List<SituationAffectsBean> allAffects = alert.getAllAffects();
    if (allAffects == null || _index >= allAffects.size()) {
        return INPUT;
    }
    allAffects.remove(_index);
    try {
        _transitDataService.updateServiceAlert(alert);
    } catch (RuntimeException e) {
        _log.error("Error removing 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 7 with SituationAffectsBean

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

the class BeanFactoryV2 method getSituation.

public SituationV2Bean getSituation(ServiceAlertBean situation) {
    SituationV2Bean bean = new SituationV2Bean();
    bean.setId(situation.getId());
    bean.setCreationTime(situation.getCreationTime());
    if (!CollectionsLibrary.isEmpty(situation.getActiveWindows())) {
        List<TimeRangeV2Bean> activeWindows = new ArrayList<TimeRangeV2Bean>();
        for (TimeRangeBean activeWindow : situation.getActiveWindows()) activeWindows.add(getTimeRange(activeWindow));
        bean.setActiveWindows(activeWindows);
    }
    if (!CollectionsLibrary.isEmpty(situation.getPublicationWindows())) {
        List<TimeRangeV2Bean> publicationWindows = new ArrayList<TimeRangeV2Bean>();
        for (TimeRangeBean publicationWindow : situation.getPublicationWindows()) publicationWindows.add(getTimeRange(publicationWindow));
        bean.setPublicationWindows(publicationWindows);
    }
    if (!CollectionsLibrary.isEmpty(situation.getAllAffects())) {
        List<SituationAffectsV2Bean> affects = new ArrayList<SituationAffectsV2Bean>();
        for (SituationAffectsBean affect : situation.getAllAffects()) affects.add(getSituationAffects(affect));
        bean.setAllAffects(affects);
    }
    if (!CollectionsLibrary.isEmpty(situation.getConsequences())) {
        List<SituationConsequenceV2Bean> beans = new ArrayList<SituationConsequenceV2Bean>();
        for (SituationConsequenceBean consequence : situation.getConsequences()) {
            SituationConsequenceV2Bean consequenceBean = getSituationConsequence(consequence);
            beans.add(consequenceBean);
        }
        bean.setConsequences(beans);
    }
    bean.setReason(situation.getReason());
    bean.setSummary(getBestString(situation.getSummaries()));
    bean.setDescription(getBestString(situation.getDescriptions()));
    bean.setUrl(getBestString(situation.getUrls()));
    ESeverity severity = situation.getSeverity();
    if (severity != null) {
        String[] codes = severity.getTpegCodes();
        bean.setSeverity(codes[0]);
    }
    return bean;
}
Also used : ArrayList(java.util.ArrayList) SituationConsequenceV2Bean(org.onebusaway.api.model.transit.service_alerts.SituationConsequenceV2Bean) ESeverity(org.onebusaway.transit_data.model.service_alerts.ESeverity) SituationAffectsV2Bean(org.onebusaway.api.model.transit.service_alerts.SituationAffectsV2Bean) SituationV2Bean(org.onebusaway.api.model.transit.service_alerts.SituationV2Bean) TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) TimeRangeV2Bean(org.onebusaway.api.model.transit.service_alerts.TimeRangeV2Bean) SituationConsequenceBean(org.onebusaway.transit_data.model.service_alerts.SituationConsequenceBean)

Example 8 with SituationAffectsBean

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

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

the class AlertsAction method toAffectClause.

private List<AffectsClauseRssBean> toAffectClause(List<SituationAffectsBean> clauses) {
    List<AffectsClauseRssBean> beans = new ArrayList<>();
    if (clauses == null)
        return null;
    for (SituationAffectsBean clause : clauses) {
        AffectsClauseRssBean bean = new AffectsClauseRssBean();
        bean.setAgencyId(clause.getAgencyId());
        bean.setRouteId(clause.getRouteId());
        bean.setTripId(clause.getTripId());
        bean.setStopId(clause.getStopId());
        beans.add(bean);
    }
    return beans;
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) ArrayList(java.util.ArrayList) AffectsClauseRssBean(org.onebusaway.rss.model.AffectsClauseRssBean)

Example 10 with SituationAffectsBean

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

the class ServiceAlertsHelper method handleAffects.

/*
  @SuppressWarnings("unused")
  private void handlReasons(PtSituationElementStructure ptSituation,
      ServiceAlertBean serviceAlert) {
    throw new RuntimeException("handleReasons not implemented");
  }
*/
private void handleAffects(ServiceAlertBean serviceAlert, PtSituationElementStructure ptSituation) {
    if (serviceAlert.getAllAffects() == null)
        return;
    boolean hasOperators = false;
    AffectsScopeStructure affectsStructure = new AffectsScopeStructure();
    VehicleJourneys vehicleJourneys = new VehicleJourneys();
    for (SituationAffectsBean affects : serviceAlert.getAllAffects()) {
        String agencyId = affects.getAgencyId();
        if (agencyId != null) {
            Operators operators = new Operators();
            if (StringUtils.equals(agencyId, "__ALL_OPERATORS__")) {
                operators.setAllOperators("");
            } else {
                AffectedOperatorStructure affectedOperator = new AffectedOperatorStructure();
                affectedOperator.setOperatorName(createDefaultedTextStructure(agencyId));
                operators.getAffectedOperator().add(affectedOperator);
            }
            affectsStructure.setOperators(operators);
            hasOperators = true;
        }
        // LineRef
        String routeId = affects.getRouteId();
        String directionId = affects.getDirectionId();
        String stopId = affects.getStopId();
        if (!StringUtils.isBlank(routeId)) {
            AffectedVehicleJourneyStructure affectedVehicleJourneyStructure = new AffectedVehicleJourneyStructure();
            LineRefStructure lineRefStructure = new LineRefStructure();
            lineRefStructure.setValue(routeId);
            affectedVehicleJourneyStructure.setLineRef(lineRefStructure);
            if (!StringUtils.isBlank(directionId)) {
                DirectionRefStructure directionRefStructure = new DirectionRefStructure();
                directionRefStructure.setValue(directionId);
                affectedVehicleJourneyStructure.setDirectionRef(directionRefStructure);
            }
            vehicleJourneys.getAffectedVehicleJourney().add(affectedVehicleJourneyStructure);
        }
        // add support for stop level alerts
        if (!StringUtils.isBlank(stopId)) {
            AffectedStopPointStructure stop = new AffectedStopPointStructure();
            StopPointRefStructure stopRef = new StopPointRefStructure();
            stopRef.setValue(stopId);
            stop.setStopPointRef(stopRef);
            if (affectsStructure.getStopPoints() == null) {
                affectsStructure.setStopPoints(new AffectsScopeStructure.StopPoints());
            }
            affectsStructure.getStopPoints().getAffectedStopPoint().add(stop);
        }
    }
    if (vehicleJourneys.getAffectedVehicleJourney().size() > 0) {
        affectsStructure.setVehicleJourneys(vehicleJourneys);
    }
    if ((vehicleJourneys.getAffectedVehicleJourney().size() > 0) || hasOperators) {
        ptSituation.setAffects(affectsStructure);
    }
}
Also used : Operators(uk.org.siri.siri.AffectsScopeStructure.Operators) AffectedVehicleJourneyStructure(uk.org.siri.siri.AffectedVehicleJourneyStructure) AffectedOperatorStructure(uk.org.siri.siri.AffectedOperatorStructure) LineRefStructure(uk.org.siri.siri.LineRefStructure) AffectsScopeStructure(uk.org.siri.siri.AffectsScopeStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) VehicleJourneys(uk.org.siri.siri.AffectsScopeStructure.VehicleJourneys) StopPointRefStructure(uk.org.siri.siri.StopPointRefStructure) DirectionRefStructure(uk.org.siri.siri.DirectionRefStructure) AffectedStopPointStructure(uk.org.siri.siri.AffectedStopPointStructure)

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