Search in sources :

Example 1 with StopPointsDeliveryStructure

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

Aggregations

Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 SiriUpcomingServiceExtension (org.onebusaway.transit_data_federation.siri.SiriUpcomingServiceExtension)1 ErrorDescriptionStructure (uk.org.siri.siri_2.ErrorDescriptionStructure)1 ExtensionsStructure (uk.org.siri.siri_2.ExtensionsStructure)1 OtherErrorStructure (uk.org.siri.siri_2.OtherErrorStructure)1 ServiceDeliveryErrorConditionStructure (uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure)1 Siri (uk.org.siri.siri_2.Siri)1 StopPointsDeliveryStructure (uk.org.siri.siri_2.StopPointsDeliveryStructure)1