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;
}
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()));
}
}
}
}
}
}
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;
}
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;
}
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);
}
Aggregations