Search in sources :

Example 6 with AnnotatedStopPointStructure

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

the class RealtimeServiceTest method testStopPointsByRoute.

@Test
public void testStopPointsByRoute() throws Exception {
    when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean);
    when(transitDataService.getStopsForRoute("1_100194")).thenReturn(stopsForRouteBean);
    when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
    LineDirectionStructure lds = new LineDirectionStructure();
    DirectionRefStructure drs = new DirectionRefStructure();
    LineRefStructure lrs = new LineRefStructure();
    lds.setDirectionRef(drs);
    lds.setLineRef(lrs);
    drs.setValue("0");
    lrs.setValue("1_100194");
    LocationStructure ls = new LocationStructure();
    BigDecimal lat = new BigDecimal(47.610813);
    BigDecimal lon = new BigDecimal(-122.338662);
    ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
    stopName.setValue("3rd Ave & Pine St");
    List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
    stopNames.add(stopName);
    StopPointRefStructure stopPointRef = new StopPointRefStructure();
    stopPointRef.setValue("1_430");
    Boolean monitored = true;
    AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
    mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
    mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
    mockStopPoint.setLocation(ls);
    mockStopPoint.getStopName().add(stopName);
    mockStopPoint.setStopPointRef(stopPointRef);
    mockStopPoint.setMonitored(monitored);
    // REALTIME ARGUMENTS
    // Agency Ids
    List<String> agencyIds = new ArrayList<String>();
    String agencyId = "1";
    agencyIds.add(agencyId);
    // Route Ids
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    AgencyAndId routeId = AgencyAndIdLibrary.convertFromString("1_100194");
    routeIds.add(routeId);
    // Detail Level
    DetailLevel detailLevel = DetailLevel.NORMAL;
    // Time
    long time = System.currentTimeMillis();
    // Filters
    Map<Filters, String> filters = new HashMap<Filters, String>();
    Map<Boolean, List<AnnotatedStopPointStructure>> actualResult = realtimeService.getAnnotatedStopPointStructures(agencyIds, routeIds, detailLevel, time, filters);
    AnnotatedStopPointStructure actualStopPoint = actualResult.get(true).get(0);
    assertTrue(isEqual(mockStopPoint, actualStopPoint));
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) LineDirectionStructure(uk.org.siri.siri_2.LineDirectionStructure) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) ArrayList(java.util.ArrayList) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) Matchers.anyString(org.mockito.Matchers.anyString) LocationStructure(uk.org.siri.siri_2.LocationStructure) BigDecimal(java.math.BigDecimal) Filters(org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) ArrayList(java.util.ArrayList) List(java.util.List) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) Test(org.junit.Test)

Example 7 with AnnotatedStopPointStructure

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

the class StopPointsActionTest method initialize.

@Before
public void initialize() throws Exception {
    // Agencies
    Map<String, List<CoordinateBounds>> agencies = new HashMap<String, List<CoordinateBounds>>();
    agencies.put("1", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.410813, -122.038662, 47.810813, -122.638662))));
    agencies.put("3", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(0.0, 0.0, 0.0, 0.0))));
    agencies.put("40", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.510813, -122.138662, 47.710813, -122.538662))));
    // Route Bean
    Builder routeBuilder = RouteBean.builder();
    routeBuilder.setAgency(new AgencyBean());
    routeBuilder.setId("1_100194");
    routeBean = routeBuilder.create();
    // Route Bean List
    routes = new ArrayList<RouteBean>(1);
    routes.add(routeBean);
    // Stop Bean
    stopBean = new StopBean();
    stopBean.setId("1_430");
    stopBean.setName("3rd Ave & Pine St");
    stopBean.setLon(-122.338662);
    stopBean.setLat(47.610813);
    stopBean.setRoutes(routes);
    // Stop Bean List
    stops = new ArrayList<StopBean>(1);
    stops.add(stopBean);
    // Stop Group
    stopIds = new ArrayList<String>(1);
    stopIds.add(stopBean.getId());
    stopGroupName = new NameBean("destination", "Destination");
    stopGroup = new StopGroupBean();
    stopGroup.setId("0");
    stopGroup.setStopIds(stopIds);
    stopGroup.setName(stopGroupName);
    // Stop Group List
    stopGroups = new ArrayList<StopGroupBean>(1);
    stopGroups.add(stopGroup);
    // Stop Grouping
    stopGrouping = new StopGroupingBean();
    stopGrouping.setStopGroups(stopGroups);
    // Stop Grouping List
    List<StopGroupingBean> stopGroupings = new ArrayList<StopGroupingBean>(1);
    stopGroupings.add(stopGrouping);
    // Stops For Route
    stopsForRouteBean = new StopsForRouteBean();
    stopsForRouteBean.setRoute(routeBean);
    stopsForRouteBean.setStopGroupings(stopGroupings);
    stopsForRouteBean.setStops(stops);
    // LineDirectionStructure
    LineDirectionStructure lds = new LineDirectionStructure();
    DirectionRefStructure drs = new DirectionRefStructure();
    LineRefStructure lrs = new LineRefStructure();
    lds.setDirectionRef(drs);
    lds.setLineRef(lrs);
    drs.setValue("0");
    lrs.setValue("1_100194");
    // Location Structure
    LocationStructure ls = new LocationStructure();
    BigDecimal lat = new BigDecimal(47.610813);
    BigDecimal lon = new BigDecimal(-122.338662);
    ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    // StopNames
    NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
    stopName.setValue("3rd Ave & Pine St");
    List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
    stopNames.add(stopName);
    // StopPointRef
    StopPointRefStructure stopPointRef = new StopPointRefStructure();
    stopPointRef.setValue("1_430");
    // Monitored
    Boolean monitored = true;
    // AnnotatedStopPointStructure
    AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
    mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
    mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
    mockStopPoint.setLocation(ls);
    mockStopPoint.getStopName().add(stopName);
    mockStopPoint.setStopPointRef(stopPointRef);
    mockStopPoint.setMonitored(monitored);
    List<AnnotatedStopPointStructure> mockStopPoints = new ArrayList<AnnotatedStopPointStructure>(1);
    mockStopPoints.add(mockStopPoint);
    Map<Boolean, List<AnnotatedStopPointStructure>> annotatedStopPointMap = new HashMap<Boolean, List<AnnotatedStopPointStructure>>();
    annotatedStopPointMap.put(true, mockStopPoints);
    when(realtimeService.getAnnotatedStopPointStructures(anyListOf(String.class), anyListOf(AgencyAndId.class), any(DetailLevel.class), anyLong(), anyMapOf(Filters.class, String.class))).thenReturn(annotatedStopPointMap);
    // XML Serializer
    SiriXmlSerializerV2 serializer = new SiriXmlSerializerV2();
    when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
    // Print Writer
    PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
        // Do nothing
        }
    });
    when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
    when(transitDataService.getRouteForId("1_430")).thenReturn(routeBean);
    when(transitDataService.getStopsForRoute("1_430")).thenReturn(stopsForRouteBean);
    when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
    when(transitDataService.getAgencyIdsWithCoverageArea()).thenReturn(agencies);
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) LineDirectionStructure(uk.org.siri.siri_2.LineDirectionStructure) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) Builder(org.onebusaway.transit_data.model.RouteBean.Builder) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matchers.anyString(org.mockito.Matchers.anyString) LocationStructure(uk.org.siri.siri_2.LocationStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Filters(org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters) ArrayList(java.util.ArrayList) List(java.util.List) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) PrintWriter(java.io.PrintWriter) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) SiriXmlSerializerV2(org.onebusaway.transit_data_federation.siri.SiriXmlSerializerV2) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Before(org.junit.Before)

Example 8 with AnnotatedStopPointStructure

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

the class RealtimeServiceV2Impl method getAnnotatedLineStructures.

@Override
public Map<Boolean, List<AnnotatedLineStructure>> getAnnotatedLineStructures(List<String> agencyIds, List<AgencyAndId> routeIds, DetailLevel detailLevel, long currentTime, Map<Filters, String> filters) {
    // Store processed StopBean as AnnotatedStopPointStructure
    List<AnnotatedLineStructure> annotatedLines = new ArrayList<AnnotatedLineStructure>();
    // AnnotatedStopPointStructures List with hasUpcomingScheduledService
    Map<Boolean, List<AnnotatedLineStructure>> output = new HashMap<Boolean, List<AnnotatedLineStructure>>();
    Boolean upcomingServiceAllStops = null;
    for (AgencyAndId rteId : routeIds) {
        String routeId = AgencyAndId.convertToString(rteId);
        RouteBean routeBean = _transitDataService.getRouteForId(routeId);
        // Filter By AgencyID
        if (routeBean.getAgency() == null || !agencyIds.contains(routeBean.getAgency().getId()))
            continue;
        AnnotatedLineStructure annotatedLineStructure = new AnnotatedLineStructure();
        RouteResult routeResult = getRouteResult(routeBean, filters);
        // Skip Routes with no stops
        if (routeResult.getDirections() == null || routeResult.getDirections().size() == 0)
            continue;
        boolean isValid = SiriSupportV2.fillAnnotatedLineStructure(annotatedLineStructure, routeResult, filters, detailLevel, currentTime);
        if (isValid)
            annotatedLines.add(annotatedLineStructure);
    }
    output.put(upcomingServiceAllStops, annotatedLines);
    return output;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) RouteResult(org.onebusaway.api.actions.siri.model.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AnnotatedLineStructure(uk.org.siri.siri_2.AnnotatedLineStructure)

Example 9 with AnnotatedStopPointStructure

use of uk.org.siri.siri_2.AnnotatedStopPointStructure 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

ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 List (java.util.List)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 AnnotatedStopPointStructure (uk.org.siri.siri_2.AnnotatedStopPointStructure)6 BigDecimal (java.math.BigDecimal)4 Filters (org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters)4 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)4 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)4 DirectionRefStructure (uk.org.siri.siri_2.DirectionRefStructure)4 LineDirectionStructure (uk.org.siri.siri_2.LineDirectionStructure)4 LineRefStructure (uk.org.siri.siri_2.LineRefStructure)4 LocationStructure (uk.org.siri.siri_2.LocationStructure)4 NaturalLanguageStringStructure (uk.org.siri.siri_2.NaturalLanguageStringStructure)4 StopPointRefStructure (uk.org.siri.siri_2.StopPointRefStructure)4 Matchers.anyString (org.mockito.Matchers.anyString)3 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)3 RouteBean (org.onebusaway.transit_data.model.RouteBean)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 IOException (java.io.IOException)2