Search in sources :

Example 1 with ExtensionsStructure

use of uk.org.siri.siri_2.ExtensionsStructure 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 2 with ExtensionsStructure

use of uk.org.siri.siri_2.ExtensionsStructure 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;
}
Also used : OtherErrorStructure(uk.org.siri.siri_2.OtherErrorStructure) ServiceDeliveryErrorConditionStructure(uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure) LinesDeliveryStructure(uk.org.siri.siri_2.LinesDeliveryStructure) 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 ExtensionsStructure

use of uk.org.siri.siri_2.ExtensionsStructure in project onebusaway-application-modules by camsys.

the class ServiceAlertsHelperV2 method handleConsequences.

private void handleConsequences(ServiceAlertBean serviceAlert, PtSituationElementStructure ptSituation) {
    if (serviceAlert == null)
        return;
    List<SituationConsequenceBean> consequences = serviceAlert.getConsequences();
    if (consequences == null || consequences.isEmpty())
        return;
    PtConsequencesStructure ptConsequences = new PtConsequencesStructure();
    ptSituation.setConsequences(ptConsequences);
    for (SituationConsequenceBean consequence : consequences) {
        EEffect effect = consequence.getEffect();
        PtConsequenceStructure ptConsequenceStructure = new PtConsequenceStructure();
        ServiceConditionEnumeration serviceCondition = getEFfectAsCondition(effect);
        ptConsequenceStructure.getCondition().add(serviceCondition);
        String detourPath = consequence.getDetourPath();
        if (!StringUtils.isBlank(detourPath)) {
            ExtensionsStructure extensionStructure = new ExtensionsStructure();
            OneBusAwayConsequence oneBusAwayConsequence = new OneBusAwayConsequence();
            oneBusAwayConsequence.setDiversionPath(detourPath);
            extensionStructure.setAny(oneBusAwayConsequence);
            ptConsequenceStructure.setExtensions(extensionStructure);
        }
        ptConsequences.getConsequence().add(ptConsequenceStructure);
    }
}
Also used : PtConsequenceStructure(uk.org.siri.siri_2.PtConsequenceStructure) OneBusAwayConsequence(org.onebusaway.siri.OneBusAwayConsequence) PtConsequencesStructure(uk.org.siri.siri_2.PtConsequencesStructure) ExtensionsStructure(uk.org.siri.siri_2.ExtensionsStructure) SituationConsequenceBean(org.onebusaway.transit_data.model.service_alerts.SituationConsequenceBean) ServiceConditionEnumeration(uk.org.siri.siri_2.ServiceConditionEnumeration) EEffect(org.onebusaway.transit_data.model.service_alerts.EEffect)

Example 4 with ExtensionsStructure

use of uk.org.siri.siri_2.ExtensionsStructure in project onebusaway-application-modules by camsys.

the class SiriSupportV2 method getMonitoredCallStructure.

private static MonitoredCallStructure getMonitoredCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, DetailLevel detailLevel, long responseTimestamp) {
    MonitoredCallStructure monitoredCallStructure = new MonitoredCallStructure();
    monitoredCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber));
    StopPointRefStructure stopPointRef = new StopPointRefStructure();
    stopPointRef.setValue(stopBean.getId());
    NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure();
    stopPoint.setValue(stopBean.getName());
    if (prediction != null) {
        // do not allow predicted times to be less than ResponseTimestamp
        if (prediction.getTimepointPredictedArrivalTime() < responseTimestamp) {
            /*
         * monitoredCall has less precision than onwardCall (date vs.
         * timestamp) which results in a small amount of error when
         * converting back to timestamp. Add a second here to prevent
         * negative values from showing up in the UI (actual precision
         * of the value is 1 minute, so a second has little influence)
         */
            monitoredCallStructure.setExpectedArrivalTime(DateUtil.toXmlGregorianCalendar(responseTimestamp + 1000));
            monitoredCallStructure.setExpectedDepartureTime(DateUtil.toXmlGregorianCalendar(responseTimestamp + 1000));
        } else {
            monitoredCallStructure.setExpectedArrivalTime(DateUtil.toXmlGregorianCalendar(prediction.getTimepointPredictedArrivalTime()));
            monitoredCallStructure.setExpectedDepartureTime(DateUtil.toXmlGregorianCalendar(prediction.getTimepointPredictedArrivalTime()));
        }
    }
    // siri extensions
    // TODO - LCARABALLO - Distance Along Route Might Still need Extension
    /*SiriExtensionWrapper wrapper = new SiriExtensionWrapper();
    ExtensionsStructure distancesExtensions = new ExtensionsStructure();
    SiriDistanceExtension distances = new SiriDistanceExtension();

    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    df.setGroupingUsed(false);

    distances.setCallDistanceAlongRoute(Double.valueOf(df
        .format(distanceOfCallAlongTrip)));
  
    wrapper.setDistances(distances);
    distancesExtensions.setAny(wrapper);
    monitoredCallStructure.setExtensions(distancesExtensions);*/
    // distances
    NaturalLanguageStringStructure presentableDistance = new NaturalLanguageStringStructure();
    presentableDistance.setValue(presentationService.getPresentableDistance(distanceOfVehicleFromCall, index));
    monitoredCallStructure.setNumberOfStopsAway(BigInteger.valueOf(index));
    monitoredCallStructure.setDistanceFromStop(new BigDecimal(distanceOfVehicleFromCall).toBigInteger());
    monitoredCallStructure.setArrivalProximityText(presentableDistance);
    // basic
    if (detailLevel.equals(DetailLevel.BASIC) || detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) {
        monitoredCallStructure.getStopPointName().add(stopPoint);
    }
    // normal
    if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) {
        monitoredCallStructure.setStopPointRef(stopPointRef);
    }
    return monitoredCallStructure;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) MonitoredCallStructure(uk.org.siri.siri_2.MonitoredCallStructure) BigDecimal(java.math.BigDecimal)

Example 5 with ExtensionsStructure

use of uk.org.siri.siri_2.ExtensionsStructure in project onebusaway-application-modules by camsys.

the class SiriSupportV2 method fillAnnotatedLineStructure.

public static boolean fillAnnotatedLineStructure(AnnotatedLineStructure annotatedLineStructure, RouteResult routeResult, Map<Filters, String> filters, DetailLevel detailLevel, long currentTime) {
    Directions directions = new Directions();
    // Set Line Value
    LineRefStructure line = new LineRefStructure();
    line.setValue(routeResult.getId());
    NaturalLanguageStringStructure lineName = new NaturalLanguageStringStructure();
    lineName.setValue(routeResult.getShortName());
    // DETAIL - minimum: Return only the name and identifier of stops
    // ideally, this would return only stops with scheduled service
    annotatedLineStructure.setLineRef(line);
    annotatedLineStructure.getLineName().add(lineName);
    annotatedLineStructure.setDirections(directions);
    annotatedLineStructure.setMonitored(true);
    // Loop through Direction Ids
    for (RouteDirection direction : routeResult.getDirections()) {
        // Check for existing stops in direction
        if (direction == null | direction.getStops().size() == 0)
            continue;
        String directionId = direction.getDirectionId();
        // Journey patterns - holds stop points for direction
        JourneyPattern pattern = new JourneyPattern();
        JourneyPatterns patterns = new JourneyPatterns();
        // Directions
        DirectionRefStructure dirRefStructure = new DirectionRefStructure();
        dirRefStructure.setValue(directionId);
        RouteDirectionStructure routeDirectionStructure = new RouteDirectionStructure();
        NaturalLanguageStringStructure directionName = new NaturalLanguageStringStructure();
        directionName.setValue(direction.getDestination());
        routeDirectionStructure.getDirectionName().add(directionName);
        directions.getDirection().add(routeDirectionStructure);
        // Destination
        Destinations destinations = new Destinations();
        AnnotatedDestinationStructure annotatedDest = new AnnotatedDestinationStructure();
        DestinationRefStructure destRef = new DestinationRefStructure();
        destRef.setValue(direction.getDestination());
        annotatedDest.setDestinationRef(destRef);
        destinations.getDestination().add(annotatedDest);
        // Stops
        StopsInPattern stopsInPattern = new StopsInPattern();
        List<StopOnRoute> scheduledStops = new ArrayList<StopOnRoute>();
        List<StopOnRoute> allStops = new ArrayList<StopOnRoute>();
        // Categorize by Scheduled and Unscheduled Stops
        for (StopOnRoute stop : direction.getStops()) {
            if (stop.getHasUpcomingScheduledStop() != null && stop.getHasUpcomingScheduledStop())
                scheduledStops.add(stop);
            allStops.add(stop);
        }
        if (detailLevel.equals(DetailLevel.NORMAL)) {
            for (int i = 0; i < scheduledStops.size(); i++) {
                StopOnRoute stop = direction.getStops().get(i);
                BigDecimal stopLat = new BigDecimal(stop.getLatitude());
                BigDecimal stopLon = new BigDecimal(stop.getLongitude());
                LocationStructure location = new LocationStructure();
                location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
                pointInPattern.setLocation(location);
                pointInPattern.setOrder(BigInteger.valueOf(i));
                NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
                stopName.setValue(stop.getName());
                pointInPattern.getStopName().add(stopName);
                StopPointRefStructure spr = new StopPointRefStructure();
                spr.setValue(stop.getId());
                stopsInPattern.getStopPointInPattern().add(pointInPattern);
            }
        }
        if (detailLevel.equals(DetailLevel.STOPS) || detailLevel.equals(DetailLevel.FULL)) {
            for (int i = 0; i < allStops.size(); i++) {
                StopOnRoute stop = direction.getStops().get(i);
                Boolean hasUpcomingScheduledService = stop.getHasUpcomingScheduledStop();
                BigDecimal stopLat = new BigDecimal(stop.getLatitude());
                BigDecimal stopLon = new BigDecimal(stop.getLongitude());
                LocationStructure location = new LocationStructure();
                location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                StopPointRefStructure spr = new StopPointRefStructure();
                spr.setValue(stop.getId());
                StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
                pointInPattern.setLocation(location);
                pointInPattern.setOrder(BigInteger.valueOf(i));
                NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
                stopName.setValue(stop.getName());
                pointInPattern.getStopName().add(stopName);
                pointInPattern.setStopPointRef(spr);
                stopsInPattern.getStopPointInPattern().add(pointInPattern);
                // HasUpcomingService Extension
                SiriUpcomingServiceExtension upcomingService = new SiriUpcomingServiceExtension();
                upcomingService.setUpcomingScheduledService(hasUpcomingScheduledService);
                ExtensionsStructure upcomingServiceExtensions = new ExtensionsStructure();
                upcomingServiceExtensions.setAny(upcomingService);
                pointInPattern.setExtensions(upcomingServiceExtensions);
            }
        }
        String includePolylineFilter = filters.get(Filters.INCLUDE_POLYLINES);
        if (includePolylineFilter != null && passFilter("true", includePolylineFilter)) {
            // Polyline Extension
            SiriPolyLinesExtension polylines = new SiriPolyLinesExtension();
            for (String polyline : direction.getPolylines()) {
                polylines.getPolylines().add(polyline);
            }
            ExtensionsStructure PolylineExtension = new ExtensionsStructure();
            PolylineExtension.setAny(polylines);
            routeDirectionStructure.setExtensions(PolylineExtension);
        }
        routeDirectionStructure.setJourneyPatterns(patterns);
        pattern.setStopsInPattern(stopsInPattern);
        patterns.getJourneyPattern().add(pattern);
        routeDirectionStructure.setDirectionRef(dirRefStructure);
    }
    return true;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) DestinationRefStructure(uk.org.siri.siri_2.DestinationRefStructure) Directions(uk.org.siri.siri_2.AnnotatedLineStructure.Directions) Destinations(uk.org.siri.siri_2.AnnotatedLineStructure.Destinations) ArrayList(java.util.ArrayList) LocationStructure(uk.org.siri.siri_2.LocationStructure) ExtensionsStructure(uk.org.siri.siri_2.ExtensionsStructure) JourneyPattern(uk.org.siri.siri_2.RouteDirectionStructure.JourneyPatterns.JourneyPattern) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) RouteDirection(org.onebusaway.api.actions.siri.model.RouteDirection) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) AnnotatedDestinationStructure(uk.org.siri.siri_2.AnnotatedDestinationStructure) SiriPolyLinesExtension(org.onebusaway.transit_data_federation.siri.SiriPolyLinesExtension) StopPointInPatternStructure(uk.org.siri.siri_2.StopPointInPatternStructure) JourneyPatterns(uk.org.siri.siri_2.RouteDirectionStructure.JourneyPatterns) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) StopsInPattern(uk.org.siri.siri_2.RouteDirectionStructure.JourneyPatterns.JourneyPattern.StopsInPattern) BigDecimal(java.math.BigDecimal) RouteDirectionStructure(uk.org.siri.siri_2.RouteDirectionStructure) SiriUpcomingServiceExtension(org.onebusaway.transit_data_federation.siri.SiriUpcomingServiceExtension) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) StopOnRoute(org.onebusaway.api.actions.siri.model.StopOnRoute)

Aggregations

ExtensionsStructure (uk.org.siri.siri_2.ExtensionsStructure)4 SiriUpcomingServiceExtension (org.onebusaway.transit_data_federation.siri.SiriUpcomingServiceExtension)3 BigDecimal (java.math.BigDecimal)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 ErrorDescriptionStructure (uk.org.siri.siri_2.ErrorDescriptionStructure)2 NaturalLanguageStringStructure (uk.org.siri.siri_2.NaturalLanguageStringStructure)2 OtherErrorStructure (uk.org.siri.siri_2.OtherErrorStructure)2 ServiceDeliveryErrorConditionStructure (uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure)2 Siri (uk.org.siri.siri_2.Siri)2 StopPointRefStructure (uk.org.siri.siri_2.StopPointRefStructure)2 ArrayList (java.util.ArrayList)1 RouteDirection (org.onebusaway.api.actions.siri.model.RouteDirection)1 StopOnRoute (org.onebusaway.api.actions.siri.model.StopOnRoute)1 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)1 OneBusAwayConsequence (org.onebusaway.siri.OneBusAwayConsequence)1 EEffect (org.onebusaway.transit_data.model.service_alerts.EEffect)1 SituationConsequenceBean (org.onebusaway.transit_data.model.service_alerts.SituationConsequenceBean)1 SiriPolyLinesExtension (org.onebusaway.transit_data_federation.siri.SiriPolyLinesExtension)1 AnnotatedDestinationStructure (uk.org.siri.siri_2.AnnotatedDestinationStructure)1