Search in sources :

Example 51 with StopBean

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

the class NearbyStopsBeanServiceImplTest method test.

@Test
public void test() {
    AgencyAndId stopIdA = new AgencyAndId("1", "stopA");
    AgencyAndId stopIdB = new AgencyAndId("1", "stopB");
    StopBean stop = new StopBean();
    stop.setId(AgencyAndIdLibrary.convertToString(stopIdA));
    stop.setLat(47.0);
    stop.setLon(-122.0);
    List<AgencyAndId> stopIds = new ArrayList<AgencyAndId>();
    stopIds.add(stopIdA);
    stopIds.add(stopIdB);
    CoordinateBounds bounds = SphericalGeometryLibrary.bounds(stop.getLat(), stop.getLon(), 400);
    Mockito.when(_geoBeanService.getStopsByBounds(bounds)).thenReturn(stopIds);
    List<AgencyAndId> nearby = _service.getNearbyStops(stop, 400);
    assertEquals(1, nearby.size());
    assertTrue(nearby.contains(stopIdB));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Example 52 with StopBean

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

the class StopBeanServiceImplTest method testGetStopForId.

@Test
public void testGetStopForId() {
    AgencyAndId stopId = new AgencyAndId("29", "1109");
    StopEntryImpl stopEntry = new StopEntryImpl(stopId, 47.1, -122.1);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopId)).thenReturn(stopEntry);
    StopNarrative.Builder builder = StopNarrative.builder();
    builder.setCode("1109-b");
    builder.setDescription("stop description");
    builder.setLocationType(0);
    builder.setName("stop name");
    builder.setUrl("http://some/url");
    builder.setDirection("N");
    StopNarrative stop = builder.create();
    Mockito.when(_narrativeService.getStopForId(stopId)).thenReturn(stop);
    AgencyAndId routeId = new AgencyAndId("1", "route");
    Set<AgencyAndId> routeIds = new HashSet<AgencyAndId>();
    routeIds.add(routeId);
    Mockito.when(_routeService.getRouteCollectionIdsForStop(stopId)).thenReturn(routeIds);
    RouteBean.Builder routeBuilder = RouteBean.builder();
    routeBuilder.setId(AgencyAndIdLibrary.convertToString(routeId));
    RouteBean route = routeBuilder.create();
    Mockito.when(_routeBeanService.getRouteForId(routeId)).thenReturn(route);
    StopBean stopBean = _service.getStopForId(stopId);
    assertNotNull(stopBean);
    assertEquals(stopId.toString(), stopBean.getId());
    assertEquals(stop.getName(), stopBean.getName());
    assertEquals(stopEntry.getStopLat(), stopBean.getLat(), 0.0);
    assertEquals(stopEntry.getStopLon(), stopBean.getLon(), 0.0);
    assertEquals(stop.getCode(), stopBean.getCode());
    assertEquals(stop.getLocationType(), stopBean.getLocationType());
    List<RouteBean> routes = stopBean.getRoutes();
    assertEquals(1, routes.size());
    assertSame(route, routes.get(0));
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopBean(org.onebusaway.transit_data.model.StopBean) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with StopBean

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

the class BookmarkStopAction method execute.

@Override
public String execute() throws Exception {
    _log.debug("in execute! with input=" + getInput() + " and stops=" + _stops + " and stopIds=" + _stopIds + " and user=" + _currentUser);
    if (PREVIOUS_MENU_ITEM.equals(getInput()) || "9".equals(getInput())) {
        clearNextAction();
        return "index";
    }
    if (_currentUser != null && !_currentUser.isRememberPreferencesEnabled())
        return "preferences_disabled";
    setNextAction("bookmarks/bookmark-stop");
    if (_currentUser == null) {
        // something went wrong, bail
        addMessage(Messages.BOOKMARKS_EMPTY);
        addMessage(Messages.HOW_TO_GO_BACK);
        addMessage(Messages.TO_REPEAT);
        return INPUT;
    }
    // from here we have a currentUser
    if (_stops.isEmpty()) {
        _log.debug("empty stops!");
        addMessage(Messages.BOOKMARKS_EMPTY);
        addMessage(Messages.HOW_TO_GO_BACK);
        addMessage(Messages.TO_REPEAT);
        return INPUT;
    }
    // to allow REPEAT/BACK choices to still work, we need to limit bookmarks to 7
    List<BookmarkWithStopsBean> bookmarks = _bookmarkPresentationService.getBookmarksWithStops(_currentUser.getBookmarks());
    if (bookmarks.size() > MAX_BOOKMARKS) {
        addMessage(Messages.BOOKMARKS_AT_CAPACITY);
        addMessage(Messages.HOW_TO_GO_BACK);
        return SUCCESS;
    }
    // make sure the bookmark isn't already there
    for (BookmarkWithStopsBean bookmark : bookmarks) {
        for (StopBean stopBean : _stops) {
            if (bookmark.getStops().contains(stopBean)) {
                addMessage(Messages.BOOKMARK_ALREADY_ADDED);
                addMessage(Messages.HOW_TO_GO_BACK);
                return SUCCESS;
            }
        }
    }
    // add the bookmark
    String name = _bookmarkPresentationService.getNameForStops(_stops);
    List<String> stopIds = MappingLibrary.map(_stops, "id");
    _currentUserService.addStopBookmark(name, stopIds, new RouteFilter());
    logUserInteraction("stopIds", stopIds);
    addMessage(Messages.BOOKMARK_ADDED);
    return SUCCESS;
}
Also used : BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) StopBean(org.onebusaway.transit_data.model.StopBean) RouteFilter(org.onebusaway.users.model.properties.RouteFilter)

Example 54 with StopBean

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

the class ServiceAlertsHelperV2 method addSituationExchangeToSiriForStops.

public void addSituationExchangeToSiriForStops(ServiceDelivery serviceDelivery, List<MonitoredStopVisitStructure> visits, TransitDataService transitDataService, List<AgencyAndId> stopIds) {
    Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>();
    for (MonitoredStopVisitStructure visit : visits) {
        if (visit.getMonitoredVehicleJourney() != null)
            addSituationElement(transitDataService, ptSituationElements, visit.getMonitoredVehicleJourney().getSituationRef());
    }
    if (stopIds != null && stopIds.size() > 0) {
        for (AgencyAndId stopId : stopIds) {
            String stopIdString = stopId.toString();
            // First get service alerts for the stop
            SituationQueryBean query = new SituationQueryBean();
            List<String> stopIdStrings = new ArrayList<String>();
            stopIdStrings.add(stopIdString);
            SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
            query.getAffects().add(affects);
            affects.setStopId(stopIdString);
            addFromQuery(transitDataService, ptSituationElements, query);
            // Now also add service alerts for (route+direction)s of the stop
            query = new SituationQueryBean();
            StopBean stopBean = transitDataService.getStop(stopIdString);
            List<RouteBean> routes = stopBean.getRoutes();
            for (RouteBean route : routes) {
                StopsForRouteBean stopsForRoute = transitDataService.getStopsForRoute(route.getId());
                List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
                for (StopGroupingBean stopGrouping : stopGroupings) {
                    if (!stopGrouping.getType().equalsIgnoreCase("direction"))
                        continue;
                    for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
                        handleStopGroupBean(stopIdString, query, route, stopGroup);
                    }
                }
            }
            addFromQuery(transitDataService, ptSituationElements, query);
        }
    }
    addPtSituationElementsToServiceDelivery(serviceDelivery, ptSituationElements);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) PtSituationElementStructure(uk.org.siri.siri_2.PtSituationElementStructure) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) MonitoredStopVisitStructure(uk.org.siri.siri_2.MonitoredStopVisitStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 55 with StopBean

use of org.onebusaway.transit_data.model.StopBean 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

StopBean (org.onebusaway.transit_data.model.StopBean)69 ArrayList (java.util.ArrayList)34 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 RouteBean (org.onebusaway.transit_data.model.RouteBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)17 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)15 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)15 HashMap (java.util.HashMap)12 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)9 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)9 NameBean (org.onebusaway.transit_data.model.NameBean)9 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)8 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashSet (java.util.HashSet)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 List (java.util.List)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 Test (org.junit.Test)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)5