****/
protected void handleAffects(PtSituationElementStructure ptSituation,
ServiceAlert.Builder serviceAlert) {
AffectsScopeStructure affectsStructure = ptSituation.getAffects();
if (affectsStructure == null)
return;
Operators operators = affectsStructure.getOperators();
if (operators != null
&& !CollectionsLibrary.isEmpty(operators.getAffectedOperator())) {
for (AffectedOperatorStructure operator : operators.getAffectedOperator()) {
OperatorRefStructure operatorRef = operator.getOperatorRef();
if (operatorRef == null || operatorRef.getValue() == null)
continue;
String agencyId = operatorRef.getValue();
Affects.Builder affects = Affects.newBuilder();
affects.setAgencyId(agencyId);
serviceAlert.addAffects(affects);
}
}
StopPoints stopPoints = affectsStructure.getStopPoints();
if (stopPoints != null
&& !CollectionsLibrary.isEmpty(stopPoints.getAffectedStopPoint())) {
for (AffectedStopPointStructure stopPoint : stopPoints.getAffectedStopPoint()) {
StopPointRefStructure stopRef = stopPoint.getStopPointRef();
if (stopRef == null || stopRef.getValue() == null)
continue;
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(stopRef.getValue());
Id id = ServiceAlertLibrary.id(stopId);
Affects.Builder affects = Affects.newBuilder();
affects.setStopId(id);
serviceAlert.addAffects(affects);
}
}
VehicleJourneys vjs = affectsStructure.getVehicleJourneys();
if (vjs != null
&& !CollectionsLibrary.isEmpty(vjs.getAffectedVehicleJourney())) {
for (AffectedVehicleJourneyStructure vj : vjs.getAffectedVehicleJourney()) {
Affects.Builder affects = Affects.newBuilder();
if (vj.getLineRef() != null) {
AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(vj.getLineRef().getValue());
Id id = ServiceAlertLibrary.id(routeId);
affects.setRouteId(id);
}
if (vj.getDirectionRef() != null)
affects.setDirectionId(vj.getDirectionRef().getValue());
List<VehicleJourneyRefStructure> tripRefs = vj.getVehicleJourneyRef();
Calls stopRefs = vj.getCalls();
boolean hasTripRefs = !CollectionsLibrary.isEmpty(tripRefs);
boolean hasStopRefs = stopRefs != null
&& !CollectionsLibrary.isEmpty(stopRefs.getCall());
if (!(hasTripRefs || hasStopRefs)) {
if (affects.hasRouteId())
serviceAlert.addAffects(affects);
} else if (hasTripRefs && hasStopRefs) {
for (VehicleJourneyRefStructure vjRef : vj.getVehicleJourneyRef()) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(vjRef.getValue());
affects.setTripId(ServiceAlertLibrary.id(tripId));
for (AffectedCallStructure call : stopRefs.getCall()) {
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(call.getStopPointRef().getValue());
affects.setStopId(ServiceAlertLibrary.id(stopId));
serviceAlert.addAffects(affects);
}
}
} else if (hasTripRefs) {
for (VehicleJourneyRefStructure vjRef : vj.getVehicleJourneyRef()) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(vjRef.getValue());
affects.setTripId(ServiceAlertLibrary.id(tripId));
serviceAlert.addAffects(affects);
}
} else {
for (AffectedCallStructure call : stopRefs.getCall()) {
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(call.getStopPointRef().getValue());
affects.setStopId(ServiceAlertLibrary.id(stopId));
serviceAlert.addAffects(affects);
}
}
}
}
ExtensionsStructure extension = affectsStructure.getExtensions();
if (extension != null && extension.getAny() != null) {
Object ext = extension.getAny();
if (ext instanceof OneBusAwayAffects) {
OneBusAwayAffects obaAffects = (OneBusAwayAffects) ext;