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.setReason(situation.getReason());
private long getTimeForSituation(ServiceAlertBean bean) { long t = getFirstTime(bean.getPublicationWindows()); if (t != Long.MAX_VALUE) return t; t = getFirstTime(bean.getActiveWindows()); if (t != Long.MAX_VALUE) return t; return bean.getCreationTime(); }
public String getTitle(ServiceAlertBean situation) { /** * TODO: Better handling around language selection */ if (!CollectionsLibrary.isEmpty(situation.getSummaries())) return getValue(situation.getSummaries().get(0)); if (!CollectionsLibrary.isEmpty(situation.getDescriptions())) return getValue(situation.getDescriptions().get(0)); return null; }
if (bean.getId() != null && !bean.getId().isEmpty()) { AgencyAndId id; if(bean.getId().indexOf("_") > -1){ id = AgencyAndIdLibrary.convertFromString(bean.getId()); }else{ id = AgencyAndIdLibrary.convertFromString(agencyId + "_" + bean.getId()); serviceAlertRecord.setCreationTime(bean.getCreationTime()); serviceAlertRecord.setActiveWindows(getBeansAsRanges(bean.getActiveWindows())); serviceAlertRecord.setPublicationWindows(getBeansAsRanges(bean.getPublicationWindows())); serviceAlertRecord.setCause(getReasonAsCause(bean.getReason())); if(bean.getSummaries() != null){ for(NaturalLanguageStringBean summary : bean.getSummaries()){ ServiceAlertLocalizedString string = new ServiceAlertLocalizedString(); string.setLanguage(summary.getLang()); if(bean.getDescriptions() != null){ for(NaturalLanguageStringBean summary : bean.getDescriptions()){ ServiceAlertLocalizedString string = new ServiceAlertLocalizedString(); string.setLanguage(summary.getLang()); if(bean.getUrls() != null){ for(NaturalLanguageStringBean url : bean.getUrls()){ ServiceAlertLocalizedString string = new ServiceAlertLocalizedString(); string.setLanguage(url.getLang()); if (bean.getSeverity() != null)
public List<ServiceAlertBean> getReadSituations() { List<ServiceAlertBean> situations = new ArrayList<ServiceAlertBean>(); Map<String, Long> readServiceAlerts = _user.getReadServiceAlerts(); for (ServiceAlertBean situation : _situations) { if (readServiceAlerts.containsKey(situation.getId())) situations.add(situation); } Collections.sort(situations, _comparator); return situations; }
if (serviceAlert.getUrls() != null && ! serviceAlert.getUrls().isEmpty()) { InfoLinks infoLinks = ptSituation.getInfoLinks(); if (infoLinks == null) { ptSituation.setInfoLinks(infoLinks); for (NaturalLanguageStringBean linkBean : serviceAlert.getUrls()) { InfoLinkStructure infoLinkStructure = new InfoLinkStructure(); infoLinkStructure.setUri(linkBean.getValue()); if (serviceAlert.getPublicationWindows() == null) { return; if (serviceAlert.getPublicationWindows() != null && !serviceAlert.getPublicationWindows().isEmpty()) { timestampRangeStructure.setStartTime(serviceAlertTimeToDate(serviceAlert.getPublicationWindows().get( 0).getFrom())); timestampRangeStructure.setEndTime(serviceAlertTimeToDate(serviceAlert.getPublicationWindows().get( 0).getTo())); ptSituation.setPublicationWindow(timestampRangeStructure);
public PtSituationElementStructure getServiceAlertBeanAsPtSituationElementStructure( ServiceAlertBean serviceAlert) { PtSituationElementStructure ptSit = new PtSituationElementStructure(); EntryQualifierStructure value = new EntryQualifierStructure(); if (serviceAlert != null) { value.setValue(serviceAlert.getId()); ptSit.setSituationNumber(value); } else { // nothing to do return ptSit; } if (serviceAlert.getCreationTime() != 0) ptSit.setCreationTime(new Date(serviceAlert.getCreationTime())); handleDescriptions(serviceAlert, ptSit); handleOtherFields(serviceAlert, ptSit); handleAffects(serviceAlert, ptSit); handleConsequences(serviceAlert, ptSit); return ptSit; }
private boolean isSituationApplicable(ServiceAlertBean situation) { Set<String> applicationIds = new HashSet<String>(); for (SituationAffectsBean affects : situation.getAllAffects()) { if (affects.getApplicationId() != null) applicationIds.add(affects.getApplicationId()); } if (CollectionsLibrary.isEmpty(applicationIds)) return true; if (_apiKey == null) return false; return applicationIds.contains(_apiKey); } }
private Set<ServiceAlertSituationConsequenceClause> getBeanAsConsequences(ServiceAlertBean bean) { Set<ServiceAlertSituationConsequenceClause> consequences = new HashSet<ServiceAlertSituationConsequenceClause>(); if (!CollectionsLibrary.isEmpty(bean.getConsequences())) { for (SituationConsequenceBean consequence : bean.getConsequences()) { ServiceAlertSituationConsequenceClause consequenceClause = new ServiceAlertSituationConsequenceClause(); if (consequence.getEffect() != null) consequenceClause.setEffect(consequence.getEffect()); if (consequence.getDetourPath() != null) consequenceClause.setDetourPath(consequence.getDetourPath()); if (!CollectionsLibrary.isEmpty(consequence.getDetourStopIds())) { Set<String> detourStopIds = new HashSet<String>(); for (String detourStopId : consequence.getDetourStopIds()) { detourStopIds.add(detourStopId); } consequenceClause.setDetourStopIds(detourStopIds); } consequences.add(consequenceClause); } } return consequences; }
private boolean isSituationActiveAtTime(ServiceAlertBean situation, long time) { if (CollectionsLibrary.isEmpty(situation.getActiveWindows())) return true; for (TimeRangeBean window : situation.getActiveWindows()) { if (isTimeRangeActive(window, _time, true)) return true; } return false; }
private boolean isSituationInActivePublicationWindow(ServiceAlertBean situation) { if (CollectionsLibrary.isEmpty(situation.getPublicationWindows())) return true; for (TimeRangeBean window : situation.getPublicationWindows()) { if (isTimeRangeActive(window, _time, true)) return true; } return false; }
private ESeverity getHighestUnreadSeverity() { ESeverity maxSeverity = null; Map<String, Long> readServiceAlerts = _user.getReadServiceAlerts(); for (ServiceAlertBean situation : _situations) { if (isSituationUnread(readServiceAlerts, situation)) { ESeverity s = situation.getSeverity(); if (s == null) s = ESeverity.UNDEFINED; if (maxSeverity == null || maxSeverity.getNumericValue() < s.getNumericValue()) maxSeverity = s; } } return maxSeverity; }
public void addGlobalServiceAlertsToServiceDelivery(ServiceDelivery serviceDelivery, RealtimeService realtimeService) { List<ServiceAlertBean> serviceAlertBeans = realtimeService.getServiceAlertsGlobal(); if (serviceAlertBeans == null) return; Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>(); for (ServiceAlertBean serviceAlertBean : serviceAlertBeans) { ptSituationElements.put(serviceAlertBean.getId(), getServiceAlertBeanAsPtSituationElementStructure(serviceAlertBean)); } addPtSituationElementsToServiceDelivery(serviceDelivery, ptSituationElements); }
private void handleDescriptions(ServiceAlertBean serviceAlert, PtSituationElementStructure ptSituation) { if (serviceAlert == null) return; if (serviceAlert.getSummaries() != null) for (NaturalLanguageStringBean summary : serviceAlert.getSummaries()) { ptSituation.setSummary(createDefaultedTextStructure(summary)); } if (serviceAlert.getDescriptions() != null) for (NaturalLanguageStringBean description : serviceAlert.getDescriptions()) { ptSituation.setDescription(createDefaultedTextStructure(description)); } }
public boolean isSituationExcludedForApplication(ServiceAlertBean situation) { List<SituationAffectsBean> affects = situation.getAllAffects(); if (affects == null) return false; Set<String> applicationIds = new HashSet<String>(); for (SituationAffectsBean affect : affects) { if (affect.getApplicationId() != null) applicationIds.add(affect.getApplicationId()); } if (CollectionsLibrary.isEmpty(applicationIds)) return false; if (_applicationKey == null) return true; return !_applicationKey.contains(_applicationKey); }
private void handleConsequences(ServiceAlertBean serviceAlert, PtSituationElementStructure ptSituation) { if (serviceAlert == null) return; List<SituationConsequenceBean> consequences = serviceAlert.getConsequences(); if (consequences == null || consequences.isEmpty()) return; PtConsequencesStructure ptConsequences = new PtConsequencesStructure(); ptSituation.setConsequences(ptConsequences); for (SituationConsequenceBean consequence : consequences) { EEffect effect = consequence.getEffect(); PtConsequenceStructure ptConsequenceStructure = new PtConsequenceStructure(); ServiceConditionEnumeration serviceCondition = getEFfectAsCondition(effect); ptConsequenceStructure.setCondition(serviceCondition); String detourPath = consequence.getDetourPath(); if (!StringUtils.isBlank(detourPath)) { ExtensionsStructure extensionStructure = new ExtensionsStructure(); OneBusAwayConsequence oneBusAwayConsequence = new OneBusAwayConsequence(); oneBusAwayConsequence.setDiversionPath(detourPath); extensionStructure.setAny(oneBusAwayConsequence); ptConsequenceStructure.setExtensions(extensionStructure); } ptConsequences.getConsequence().add(ptConsequenceStructure); } }
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.setReason(situation.getReason());
private boolean isSituationUnread(Map<String, Long> readServiceAlerts, ServiceAlertBean situation) { if (!isSituationInActivePublicationWindow(situation)) return false; Long readTime = readServiceAlerts.get(situation.getId()); if (readTime == null) return true; /** * Optionally, if a service alert has just become active and it hasn't been * read in a while, we might also consider it unread. */ if (readTime + _redisplayIfNowActiveThhreshold < _time) { if (!isSituationActiveAtTime(situation, readTime) && isSituationActiveAtTime(situation, _time)) return true; } return false; }
protected void populateServiceAlerts(Set<String> serviceAlertDescriptions, List<ServiceAlertBean> serviceAlertBeans, boolean htmlizeNewlines) { if (serviceAlertBeans == null) return; for (ServiceAlertBean serviceAlertBean : serviceAlertBeans) { boolean descriptionsAdded = false; descriptionsAdded = setDescription(serviceAlertDescriptions, serviceAlertBean.getDescriptions(), htmlizeNewlines) || setDescription(serviceAlertDescriptions, serviceAlertBean.getSummaries(), htmlizeNewlines); if (!descriptionsAdded) { serviceAlertDescriptions.add("(no description)"); } } }
public boolean isSituationExcludedForApplication(ServiceAlertBean situation) { List<SituationAffectsBean> affects = situation.getAllAffects(); if (affects == null) return false; Set<String> applicationIds = new HashSet<String>(); for (SituationAffectsBean affect : affects) { if (affect.getApplicationId() != null) applicationIds.add(affect.getApplicationId()); } if (CollectionsLibrary.isEmpty(applicationIds)) return false; if (_applicationKey == null) return true; return !_applicationKey.contains(_applicationKey); }