Search in sources :

Example 1 with ServiceDelivery

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;
}
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)

Example 2 with ServiceDelivery

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;
}
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)

Example 3 with ServiceDelivery

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;
}
Also used : OtherErrorStructure(uk.org.siri.siri_2.OtherErrorStructure) VehicleMonitoringDeliveryStructure(uk.org.siri.siri_2.VehicleMonitoringDeliveryStructure) 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)

Example 4 with ServiceDelivery

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);
}
Also used : HashMap(java.util.HashMap) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 5 with ServiceDelivery

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);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) VehicleActivityStructure(uk.org.siri.siri_2.VehicleActivityStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Aggregations

PtSituationElementStructure (uk.org.siri.siri_2.PtSituationElementStructure)5 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)4 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 HashMap (java.util.HashMap)3 ErrorDescriptionStructure (uk.org.siri.siri_2.ErrorDescriptionStructure)3 OtherErrorStructure (uk.org.siri.siri_2.OtherErrorStructure)3 ServiceDeliveryErrorConditionStructure (uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure)3 Siri (uk.org.siri.siri_2.Siri)3 ArrayList (java.util.ArrayList)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)2 SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)2 ServiceDelivery (uk.org.siri.siri_2.ServiceDelivery)2 SituationExchangeDeliveryStructure (uk.org.siri.siri_2.SituationExchangeDeliveryStructure)2 Situations (uk.org.siri.siri_2.SituationExchangeDeliveryStructure.Situations)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1