Search in sources :

Example 1 with VehicleJourneys

use of uk.org.siri.siri.AffectsScopeStructure.VehicleJourneys 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);
                }
            }
        }
    }
}
Also used : Operators(uk.org.siri.siri.AffectsScopeStructure.Operators) AffectedApplicationStructure(org.onebusaway.siri.AffectedApplicationStructure) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Applications(org.onebusaway.siri.OneBusAwayAffectsStructure.Applications) Calls(uk.org.siri.siri.AffectedVehicleJourneyStructure.Calls) VehicleJourneys(uk.org.siri.siri.AffectsScopeStructure.VehicleJourneys) StopPoints(uk.org.siri.siri.AffectsScopeStructure.StopPoints) OneBusAwayAffects(org.onebusaway.siri.OneBusAwayAffects) HashSet(java.util.HashSet)

Example 2 with VehicleJourneys

use of uk.org.siri.siri.AffectsScopeStructure.VehicleJourneys 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);
    }
}
Also used : Operators(uk.org.siri.siri.AffectsScopeStructure.Operators) AffectedVehicleJourneyStructure(uk.org.siri.siri.AffectedVehicleJourneyStructure) AffectedOperatorStructure(uk.org.siri.siri.AffectedOperatorStructure) LineRefStructure(uk.org.siri.siri.LineRefStructure) AffectsScopeStructure(uk.org.siri.siri.AffectsScopeStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) VehicleJourneys(uk.org.siri.siri.AffectsScopeStructure.VehicleJourneys) StopPointRefStructure(uk.org.siri.siri.StopPointRefStructure) DirectionRefStructure(uk.org.siri.siri.DirectionRefStructure) AffectedStopPointStructure(uk.org.siri.siri.AffectedStopPointStructure)

Aggregations

Operators (uk.org.siri.siri.AffectsScopeStructure.Operators)2 VehicleJourneys (uk.org.siri.siri.AffectsScopeStructure.VehicleJourneys)2 HashSet (java.util.HashSet)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 AffectedApplicationStructure (org.onebusaway.siri.AffectedApplicationStructure)1 OneBusAwayAffects (org.onebusaway.siri.OneBusAwayAffects)1 Applications (org.onebusaway.siri.OneBusAwayAffectsStructure.Applications)1 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)1 AffectedOperatorStructure (uk.org.siri.siri.AffectedOperatorStructure)1 AffectedStopPointStructure (uk.org.siri.siri.AffectedStopPointStructure)1 AffectedVehicleJourneyStructure (uk.org.siri.siri.AffectedVehicleJourneyStructure)1 Calls (uk.org.siri.siri.AffectedVehicleJourneyStructure.Calls)1 AffectsScopeStructure (uk.org.siri.siri.AffectsScopeStructure)1 StopPoints (uk.org.siri.siri.AffectsScopeStructure.StopPoints)1 DirectionRefStructure (uk.org.siri.siri.DirectionRefStructure)1 LineRefStructure (uk.org.siri.siri.LineRefStructure)1 StopPointRefStructure (uk.org.siri.siri.StopPointRefStructure)1