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