Search in sources :

Example 1 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method addGlobalServiceAlertsToServiceDelivery.

public void addGlobalServiceAlertsToServiceDelivery(ServiceDelivery serviceDelivery, RealtimeServiceV2 realtimeService) {
    List<ServiceAlertBean> serviceAlertBeans = realtimeService.getServiceAlertsGlobal();
    if (serviceAlertBeans == null)
        return;
    Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>();
    for (ServiceAlertBean serviceAlertBean : serviceAlertBeans) {
        ptSituationElements.put(serviceAlertBean.getId(), getServiceAlertBeanAsPtSituationElementStructure(serviceAlertBean));
    }
    addPtSituationElementsToServiceDelivery(serviceDelivery, ptSituationElements);
}
Also used : HashMap(java.util.HashMap) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 2 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method addSituationExchangeToServiceDelivery.

/*
  public void addSituationExchangeToServiceDelivery(ServiceDelivery serviceDelivery,
      List<VehicleActivityStructure> activities,
      TransitDataService transitDataService) {
    
    addSituationExchangeToServiceDelivery(serviceDelivery, activities, transitDataService, null);
  }
  */
public void addSituationExchangeToServiceDelivery(ServiceDelivery serviceDelivery, List<VehicleActivityStructure> activities, TransitDataService transitDataService, List<AgencyAndId> routeIds) {
    if (activities == null)
        return;
    Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>();
    for (VehicleActivityStructure activity : activities) {
        if (activity.getMonitoredVehicleJourney() != null) {
            addSituationElement(transitDataService, ptSituationElements, activity.getMonitoredVehicleJourney().getSituationRef());
        }
    }
    addPtSituationElementsToServiceDelivery(serviceDelivery, ptSituationElements);
    if (routeIds == null)
        return;
    List<ServiceAlertBean> serviceAlerts = new ArrayList<ServiceAlertBean>();
    for (AgencyAndId routeId : routeIds) {
        SituationQueryBean query = new SituationQueryBean();
        SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
        query.getAffects().add(affects);
        affects.setRouteId(routeId.toString());
        ListBean<ServiceAlertBean> serviceAlertsForRoute = transitDataService.getServiceAlerts(query);
        if (serviceAlertsForRoute != null) {
            serviceAlerts.addAll(serviceAlertsForRoute.getList());
        }
    }
    if (serviceAlerts.size() == 0)
        return;
    addSituationExchangeToServiceDelivery(serviceDelivery, serviceAlerts);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) VehicleActivityStructure(uk.org.siri.siri_2.VehicleActivityStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 3 with PtSituationElementStructure

use of uk.org.siri.siri_2.PtSituationElementStructure 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)

Example 4 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method addFromQuery.

private void addFromQuery(TransitDataService transitDataService, Map<String, PtSituationElementStructure> ptSituationElements, SituationQueryBean queryBean) {
    ListBean<ServiceAlertBean> serviceAlerts = transitDataService.getServiceAlerts(queryBean);
    ServiceAlertsHelperV2 helper = new ServiceAlertsHelperV2();
    for (ServiceAlertBean bean : serviceAlerts.getList()) {
        PtSituationElementStructure ptSit = helper.getServiceAlertBeanAsPtSituationElementStructure(bean);
        ptSituationElements.put(ptSit.getSituationNumber().getValue(), ptSit);
    }
}
Also used : PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 5 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method addSituationElement.

/*
  public void addSituationExchangeToServiceDelivery(ServiceDelivery serviceDelivery,
      Map<String, ServiceAlertBean> currentServiceAlerts) {
    addSituationExchangeToServiceDelivery(serviceDelivery, currentServiceAlerts.values());
  }

  public void addClosedSituationExchangesToSiri(
      ServiceDelivery serviceDelivery, Collection<String> deletedIds) {
    Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>();

    for (String id : deletedIds) {
      PtSituationElementStructure ptSit = new PtSituationElementStructure();
      EntryQualifierStructure value = new EntryQualifierStructure();
      value.setValue(id);
      ptSit.setSituationNumber(value);
      ptSit.setProgress(WorkflowStatusEnumeration.CLOSED);
      ptSituationElements.put(id, ptSit);
    }

    addPtSituationElementsToServiceDelivery(serviceDelivery,
        ptSituationElements);

  }
*/
private void addSituationElement(TransitDataService transitDataService, Map<String, PtSituationElementStructure> ptSituationElements, List<SituationRefStructure> situationRefs) {
    if (situationRefs == null)
        return;
    for (SituationRefStructure situationRef : situationRefs) {
        String situationId = situationRef.getSituationSimpleRef().getValue();
        ServiceAlertBean serviceAlert = transitDataService.getServiceAlertForId(situationId);
        PtSituationElementStructure e = getServiceAlertBeanAsPtSituationElementStructure(serviceAlert);
        ptSituationElements.put(situationId, e);
    }
}
Also used : SituationRefStructure(uk.org.siri.siri_2.SituationRefStructure) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Aggregations

PtSituationElementStructure (uk.org.siri.siri_2.PtSituationElementStructure)7 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)4 HashMap (java.util.HashMap)3 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)3 ArrayList (java.util.ArrayList)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)2 OneBusAwayConsequence (org.onebusaway.siri.OneBusAwayConsequence)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1 EEffect (org.onebusaway.transit_data.model.service_alerts.EEffect)1 SituationConsequenceBean (org.onebusaway.transit_data.model.service_alerts.SituationConsequenceBean)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