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));
}
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));
}
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;
}
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);
}
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;
}
Aggregations