Search in sources :

Example 1 with Situations

use of uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations in project onebusaway-application-modules by camsys.

the class SiriService method handleSituationExchange.

private void handleSituationExchange(ServiceDelivery serviceDelivery, SituationExchangeDeliveryStructure sxDelivery, SiriEndpointDetails endpointDetails) {
    Situations situations = sxDelivery.getSituations();
    if (situations == null)
        return;
    List<ServiceAlertRecord> serviceAlertsToUpdate = new ArrayList<ServiceAlertRecord>();
    List<AgencyAndId> serviceAlertIdsToRemove = new ArrayList<AgencyAndId>();
    for (PtSituationElementStructure ptSituation : situations.getPtSituationElement()) {
        ServiceAlertRecord serviceAlert = getPtSituationAsServiceAlert(ptSituation, endpointDetails);
        WorkflowStatusEnumeration progress = ptSituation.getProgress();
        boolean remove = (progress != null && (progress == WorkflowStatusEnumeration.CLOSING || progress == WorkflowStatusEnumeration.CLOSED));
        if (remove) {
            AgencyAndId situationId = ServiceAlertLibrary.agencyAndId(serviceAlert.getAgencyId(), serviceAlert.getServiceAlertId());
            serviceAlertIdsToRemove.add(situationId);
        } else {
            serviceAlertsToUpdate.add(serviceAlert);
        }
    }
    String defaultAgencyId = null;
    if (!CollectionsLibrary.isEmpty(endpointDetails.getDefaultAgencyIds()))
        defaultAgencyId = endpointDetails.getDefaultAgencyIds().get(0);
    for (ServiceAlertRecord serviceAlert : serviceAlertsToUpdate) {
        serviceAlert.setAgencyId(defaultAgencyId);
        _serviceAlertsService.createOrUpdateServiceAlert(serviceAlert);
    }
    _serviceAlertsService.removeServiceAlerts(serviceAlertIdsToRemove);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) Situations(uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations)

Example 2 with Situations

use of uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations in project onebusaway-application-modules by camsys.

the class ServiceAlertsHelper method addPtSituationElementsToServiceDelivery.

private void addPtSituationElementsToServiceDelivery(ServiceDelivery serviceDelivery, Map<String, PtSituationElementStructure> ptSituationElements) {
    if (serviceDelivery == null || ptSituationElements == null)
        return;
    SituationExchangeDeliveryStructure situationExchangeDeliveryStructure;
    // Check if the serviceDelivery already has a situationDeliveryStructure in its list
    if (serviceDelivery.getSituationExchangeDelivery().size() > 0) {
        // It does, so use it
        situationExchangeDeliveryStructure = serviceDelivery.getSituationExchangeDelivery().get(0);
    } else {
        // It does not, so create a new one and use it
        situationExchangeDeliveryStructure = new SituationExchangeDeliveryStructure();
    }
    // Try to get the situation object from our situationExchangeDeliveryStructure
    Situations situations = situationExchangeDeliveryStructure.getSituations();
    // If it contained no situation object, create a new one and add it to our situationExchangeDeliveryStructure
    if (situations == null) {
        situations = new Situations();
        situationExchangeDeliveryStructure.setSituations(situations);
    }
    // Iterate through our ptSituationElements and add them to our situations object
    for (PtSituationElementStructure p : ptSituationElements.values()) {
        situations.getPtSituationElement().add(p);
    }
    // If our situationExchangeDeliveryStructure has a situations object...
    if (situationExchangeDeliveryStructure.getSituations() != null && // AND our situations object's ptSituationsElement is not empty
    (situationExchangeDeliveryStructure.getSituations().getPtSituationElement() != null && !situationExchangeDeliveryStructure.getSituations().getPtSituationElement().isEmpty()) && // AND our serviceDelivery doesn't already contain our situationExchangeDeliveryStructure
    !serviceDelivery.getSituationExchangeDelivery().contains(situationExchangeDeliveryStructure)) {
        // Add our situationExchangeDeliveryStructure to our serviceDelivery
        serviceDelivery.getSituationExchangeDelivery().add(situationExchangeDeliveryStructure);
    }
}
Also used : SituationExchangeDeliveryStructure(uk.org.siri.siri.SituationExchangeDeliveryStructure) Situations(uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations) PtSituationElementStructure(uk.org.siri.siri.PtSituationElementStructure)

Example 3 with Situations

use of uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations in project onebusaway-application-modules by camsys.

the class ServiceAlertsHelper method addSituationExchangeToServiceDelivery.

public void addSituationExchangeToServiceDelivery(ServiceDelivery serviceDelivery, Collection<ServiceAlertBean> serviceAlerts) {
    Situations situations = new Situations();
    for (ServiceAlertBean serviceAlert : serviceAlerts) {
        situations.getPtSituationElement().add(getServiceAlertBeanAsPtSituationElementStructure(serviceAlert));
    }
    if (situations.getPtSituationElement().size() > 0) {
        SituationExchangeDeliveryStructure situationExchangeDelivery = new SituationExchangeDeliveryStructure();
        situationExchangeDelivery.setSituations(situations);
        serviceDelivery.getSituationExchangeDelivery().add(situationExchangeDelivery);
    }
}
Also used : SituationExchangeDeliveryStructure(uk.org.siri.siri.SituationExchangeDeliveryStructure) Situations(uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Aggregations

Situations (uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations)3 SituationExchangeDeliveryStructure (uk.org.siri.siri.SituationExchangeDeliveryStructure)2 ArrayList (java.util.ArrayList)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1 PtSituationElementStructure (uk.org.siri.siri.PtSituationElementStructure)1