use of uk.org.siri.siri_2.Siri 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.Siri 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.Siri 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.Siri in project onebusaway-application-modules by camsys.
the class LinesRequestV2Action method generateSiriResponse.
private Siri generateSiriResponse(List<AnnotatedLineStructure> lines, Boolean hasUpcomingScheduledService, Exception error, long responseTimestamp) {
LinesDeliveryStructure linesDelivery = new LinesDeliveryStructure();
linesDelivery.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);
linesDelivery.setErrorCondition(errorConditionStructure);
} else {
Calendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(responseTimestamp);
gregorianCalendar.add(Calendar.MINUTE, 1);
linesDelivery.setValidUntil(DateUtil.toXmlGregorianCalendar(gregorianCalendar.getTimeInMillis()));
linesDelivery.getAnnotatedLineRef().addAll(lines);
if (hasUpcomingScheduledService != null) {
// siri extensions
ExtensionsStructure upcomingServiceExtensions = new ExtensionsStructure();
upcomingServiceExtensions.setAny(hasUpcomingScheduledService);
SiriUpcomingServiceExtension upcomingService = new SiriUpcomingServiceExtension();
upcomingService.setUpcomingScheduledService(hasUpcomingScheduledService);
upcomingServiceExtensions.setAny(upcomingService);
linesDelivery.setExtensions(upcomingServiceExtensions);
}
linesDelivery.setResponseTimestamp(DateUtil.toXmlGregorianCalendar(responseTimestamp));
}
Siri siri = new Siri();
siri.setLinesDelivery(linesDelivery);
return siri;
}
use of uk.org.siri.siri_2.Siri in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getVehicleActivityForRoute.
/**
* SIRI METHODS
*/
@Override
public List<VehicleActivityStructure> getVehicleActivityForRoute(String routeId, String directionId, int maximumOnwardCalls, DetailLevel detailLevel, long currentTime) {
List<VehicleActivityStructure> output = new ArrayList<VehicleActivityStructure>();
ListBean<TripDetailsBean> trips = getAllTripsForRoute(routeId, currentTime);
for (TripDetailsBean tripDetails : trips.getList()) {
// filter out interlined routes
if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId))
continue;
// filtered out by user
if (directionId != null && !tripDetails.getTrip().getDirectionId().equals(directionId))
continue;
if (!_presentationService.include(tripDetails.getStatus()))
continue;
VehicleActivityStructure activity = new VehicleActivityStructure();
activity.setRecordedAtTime(DateUtil.toXmlGregorianCalendar(tripDetails.getStatus().getLastUpdateTime()));
List<TimepointPredictionRecord> timePredictionRecords = null;
timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(routeId).getAgencyId(), tripDetails.getStatus());
activity.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
SiriSupportV2.fillMonitoredVehicleJourney(activity.getMonitoredVehicleJourney(), tripDetails.getTrip(), tripDetails.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetails.getStatus().isPredicted(), detailLevel, currentTime, null);
output.add(activity);
}
Collections.sort(output, new Comparator<VehicleActivityStructure>() {
public int compare(VehicleActivityStructure arg0, VehicleActivityStructure arg1) {
try {
SiriExtensionWrapper wrapper0 = (SiriExtensionWrapper) arg0.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
SiriExtensionWrapper wrapper1 = (SiriExtensionWrapper) arg1.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
return wrapper0.getDistances().getDistanceFromCall().compareTo(wrapper1.getDistances().getDistanceFromCall());
} catch (Exception e) {
return -1;
}
}
});
return output;
}
Aggregations