Search in sources :

Example 16 with UserPropertiesV2

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

the class UserPropertiesServiceV2Impl method updateStopBookmark.

@Override
public void updateStopBookmark(User user, int id, String name, List<String> stopIds, RouteFilter routeFilter) {
    UserPropertiesV2 properties = getProperties(user);
    if (!properties.isRememberPreferencesEnabled())
        return;
    List<Bookmark> bookmarks = properties.getBookmarks();
    for (int index = 0; index < bookmarks.size(); index++) {
        Bookmark bookmark = bookmarks.get(index);
        if (bookmark.getId() == id) {
            bookmark = new Bookmark(id, name, stopIds, routeFilter);
            bookmarks.set(index, bookmark);
            _userDao.saveOrUpdateUser(user);
            return;
        }
    }
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2)

Example 17 with UserPropertiesV2

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

the class UserPropertiesServiceV2Impl method deleteStopBookmarks.

@Override
public void deleteStopBookmarks(User user, int id) {
    UserPropertiesV2 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());
    boolean modified = false;
    for (Iterator<Bookmark> it = properties.getBookmarks().iterator(); it.hasNext(); ) {
        Bookmark bookmark = it.next();
        if (bookmark.getId() == id) {
            it.remove();
            modified = true;
        }
    }
    if (modified)
        _userDao.saveOrUpdateUser(user);
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2)

Example 18 with UserPropertiesV2

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

the class UserPropertiesServiceV2Impl method authorizeApi.

@Override
public void authorizeApi(User user, long minApiRequestInterval) {
    UserPropertiesV2 properties = getProperties(user);
    properties.setMinApiRequestInterval(minApiRequestInterval);
    _userDao.saveOrUpdateUser(user);
}
Also used : UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2)

Example 19 with UserPropertiesV2

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

the class UserDaoImplTest method deleteUser.

@Test
public void deleteUser() {
    UserRole userRole = new UserRole("user");
    _dao.saveOrUpdateUserRole(userRole);
    User user = new User();
    user.setCreationTime(new Date());
    user.setProperties(new UserPropertiesV2());
    user.getRoles().add(userRole);
    UserIndexKey key = new UserIndexKey("phone", "2065551234");
    UserIndex index = new UserIndex();
    index.setId(key);
    index.setUser(user);
    user.getUserIndices().add(index);
    _dao.saveOrUpdateUser(user);
    assertEquals(1, _dao.getNumberOfUsers());
    UserIndex index2 = _dao.getUserIndexForId(key);
    assertEquals(key, index2.getId());
    assertEquals(user, index2.getUser());
    _dao.deleteUser(user);
    assertEquals(0, _dao.getNumberOfUsers());
    index2 = _dao.getUserIndexForId(key);
    assertNull(index2);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserRole(org.onebusaway.users.model.UserRole) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) Date(java.util.Date) Test(org.junit.Test)

Example 20 with UserPropertiesV2

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

the class UserDaoImplTest method testGetNumberOfStaleUsers.

@Test
public void testGetNumberOfStaleUsers() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MONTH, -1);
    Date oneMonth = c.getTime();
    c.add(Calendar.MONTH, -1);
    Date twoMonth = c.getTime();
    c.add(Calendar.MONTH, -1);
    Date threeMonth = c.getTime();
    assertEquals(0, _dao.getNumberOfStaleUsers(oneMonth));
    User userA = new User();
    userA.setCreationTime(new Date());
    userA.setLastAccessTime(twoMonth);
    userA.setProperties(new UserPropertiesV2());
    _dao.saveOrUpdateUser(userA);
    assertEquals(1, _dao.getNumberOfStaleUsers(oneMonth));
    assertEquals(0, _dao.getNumberOfStaleUsers(twoMonth));
    assertEquals(0, _dao.getNumberOfStaleUsers(threeMonth));
    User userB = new User();
    userB.setCreationTime(new Date());
    userB.setLastAccessTime(threeMonth);
    userB.setProperties(new UserPropertiesV2());
    _dao.saveOrUpdateUser(userB);
    assertEquals(2, _dao.getNumberOfStaleUsers(oneMonth));
    assertEquals(1, _dao.getNumberOfStaleUsers(twoMonth));
    assertEquals(0, _dao.getNumberOfStaleUsers(threeMonth));
}
Also used : User(org.onebusaway.users.model.User) Calendar(java.util.Calendar) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) Date(java.util.Date) Test(org.junit.Test)

Aggregations

UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)21 Bookmark (org.onebusaway.users.model.properties.Bookmark)9 Test (org.junit.Test)8 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)4 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 Date (java.util.Date)3 User (org.onebusaway.users.model.User)3 UserPropertiesV3 (org.onebusaway.users.model.properties.UserPropertiesV3)3 UserIndex (org.onebusaway.users.model.UserIndex)2 UserIndexKey (org.onebusaway.users.model.UserIndexKey)2 UserProperties (org.onebusaway.users.model.UserProperties)2 Calendar (java.util.Calendar)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 UserRole (org.onebusaway.users.model.UserRole)1 UserPropertiesV4 (org.onebusaway.users.model.properties.UserPropertiesV4)1