Search in sources :

Example 6 with TimeRangeBean

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

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

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

the class ServiceAlertsAction method isActive.

public boolean isActive(List<TimeRangeBean> windows) {
    if (windows != null && !windows.isEmpty()) {
        long now = System.currentTimeMillis();
        TimeRangeBean timeRangeBean = windows.get(0);
        if ((timeRangeBean.getTo() > 0 && timeRangeBean.getTo() <= now) || (timeRangeBean.getFrom() > 0 && timeRangeBean.getFrom() >= now)) {
            return false;
        }
    }
    return true;
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)

Example 9 with TimeRangeBean

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

the class AlertsAction method toTimeRange.

private List<TimeRangeRssBean> toTimeRange(List<TimeRangeBean> beans) {
    List<TimeRangeRssBean> trrbs = new ArrayList<>();
    if (beans == null)
        return trrbs;
    for (TimeRangeBean trb : beans) {
        TimeRangeRssBean trrb = new TimeRangeRssBean();
        trrb.setFrom(trb.getFrom());
        trrb.setTo(trb.getTo());
        trrbs.add(trrb);
    }
    return trrbs;
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) ArrayList(java.util.ArrayList) TimeRangeRssBean(org.onebusaway.rss.model.TimeRangeRssBean)

Example 10 with TimeRangeBean

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

the class ServiceAlertAction method getStartDate.

public String getStartDate() {
    List<TimeRangeBean> publicationWindows = _model.getPublicationWindows();
    if (publicationWindows == null || publicationWindows.isEmpty() || publicationWindows.get(0).getFrom() == 0) {
        return null;
    }
    Date date = new Date(publicationWindows.get(0).getFrom());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    return sdf.format(date);
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)15 Date (java.util.Date)5 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)3 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)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 NaturalLanguageStringBean (org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean)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 Test (org.junit.Test)1 ResponseBean (org.onebusaway.api.model.ResponseBean)1 SituationAffectsV2Bean (org.onebusaway.api.model.transit.service_alerts.SituationAffectsV2Bean)1 SituationConsequenceV2Bean (org.onebusaway.api.model.transit.service_alerts.SituationConsequenceV2Bean)1 SituationV2Bean (org.onebusaway.api.model.transit.service_alerts.SituationV2Bean)1