Search in sources :

Example 1 with RouteFilter

use of org.onebusaway.users.model.properties.RouteFilter in project onebusaway-application-modules by camsys.

the class UserPropertiesMigrationImplTest method testV2ToV1Migration.

@Test
public void testV2ToV1Migration() {
    UserPropertiesV2 v2 = new UserPropertiesV2();
    v2.setDefaultLocationLat(47.0);
    v2.setDefaultLocationLon(-122.0);
    v2.setDefaultLocationName("Seattle");
    v2.setRememberPreferencesEnabled(true);
    Bookmark b1 = new Bookmark(0, null, Arrays.asList("1_29214"), new RouteFilter());
    Bookmark b2 = new Bookmark(1, null, Arrays.asList("1_75403", "1_75414"), new RouteFilter());
    v2.setBookmarks(Arrays.asList(b1, b2));
    UserPropertiesV2 result = _service.migrate(v2, UserPropertiesV2.class);
    assertTrue(v2 == result);
    UserPropertiesV1 v1 = _service.migrate(v2, UserPropertiesV1.class);
    assertTrue(v1.isRememberPreferencesEnabled());
    assertNull(v1.getLastSelectedStopId());
    assertEquals(47.0, v1.getDefaultLocationLat(), 0.0);
    assertEquals(-122.0, v1.getDefaultLocationLon(), 0.0);
    assertEquals("Seattle", v1.getDefaultLocationName());
    assertEquals(Arrays.asList("1_29214", "1_75403", "1_75414"), v1.getBookmarkedStopIds());
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Test(org.junit.Test)

Example 2 with RouteFilter

use of org.onebusaway.users.model.properties.RouteFilter in project onebusaway-application-modules by camsys.

the class UserPropertiesMigrationImplTest method testV2ToV3Migration.

@Test
public void testV2ToV3Migration() {
    UserPropertiesV2 v2 = new UserPropertiesV2();
    v2.setDefaultLocationLat(47.0);
    v2.setDefaultLocationLon(-122.0);
    v2.setDefaultLocationName("Seattle");
    v2.setRememberPreferencesEnabled(true);
    Bookmark b1 = new Bookmark(0, null, Arrays.asList("1_29214"), new RouteFilter());
    Bookmark b2 = new Bookmark(1, null, Arrays.asList("1_75403", "1_75414"), new RouteFilter());
    v2.setBookmarks(Arrays.asList(b1, b2));
    UserPropertiesV2 result = _service.migrate(v2, UserPropertiesV2.class);
    assertTrue(v2 == result);
    UserPropertiesV3 v3 = _service.migrate(v2, UserPropertiesV3.class);
    assertTrue(v3.isRememberPreferencesEnabled());
    assertEquals(47.0, v3.getDefaultLocationLat(), 0.0);
    assertEquals(-122.0, v3.getDefaultLocationLon(), 0.0);
    assertEquals("Seattle", v3.getDefaultLocationName());
    List<Bookmark> bookmarks = v3.getBookmarks();
    assertEquals(2, bookmarks.size());
    Bookmark bookmark = bookmarks.get(0);
    assertEquals(0, bookmark.getId());
    assertNull(bookmark.getName());
    assertEquals(Arrays.asList("1_29214"), bookmark.getStopIds());
    assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
    bookmark = bookmarks.get(1);
    assertEquals(1, bookmark.getId());
    assertNull(bookmark.getName());
    assertEquals(Arrays.asList("1_75403", "1_75414"), bookmark.getStopIds());
    assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) Test(org.junit.Test)

Example 3 with RouteFilter

use of org.onebusaway.users.model.properties.RouteFilter in project onebusaway-application-modules by camsys.

the class UserPropertiesMigrationImplTest method testV3ToV2Migration.

@Test
public void testV3ToV2Migration() {
    UserPropertiesV3 v3 = new UserPropertiesV3();
    v3.setDefaultLocationLat(47.0);
    v3.setDefaultLocationLon(-122.0);
    v3.setDefaultLocationName("Seattle");
    v3.setRememberPreferencesEnabled(true);
    Bookmark b1 = new Bookmark(0, null, Arrays.asList("1_29214"), new RouteFilter());
    Bookmark b2 = new Bookmark(1, null, Arrays.asList("1_75403", "1_75414"), new RouteFilter());
    v3.setBookmarks(Arrays.asList(b1, b2));
    UserPropertiesV3 result = _service.migrate(v3, UserPropertiesV3.class);
    assertTrue(v3 == result);
    UserPropertiesV2 v2 = _service.migrate(v3, UserPropertiesV2.class);
    assertTrue(v2.isRememberPreferencesEnabled());
    assertEquals(47.0, v2.getDefaultLocationLat(), 0.0);
    assertEquals(-122.0, v2.getDefaultLocationLon(), 0.0);
    assertEquals("Seattle", v2.getDefaultLocationName());
    List<Bookmark> bookmarks = v2.getBookmarks();
    assertEquals(2, bookmarks.size());
    Bookmark bookmark = bookmarks.get(0);
    assertEquals(0, bookmark.getId());
    assertNull(bookmark.getName());
    assertEquals(Arrays.asList("1_29214"), bookmark.getStopIds());
    assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
    bookmark = bookmarks.get(1);
    assertEquals(1, bookmark.getId());
    assertNull(bookmark.getName());
    assertEquals(Arrays.asList("1_75403", "1_75414"), bookmark.getStopIds());
    assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) Test(org.junit.Test)

Example 4 with RouteFilter

use of org.onebusaway.users.model.properties.RouteFilter 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 5 with RouteFilter

use of org.onebusaway.users.model.properties.RouteFilter in project onebusaway-application-modules by camsys.

the class CommandBookmarksAction method execute.

@Override
public String execute() throws ServiceException, BookmarkException {
    UserBean currentUser = _currentUserService.getCurrentUser();
    if (_arg != null && _arg.length() > 0) {
        if (_arg.startsWith("add")) {
            if (currentUser == null)
                return "noUser";
            List<String> lastSelectedStopIds = currentUser.getLastSelectedStopIds();
            if (!lastSelectedStopIds.isEmpty()) {
                String name = _bookmarkPresentationService.getNameForStopIds(lastSelectedStopIds);
                _currentUserService.addStopBookmark(name, lastSelectedStopIds, new RouteFilter());
            }
            return "added";
        }
        if (_arg.startsWith("delete")) {
            int index = _arg.indexOf(' ');
            if (index == -1)
                return INPUT;
            int bookmarkIndex = Integer.parseInt(_arg.substring(index + 1).trim()) - 1;
            _currentUserService.deleteStopBookmarks(bookmarkIndex);
            return "deleted";
        }
        if (_arg.matches("\\d+")) {
            int index = Integer.parseInt(_arg) - 1;
            List<BookmarkBean> bookmarks = currentUser.getBookmarks();
            if (index < 0 || index >= bookmarks.size())
                return INPUT;
            BookmarkBean bookmark = bookmarks.get(index);
            _stopIds = bookmark.getStopIds();
            _routeFilter = bookmark.getRouteFilter().getRouteIds();
            return "arrivals-and-departures";
        }
    }
    _bookmarks = _bookmarkPresentationService.getBookmarksWithStops(currentUser.getBookmarks());
    return SUCCESS;
}
Also used : UserBean(org.onebusaway.users.client.model.UserBean) BookmarkBean(org.onebusaway.users.client.model.BookmarkBean) RouteFilter(org.onebusaway.users.model.properties.RouteFilter)

Aggregations

RouteFilter (org.onebusaway.users.model.properties.RouteFilter)11 Test (org.junit.Test)7 User (org.onebusaway.users.model.User)4 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)4 Bookmark (org.onebusaway.users.model.properties.Bookmark)4 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)4 UserPropertiesV3 (org.onebusaway.users.model.properties.UserPropertiesV3)2 BookmarkWithStopsBean (org.onebusaway.presentation.model.BookmarkWithStopsBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 UserBean (org.onebusaway.users.client.model.UserBean)1