Search in sources :

Example 1 with RouteForDirection

use of org.onebusaway.api.actions.siri.model.RouteForDirection in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getStopRouteDirection.

private StopRouteDirection getStopRouteDirection(StopBean stop, List<StopsForRouteBean> stopsForRouteList, Map<Filters, String> filters) {
    // Filter Values
    String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
    String directionIdFilter = filters.get(Filters.DIRECTION_REF);
    StopRouteDirection stopRouteDirection = new StopRouteDirection(stop);
    for (StopsForRouteBean stopsForRoute : stopsForRouteList) // Check to see which stop group the specified stop exists in (usually 2 stop groups)
    for (StopGroupingBean stopGrouping : stopsForRoute.getStopGroupings()) {
        for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
            NameBean name = stopGroup.getName();
            String type = name.getType();
            String directionId = stopGroup.getId();
            RouteBean route = stopsForRoute.getRoute();
            // Destination and DirectionId Filter
            if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
                continue;
            // filter out route directions that don't stop at this stop
            if (!stopGroup.getStopIds().contains(stop.getId()))
                continue;
            // filter hasUpcomingScheduledService
            Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((route.getAgency() != null ? route.getAgency().getId() : null), SystemTime.currentTimeMillis(), stop.getId(), stopsForRoute.getRoute().getId(), directionId);
            String hasUpcomingScheduledServiceVal = String.valueOf(hasUpcomingScheduledService);
            if (!hasUpcomingScheduledServiceVal.trim().equals("false")) {
                hasUpcomingScheduledServiceVal = "true";
            }
            if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter))
                continue;
            stopRouteDirection.addRouteDirection(new RouteForDirection(route.getId(), directionId, hasUpcomingScheduledService));
        }
    }
    return stopRouteDirection;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteForDirection(org.onebusaway.api.actions.siri.model.RouteForDirection) NameBean(org.onebusaway.transit_data.model.NameBean)

Example 2 with RouteForDirection

use of org.onebusaway.api.actions.siri.model.RouteForDirection in project onebusaway-application-modules by camsys.

the class SiriSupportV2 method fillAnnotatedStopPointStructure.

public static boolean fillAnnotatedStopPointStructure(AnnotatedStopPointStructure annotatedStopPoint, StopRouteDirection stopRouteDirection, Map<Filters, String> filters, DetailLevel detailLevel, long currentTime) {
    StopBean stopBean = stopRouteDirection.getStop();
    List<RouteForDirection> routeDirections = stopRouteDirection.getRouteDirections();
    // Set Stop Name
    NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
    stopName.setValue(stopBean.getName());
    // Set Route and Direction
    Lines lines = new Lines();
    for (RouteForDirection routeDirection : routeDirections) {
        String directionId = routeDirection.getDirectionId();
        String routeId = routeDirection.getRouteId();
        LineRefStructure line = new LineRefStructure();
        line.setValue(routeId);
        DirectionRefStructure direction = new DirectionRefStructure();
        direction.setValue(directionId);
        LineDirectionStructure lineDirection = new LineDirectionStructure();
        lineDirection.setDirectionRef(direction);
        lineDirection.setLineRef(line);
        lines.getLineRefOrLineDirection().add(lineDirection);
    }
    // Set Lat and Lon
    BigDecimal stopLat = new BigDecimal(stopBean.getLat());
    BigDecimal stopLon = new BigDecimal(stopBean.getLon());
    LocationStructure location = new LocationStructure();
    location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    // Set StopId
    StopPointRefStructure stopPointRef = new StopPointRefStructure();
    stopPointRef.setValue(stopBean.getId());
    // Details -- minimum
    annotatedStopPoint.getStopName().add(stopName);
    // Details -- normal
    if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.FULL)) {
        annotatedStopPoint.setLocation(location);
        annotatedStopPoint.setLines(lines);
        annotatedStopPoint.setMonitored(true);
    }
    annotatedStopPoint.setStopPointRef(stopPointRef);
    return true;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) LineDirectionStructure(uk.org.siri.siri_2.LineDirectionStructure) StopBean(org.onebusaway.transit_data.model.StopBean) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) RouteForDirection(org.onebusaway.api.actions.siri.model.RouteForDirection) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) LocationStructure(uk.org.siri.siri_2.LocationStructure) BigDecimal(java.math.BigDecimal) Lines(uk.org.siri.siri_2.AnnotatedStopPointStructure.Lines)

Aggregations

RouteForDirection (org.onebusaway.api.actions.siri.model.RouteForDirection)2 BigDecimal (java.math.BigDecimal)1 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 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 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1 Lines (uk.org.siri.siri_2.AnnotatedStopPointStructure.Lines)1 DirectionRefStructure (uk.org.siri.siri_2.DirectionRefStructure)1 LineDirectionStructure (uk.org.siri.siri_2.LineDirectionStructure)1 LineRefStructure (uk.org.siri.siri_2.LineRefStructure)1 LocationStructure (uk.org.siri.siri_2.LocationStructure)1 NaturalLanguageStringStructure (uk.org.siri.siri_2.NaturalLanguageStringStructure)1 StopPointRefStructure (uk.org.siri.siri_2.StopPointRefStructure)1