use of org.onebusaway.siri.OneBusAwayAffects in project onebusaway-application-modules by camsys.
the class SiriService method handleAffects.
/**
**
* Affects
***
*/
protected void handleAffects(PtSituationElementStructure ptSituation, ServiceAlertRecord 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();
ServiceAlertsSituationAffectsClause affects = new ServiceAlertsSituationAffectsClause();
affects.setAgencyId(agencyId);
if (serviceAlert.getAllAffects() == null)
serviceAlert.setAllAffects(new HashSet<ServiceAlertsSituationAffectsClause>());
serviceAlert.getAllAffects().add(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());
ServiceAlertsSituationAffectsClause affects = new ServiceAlertsSituationAffectsClause();
affects.setStopId(stopId.getId());
affects.setAgencyId(stopId.getAgencyId());
if (serviceAlert.getAllAffects() == null)
serviceAlert.setAllAffects(new HashSet<ServiceAlertsSituationAffectsClause>());
serviceAlert.getAllAffects().add(affects);
}
}
VehicleJourneys vjs = affectsStructure.getVehicleJourneys();
if (vjs != null && !CollectionsLibrary.isEmpty(vjs.getAffectedVehicleJourney())) {
for (AffectedVehicleJourneyStructure vj : vjs.getAffectedVehicleJourney()) {
ServiceAlertsSituationAffectsClause affects = new ServiceAlertsSituationAffectsClause();
if (vj.getLineRef() != null) {
AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(vj.getLineRef().getValue());
affects.setRouteId(routeId.getId());
affects.setAgencyId(routeId.getAgencyId());
}
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 (serviceAlert.getAllAffects() == null)
serviceAlert.setAllAffects(new HashSet<ServiceAlertsSituationAffectsClause>());
if (!(hasTripRefs || hasStopRefs)) {
if (affects.getRouteId() != null)
serviceAlert.getAllAffects().add(affects);
} else if (hasTripRefs && hasStopRefs) {
for (VehicleJourneyRefStructure vjRef : vj.getVehicleJourneyRef()) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(vjRef.getValue());
affects.setTripId(tripId.getId());
affects.setAgencyId(tripId.getAgencyId());
for (AffectedCallStructure call : stopRefs.getCall()) {
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(call.getStopPointRef().getValue());
affects.setStopId(stopId.getId());
affects.setAgencyId(stopId.getAgencyId());
serviceAlert.getAllAffects().add(affects);
}
}
} else if (hasTripRefs) {
for (VehicleJourneyRefStructure vjRef : vj.getVehicleJourneyRef()) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(vjRef.getValue());
affects.setTripId(tripId.getId());
affects.setAgencyId(tripId.getAgencyId());
serviceAlert.getAllAffects().add(affects);
}
} else {
for (AffectedCallStructure call : stopRefs.getCall()) {
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(call.getStopPointRef().getValue());
affects.setStopId(stopId.getId());
affects.setAgencyId(stopId.getAgencyId());
serviceAlert.getAllAffects().add(affects);
}
}
}
}
ExtensionsStructure extension = affectsStructure.getExtensions();
if (extension != null && extension.getAny() != null) {
Object ext = extension.getAny();
if (ext instanceof OneBusAwayAffects) {
OneBusAwayAffects obaAffects = (OneBusAwayAffects) ext;
Applications applications = obaAffects.getApplications();
if (applications != null && !CollectionsLibrary.isEmpty(applications.getAffectedApplication())) {
List<AffectedApplicationStructure> apps = applications.getAffectedApplication();
if (serviceAlert.getAllAffects() == null)
serviceAlert.setAllAffects(new HashSet<ServiceAlertsSituationAffectsClause>());
for (AffectedApplicationStructure sApp : apps) {
ServiceAlertsSituationAffectsClause affects = new ServiceAlertsSituationAffectsClause();
affects.setApplicationId(sApp.getApiKey());
serviceAlert.getAllAffects().add(affects);
}
}
}
}
}
Aggregations