use of uk.org.siri.siri_2.ServiceDelivery in project onebusaway-application-modules by camsys.
the class ServiceAlertsHelperV2 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);
}
}
use of uk.org.siri.siri_2.ServiceDelivery 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);
}
}
use of uk.org.siri.siri_2.ServiceDelivery 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);
}
use of uk.org.siri.siri_2.ServiceDelivery 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);
}
}
Aggregations