Search in sources :

Example 6 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method addSituationExchangeToSiriForStops.

public void addSituationExchangeToSiriForStops(ServiceDelivery serviceDelivery, List<MonitoredStopVisitStructure> visits, TransitDataService transitDataService, List<AgencyAndId> stopIds) {
    Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>();
    for (MonitoredStopVisitStructure visit : visits) {
        if (visit.getMonitoredVehicleJourney() != null)
            addSituationElement(transitDataService, ptSituationElements, visit.getMonitoredVehicleJourney().getSituationRef());
    }
    if (stopIds != null && stopIds.size() > 0) {
        for (AgencyAndId stopId : stopIds) {
            String stopIdString = stopId.toString();
            // First get service alerts for the stop
            SituationQueryBean query = new SituationQueryBean();
            List<String> stopIdStrings = new ArrayList<String>();
            stopIdStrings.add(stopIdString);
            SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
            query.getAffects().add(affects);
            affects.setStopId(stopIdString);
            addFromQuery(transitDataService, ptSituationElements, query);
            // Now also add service alerts for (route+direction)s of the stop
            query = new SituationQueryBean();
            StopBean stopBean = transitDataService.getStop(stopIdString);
            List<RouteBean> routes = stopBean.getRoutes();
            for (RouteBean route : routes) {
                StopsForRouteBean stopsForRoute = transitDataService.getStopsForRoute(route.getId());
                List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
                for (StopGroupingBean stopGrouping : stopGroupings) {
                    if (!stopGrouping.getType().equalsIgnoreCase("direction"))
                        continue;
                    for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
                        handleStopGroupBean(stopIdString, query, route, stopGroup);
                    }
                }
            }
            addFromQuery(transitDataService, ptSituationElements, query);
        }
    }
    addPtSituationElementsToServiceDelivery(serviceDelivery, ptSituationElements);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) MonitoredStopVisitStructure(uk.org.siri.siri_2.MonitoredStopVisitStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 7 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 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_2.SituationExchangeDeliveryStructure) Situations(uk.org.siri.siri_2.SituationExchangeDeliveryStructure.Situations) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure)

Example 8 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method getServiceAlertBeanAsPtSituationElementStructure.

public PtSituationElementStructure getServiceAlertBeanAsPtSituationElementStructure(ServiceAlertBean serviceAlert) {
    PtSituationElementStructure ptSit = new PtSituationElementStructure();
    EntryQualifierStructure value = new EntryQualifierStructure();
    value.setValue(serviceAlert.getId());
    ptSit.setSituationNumber(value);
    if (serviceAlert.getCreationTime() != 0)
        ptSit.setCreationTime(DateUtil.toXmlGregorianCalendar(serviceAlert.getCreationTime()));
    handleDescriptions(serviceAlert, ptSit);
    handleOtherFields(serviceAlert, ptSit);
    handleAffects(serviceAlert, ptSit);
    handleConsequences(serviceAlert, ptSit);
    return ptSit;
}
Also used : PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) EntryQualifierStructure(uk.org.siri.siri_2.EntryQualifierStructure)

Example 9 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method handleConsequences.

private void handleConsequences(ServiceAlertBean serviceAlert, PtSituationElementStructure ptSituation) {
    if (serviceAlert == null)
        return;
    List<SituationConsequenceBean> consequences = serviceAlert.getConsequences();
    if (consequences == null || consequences.isEmpty())
        return;
    PtConsequencesStructure ptConsequences = new PtConsequencesStructure();
    ptSituation.setConsequences(ptConsequences);
    for (SituationConsequenceBean consequence : consequences) {
        EEffect effect = consequence.getEffect();
        PtConsequenceStructure ptConsequenceStructure = new PtConsequenceStructure();
        ServiceConditionEnumeration serviceCondition = getEFfectAsCondition(effect);
        ptConsequenceStructure.getCondition().add(serviceCondition);
        String detourPath = consequence.getDetourPath();
        if (!StringUtils.isBlank(detourPath)) {
            ExtensionsStructure extensionStructure = new ExtensionsStructure();
            OneBusAwayConsequence oneBusAwayConsequence = new OneBusAwayConsequence();
            oneBusAwayConsequence.setDiversionPath(detourPath);
            extensionStructure.setAny(oneBusAwayConsequence);
            ptConsequenceStructure.setExtensions(extensionStructure);
        }
        ptConsequences.getConsequence().add(ptConsequenceStructure);
    }
}
Also used : PtConsequenceStructure(uk.org.siri.siri_2.PtConsequenceStructure) OneBusAwayConsequence(org.onebusaway.siri.OneBusAwayConsequence) PtConsequencesStructure(uk.org.siri.siri_2.PtConsequencesStructure) ExtensionsStructure(uk.org.siri.siri_2.ExtensionsStructure) SituationConsequenceBean(org.onebusaway.transit_data.model.service_alerts.SituationConsequenceBean) ServiceConditionEnumeration(uk.org.siri.siri_2.ServiceConditionEnumeration) EEffect(org.onebusaway.transit_data.model.service_alerts.EEffect)

Example 10 with PtSituationElementStructure

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

the class ServiceAlertsHelperV2 method handleOtherFields.

private void handleOtherFields(ServiceAlertBean serviceAlert, PtSituationElementStructure ptSituation) {
    if (serviceAlert == null || serviceAlert.getPublicationWindows() == null)
        return;
    // TODO Not handling severity yet.
    ptSituation.setSeverity(SeverityEnumeration.UNDEFINED);
    // TODO - LCARABALLO - Changed from HalfOpenTimestampRangeStructure to HalfOpenTimestampOutputRangeStructure
    HalfOpenTimestampOutputRangeStructure timestampRangeStructure = new HalfOpenTimestampOutputRangeStructure();
    if (serviceAlert.getPublicationWindows() != null && !serviceAlert.getPublicationWindows().isEmpty()) {
        timestampRangeStructure.setStartTime(DateUtil.toXmlGregorianCalendar(serviceAlert.getPublicationWindows().get(0).getFrom()));
        timestampRangeStructure.setEndTime(DateUtil.toXmlGregorianCalendar(serviceAlert.getPublicationWindows().get(0).getTo()));
        ptSituation.setPublicationWindow(timestampRangeStructure);
    }
}
Also used : HalfOpenTimestampOutputRangeStructure(uk.org.siri.siri_2.HalfOpenTimestampOutputRangeStructure)

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