Search in sources :

Example 1 with AffectedVehicleJourneyStructure

use of uk.org.siri.siri_2.AffectedVehicleJourneyStructure in project onebusaway-application-modules by camsys.

the class ServiceAlertsHelperV2 method handleAffects.

/*
  public Date serviceAlertTimeToDate(long time) {
    if (time == 0)
      return null;
    return new Date(time);
  }

  @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.getOperatorName().add(createDefaultedTextStructure(agencyId));
                operators.getAffectedOperator().add(affectedOperator);
            }
            affectsStructure.setOperators(operators);
            hasOperators = true;
        }
        // LineRef
        String routeId = affects.getRouteId();
        String directionId = affects.getDirectionId();
        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);
        }
    }
    if (vehicleJourneys.getAffectedVehicleJourney().size() > 0) {
        affectsStructure.setVehicleJourneys(vehicleJourneys);
    }
    if ((vehicleJourneys.getAffectedVehicleJourney().size() > 0) || hasOperators) {
        ptSituation.setAffects(affectsStructure);
    }
}
Also used : Operators(uk.org.siri.siri_2.AffectsScopeStructure.Operators) AffectsScopeStructure(uk.org.siri.siri_2.AffectsScopeStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) AffectedVehicleJourneyStructure(uk.org.siri.siri_2.AffectedVehicleJourneyStructure) AffectedOperatorStructure(uk.org.siri.siri_2.AffectedOperatorStructure) VehicleJourneys(uk.org.siri.siri_2.AffectsScopeStructure.VehicleJourneys) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure)

Aggregations

SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)1 AffectedOperatorStructure (uk.org.siri.siri_2.AffectedOperatorStructure)1 AffectedVehicleJourneyStructure (uk.org.siri.siri_2.AffectedVehicleJourneyStructure)1 AffectsScopeStructure (uk.org.siri.siri_2.AffectsScopeStructure)1 Operators (uk.org.siri.siri_2.AffectsScopeStructure.Operators)1 VehicleJourneys (uk.org.siri.siri_2.AffectsScopeStructure.VehicleJourneys)1 DirectionRefStructure (uk.org.siri.siri_2.DirectionRefStructure)1 LineRefStructure (uk.org.siri.siri_2.LineRefStructure)1