Search in sources :

Example 1 with StopsBean

use of org.onebusaway.transit_data.model.StopsBean in project onebusaway-application-modules by camsys.

the class StopsBeanServiceImpl method constructResult.

private StopsBean constructResult(List<StopBean> stopBeans, boolean limitExceeded) {
    Collections.sort(stopBeans, new StopBeanIdComparator());
    StopsBean result = new StopsBean();
    result.setStops(stopBeans);
    result.setLimitExceeded(limitExceeded);
    return result;
}
Also used : StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 2 with StopsBean

use of org.onebusaway.transit_data.model.StopsBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getStopsForBounds.

private List<StopBean> getStopsForBounds(CoordinateBounds bounds) {
    if (bounds != null) {
        SearchQueryBean queryBean = new SearchQueryBean();
        queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
        queryBean.setBounds(bounds);
        queryBean.setMaxCount(Integer.MAX_VALUE);
        StopsBean stops = _transitDataService.getStops(queryBean);
        return stops.getStops();
    }
    return new ArrayList<StopBean>();
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) ArrayList(java.util.ArrayList) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 3 with StopsBean

use of org.onebusaway.transit_data.model.StopsBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceTest method testStopPointsByBounds.

@Test
public void testStopPointsByBounds() throws Exception {
    // MOCKS
    // Coordinate Bounds
    CoordinateBounds bounds = new CoordinateBounds(Double.parseDouble("47.612813"), Double.parseDouble("-122.339662"), Double.parseDouble("47.608813"), Double.parseDouble("-122.337662"));
    // Stops For Bounds
    StopsBean stopsBean = new StopsBean();
    stopsBean.setStops(stops);
    when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean);
    when(transitDataService.getStops(any(SearchQueryBean.class))).thenReturn(stopsBean);
    when(transitDataService.getStopsForRoute("1_100194")).thenReturn(stopsForRouteBean);
    when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
    // EXPECTED
    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(bounds, 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) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) LocationStructure(uk.org.siri.siri_2.LocationStructure) Filters(org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) ArrayList(java.util.ArrayList) List(java.util.List) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) BigDecimal(java.math.BigDecimal) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean) Test(org.junit.Test)

Example 4 with StopsBean

use of org.onebusaway.transit_data.model.StopsBean in project onebusaway-application-modules by camsys.

the class StopForCodeAction method execute.

public String execute() throws Exception {
    _log.info("in stop for code");
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null)
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    if (_stopCode == null || _stopCode.length() == 0)
        return INPUT;
    if (_stop != null) {
        _stops = Arrays.asList(_stop);
    } else {
        _log.info("searching on stopCode=" + _stopCode);
        SearchQueryBean searchQuery = new SearchQueryBean();
        searchQuery.setBounds(bounds);
        searchQuery.setMaxCount(5);
        searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
        searchQuery.setQuery(_stopCode);
        StopsBean stopsBean = _transitDataService.getStops(searchQuery);
        _stops = stopsBean.getStops();
    }
    logUserInteraction("query", _stopCode);
    if (_stops.size() == 0) {
        sessionMap.put("messageFromAction", getText(Messages.NO_STOPS_WERE_FOUND));
        sessionMap.put("backAction", "stops-index");
        return "noStopsFound";
    } else if (_stops.size() == 1) {
        StopBean stop = _stops.get(0);
        _stopIds = Arrays.asList(stop.getId());
        return SUCCESS;
    } else {
        sessionMap.put("stops", _stops);
        return "multipleStopsFound";
    }
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 5 with StopsBean

use of org.onebusaway.transit_data.model.StopsBean in project onebusaway-application-modules by camsys.

the class StopsWithinBoundsAction method execute.

@Override
public String execute() {
    if (_bounds == null) {
        return SUCCESS;
    }
    SearchQueryBean queryBean = new SearchQueryBean();
    queryBean.setType(SearchQueryBean.EQueryType.BOUNDS_OR_CLOSEST);
    queryBean.setBounds(_bounds);
    queryBean.setMaxCount(200);
    StopsBean stops = null;
    try {
        stops = _transitDataService.getStops(queryBean);
    } catch (OutOfServiceAreaServiceException e) {
        _log.error(" invalid results: ", e);
        return SUCCESS;
    }
    for (StopBean stop : stops.getStops()) {
        String agencyId = AgencyAndIdLibrary.convertFromString(stop.getId()).getAgencyId();
        if (_transitDataService.stopHasRevenueService(agencyId, stop.getId())) {
            _stops.add(new StopOnRoute(stop));
        }
    }
    return SUCCESS;
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Aggregations

StopsBean (org.onebusaway.transit_data.model.StopsBean)12 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)9 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 StopBean (org.onebusaway.transit_data.model.StopBean)7 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 List (java.util.List)2 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 ParseException (org.apache.lucene.queryParser.ParseException)1 Actions (org.apache.struts2.convention.annotation.Actions)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Filters (org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters)1 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)1 StopOnRoute (org.onebusaway.enterprise.webapp.actions.api.model.StopOnRoute)1 InvalidArgumentServiceException (org.onebusaway.exceptions.InvalidArgumentServiceException)1