Search in sources :

Example 1 with UserPropertiesV1

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

the class UserPropertiesMigrationImpl method getV1Properties.

private UserPropertiesV1 getV1Properties(UserPropertiesV2 v2) {
    UserPropertiesV1 v1 = new UserPropertiesV1();
    v1.setRememberPreferencesEnabled(v2.isRememberPreferencesEnabled());
    v1.setDefaultLocationLat(v2.getDefaultLocationLat());
    v1.setDefaultLocationLon(v2.getDefaultLocationLon());
    v1.setDefaultLocationName(v2.getDefaultLocationName());
    for (Bookmark bookmark : v2.getBookmarks()) v1.getBookmarkedStopIds().addAll(bookmark.getStopIds());
    return v1;
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1)

Example 2 with UserPropertiesV1

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

the class UserPropertiesServiceV1Impl method updateStopBookmark.

@Override
public void updateStopBookmark(User user, int id, String name, List<String> stopIds, RouteFilter routeFilter) {
    UserPropertiesV1 properties = getProperties(user);
    if (!properties.isRememberPreferencesEnabled())
        return;
    List<String> bookmarks = properties.getBookmarkedStopIds();
    if (0 <= id && id < bookmarks.size()) {
        bookmarks.set(id, stopIds.get(0));
        _userDao.saveOrUpdateUser(user);
    }
}
Also used : UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1)

Example 3 with UserPropertiesV1

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

the class UserPropertiesServiceVersionedInvocationHandler method getPropertiesVersion.

private int getPropertiesVersion(User user) {
    UserProperties props = user.getProperties();
    if (props instanceof UserPropertiesV1)
        return 1;
    if (props instanceof UserPropertiesV2)
        return 2;
    if (props instanceof UserPropertiesV3)
        return 3;
    if (props instanceof UserPropertiesV4)
        return 4;
    _log.warn("unknown user properties version: " + props.getClass());
    return 0;
}
Also used : UserProperties(org.onebusaway.users.model.UserProperties) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) UserPropertiesV4(org.onebusaway.users.model.properties.UserPropertiesV4)

Example 4 with UserPropertiesV1

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

the class UserDaoImplTest method testGetAllUserIds.

@Test
public void testGetAllUserIds() {
    Set<Integer> ids = new HashSet<Integer>();
    for (int i = 0; i < 100; i++) {
        User userA = new User();
        userA.setCreationTime(new Date());
        userA.setProperties(new UserPropertiesV1());
        _dao.saveOrUpdateUser(userA);
        ids.add(userA.getId());
    }
    int n = _dao.getNumberOfUsers();
    assertEquals(100, n);
    Set<Integer> retreivedIds = new HashSet<Integer>();
    final int limit = 20;
    for (int i = 0; i < n; i += limit) {
        List<Integer> pageOfIds = _dao.getAllUserIdsInRange(i, limit);
        assertTrue(pageOfIds.size() <= limit);
        retreivedIds.addAll(pageOfIds);
    }
    assertEquals(ids, retreivedIds);
}
Also used : User(org.onebusaway.users.model.User) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with UserPropertiesV1

use of org.onebusaway.users.model.UserPropertiesV1 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)

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