use of uk.org.siri.siri_2.ServiceDelivery in project onebusaway-application-modules by camsys.
the class StopMonitoringV2Action method generateSiriResponse.
private Siri generateSiriResponse(List<MonitoredStopVisitStructure> visits, List<AgencyAndId> stopIds, Exception error, long responseTimestamp) {
StopMonitoringDeliveryStructure stopMonitoringDelivery = new StopMonitoringDeliveryStructure();
stopMonitoringDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
ServiceDelivery serviceDelivery = new ServiceDelivery();
serviceDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
serviceDelivery.getStopMonitoringDelivery().add(stopMonitoringDelivery);
if (error != null) {
ServiceDeliveryErrorConditionStructure errorConditionStructure = new ServiceDeliveryErrorConditionStructure();
ErrorDescriptionStructure errorDescriptionStructure = new ErrorDescriptionStructure();
errorDescriptionStructure.setValue(error.getMessage());
OtherErrorStructure otherErrorStructure = new OtherErrorStructure();
otherErrorStructure.setErrorText(error.getMessage());
errorConditionStructure.setDescription(errorDescriptionStructure);
errorConditionStructure.setOtherError(otherErrorStructure);
stopMonitoringDelivery.setErrorCondition(errorConditionStructure);
} else {
Calendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(responseTimestamp);
gregorianCalendar.add(Calendar.MINUTE, 1);
stopMonitoringDelivery.setValidUntil(DateUtil.toXmlGregorianCalendar(gregorianCalendar.getTimeInMillis()));
stopMonitoringDelivery.getMonitoredStopVisit().addAll(visits);
serviceDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
_serviceAlertsHelper.addSituationExchangeToSiriForStops(serviceDelivery, visits, _transitDataService, stopIds);
_serviceAlertsHelper.addGlobalServiceAlertsToServiceDelivery(serviceDelivery, _realtimeService);
}
Siri siri = new Siri();
siri.setServiceDelivery(serviceDelivery);
return siri;
}
use of uk.org.siri.siri_2.ServiceDelivery in project onebusaway-application-modules by camsys.
the class StopPointsV2Action method generateSiriResponse.
private Siri generateSiriResponse(List<AnnotatedStopPointStructure> stopPoints, Boolean hasUpcomingScheduledService, Exception error, long responseTimestamp) {
StopPointsDeliveryStructure stopPointsDelivery = new StopPointsDeliveryStructure();
stopPointsDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
if (error != null) {
ServiceDeliveryErrorConditionStructure errorConditionStructure = new ServiceDeliveryErrorConditionStructure();
ErrorDescriptionStructure errorDescriptionStructure = new ErrorDescriptionStructure();
errorDescriptionStructure.setValue(error.getMessage());
OtherErrorStructure otherErrorStructure = new OtherErrorStructure();
otherErrorStructure.setErrorText(error.getMessage());
errorConditionStructure.setDescription(errorDescriptionStructure);
errorConditionStructure.setOtherError(otherErrorStructure);
stopPointsDelivery.setErrorCondition(errorConditionStructure);
} else {
Calendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(responseTimestamp);
gregorianCalendar.add(Calendar.MINUTE, 1);
stopPointsDelivery.setValidUntil(DateUtil.toXmlGregorianCalendar(gregorianCalendar.getTimeInMillis()));
stopPointsDelivery.getAnnotatedStopPointRef().addAll(stopPoints);
if (hasUpcomingScheduledService != null) {
// siri extensions
ExtensionsStructure upcomingServiceExtensions = new ExtensionsStructure();
SiriUpcomingServiceExtension upcomingService = new SiriUpcomingServiceExtension();
upcomingService.setUpcomingScheduledService(hasUpcomingScheduledService);
upcomingServiceExtensions.setAny(upcomingService);
stopPointsDelivery.setExtensions(upcomingServiceExtensions);
}
stopPointsDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
// TODO - LCARABALLO Do I still need serviceAlertsHelper?
/*
* _serviceAlertsHelper.addSituationExchangeToSiriForStops(
* serviceDelivery, visits, _nycTransitDataService, stopIds);
* _serviceAlertsHelper.addGlobalServiceAlertsToServiceDelivery(
* serviceDelivery, _realtimeService);
*/
}
Siri siri = new Siri();
siri.setStopPointsDelivery(stopPointsDelivery);
return siri;
}
use of uk.org.siri.siri_2.ServiceDelivery in project onebusaway-application-modules by camsys.
the class VehicleMonitoringV2Action method generateSiriResponse.
/**
* Generate a siri response for a set of VehicleActivities
*
* @param routeId
*/
private Siri generateSiriResponse(List<VehicleActivityStructure> activities, List<AgencyAndId> routeIds, Exception error, long currentTimestamp) {
VehicleMonitoringDeliveryStructure vehicleMonitoringDelivery = new VehicleMonitoringDeliveryStructure();
vehicleMonitoringDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(currentTimestamp));
ServiceDelivery serviceDelivery = new ServiceDelivery();
serviceDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(currentTimestamp));
serviceDelivery.getVehicleMonitoringDelivery().add(vehicleMonitoringDelivery);
if (error != null) {
ServiceDeliveryErrorConditionStructure errorConditionStructure = new ServiceDeliveryErrorConditionStructure();
ErrorDescriptionStructure errorDescriptionStructure = new ErrorDescriptionStructure();
errorDescriptionStructure.setValue(error.getMessage());
OtherErrorStructure otherErrorStructure = new OtherErrorStructure();
otherErrorStructure.setErrorText(error.getMessage());
errorConditionStructure.setDescription(errorDescriptionStructure);
errorConditionStructure.setOtherError(otherErrorStructure);
vehicleMonitoringDelivery.setErrorCondition(errorConditionStructure);
} else {
Calendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(currentTimestamp);
gregorianCalendar.add(Calendar.MINUTE, 1);
vehicleMonitoringDelivery.setValidUntil(DateUtil.toXmlGregorianCalendar(gregorianCalendar.getTimeInMillis()));
vehicleMonitoringDelivery.getVehicleActivity().addAll(activities);
_serviceAlertsHelper.addSituationExchangeToServiceDelivery(serviceDelivery, activities, _transitDataService, routeIds);
_serviceAlertsHelper.addGlobalServiceAlertsToServiceDelivery(serviceDelivery, _realtimeService);
}
Siri siri = new Siri();
siri.setServiceDelivery(serviceDelivery);
return siri;
}
use of uk.org.siri.siri_2.ServiceDelivery 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);
}
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,
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);
}
Aggregations