Search in sources :

Example 1 with StopMonitoringDeliveryStructure

use of uk.org.siri.siri_2.StopMonitoringDeliveryStructure 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;
}
Also used : OtherErrorStructure(uk.org.siri.siri_2.OtherErrorStructure) StopMonitoringDeliveryStructure(uk.org.siri.siri_2.StopMonitoringDeliveryStructure) ServiceDeliveryErrorConditionStructure(uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Siri(uk.org.siri.siri_2.Siri) ServiceDelivery(uk.org.siri.siri_2.ServiceDelivery) ErrorDescriptionStructure(uk.org.siri.siri_2.ErrorDescriptionStructure)

Aggregations

Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 ErrorDescriptionStructure (uk.org.siri.siri_2.ErrorDescriptionStructure)1 OtherErrorStructure (uk.org.siri.siri_2.OtherErrorStructure)1 ServiceDelivery (uk.org.siri.siri_2.ServiceDelivery)1 ServiceDeliveryErrorConditionStructure (uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure)1 Siri (uk.org.siri.siri_2.Siri)1 StopMonitoringDeliveryStructure (uk.org.siri.siri_2.StopMonitoringDeliveryStructure)1