Search in sources :

Example 6 with UserPropertiesV1

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

the class UserPropertiesMigrationImplTest method testV1ToV2Migration.

@Test
public void testV1ToV2Migration() {
    UserPropertiesV1 v1 = new UserPropertiesV1();
    v1.setDefaultLocationLat(47.0);
    v1.setDefaultLocationLon(-122.0);
    v1.setDefaultLocationName("Seattle");
    v1.setLastSelectedStopId("1_29214");
    v1.setRememberPreferencesEnabled(true);
    v1.setBookmarkedStopIds(Arrays.asList("1_29214", "1_75403"));
    UserPropertiesV1 result = _service.migrate(v1, UserPropertiesV1.class);
    assertTrue(v1 == result);
    UserPropertiesV2 v2 = _service.migrate(v1, 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"), bookmark.getStopIds());
    assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Test(org.junit.Test)

Example 7 with UserPropertiesV1

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

the class UserPropertiesServiceV1ImplTest method createUser.

private User createUser() {
    User user = new User();
    user.setProperties(new UserPropertiesV1());
    return user;
}
Also used : User(org.onebusaway.users.model.User) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1)

Example 8 with UserPropertiesV1

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

the class UserPropertiesServiceV1Impl method resetUser.

@Override
public void resetUser(User user) {
    user.setProperties(new UserPropertiesV1());
    _userDao.saveOrUpdateUser(user);
}
Also used : UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1)

Example 9 with UserPropertiesV1

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

the class UserPropertiesServiceV1Impl method setLastSelectedStopIds.

@Override
public void setLastSelectedStopIds(User user, List<String> stopIds) {
    if (stopIds.isEmpty())
        return;
    String stopId = stopIds.get(0);
    UserPropertiesV1 properties = getProperties(user);
    if (!properties.isRememberPreferencesEnabled())
        return;
    if (!stopId.equals(properties.getLastSelectedStopId())) {
        properties.setLastSelectedStopId(stopId);
        _userDao.saveOrUpdateUser(user);
    }
}
Also used : UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1)

Example 10 with UserPropertiesV1

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

the class UserPropertiesServiceV1Impl method deleteStopBookmarks.

@Override
public void deleteStopBookmarks(User user, int index) {
    UserPropertiesV1 properties = getProperties(user);
    // either way.
    if (!properties.isRememberPreferencesEnabled())
        _log.warn("Attempt to delete bookmark for stateless user.  They shouldn't have bookmarks in the first place.  User=" + user.getId());
    List<String> bookmarkedStopIds = properties.getBookmarkedStopIds();
    bookmarkedStopIds.remove(index);
    _userDao.saveOrUpdateUser(user);
}
Also used : UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1)

Aggregations

UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)20 Test (org.junit.Test)9 User (org.onebusaway.users.model.User)7 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)4 Date (java.util.Date)3 Bookmark (org.onebusaway.users.model.properties.Bookmark)3 HashSet (java.util.HashSet)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 UserProperties (org.onebusaway.users.model.UserProperties)1 UserRole (org.onebusaway.users.model.UserRole)1 UserPropertiesV3 (org.onebusaway.users.model.properties.UserPropertiesV3)1 UserPropertiesV4 (org.onebusaway.users.model.properties.UserPropertiesV4)1