Search in sources :

Example 41 with User

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

the class UserServiceImpl method deleteStaleUsers.

/**
 * Unfortunately, deleting a user is a somewhat complex operation, so we can
 * do it in bulk (TODO: maybe someone can figure out a clever cascading bulk
 * delete that plays well with all the caches / etc).
 *
 * @param lastAccessTime
 */
private void deleteStaleUsers(Date lastAccessTime) {
    while (true) {
        List<Integer> userIds = _userDao.getStaleUserIdsInRange(lastAccessTime, 0, 100);
        if (userIds.isEmpty()) {
            return;
        }
        for (int userId : userIds) {
            if (Thread.interrupted()) {
                return;
            }
            User user = _userDao.getUserForId(userId);
            if (user != null) {
                _userDao.deleteUser(user);
            }
            Thread.yield();
        }
    }
}
Also used : User(org.onebusaway.users.model.User)

Example 42 with User

use of org.onebusaway.users.model.User 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 43 with User

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

the class UserDaoImplTest method testGetNumberOfUsers.

@Test
public void testGetNumberOfUsers() {
    assertEquals(0, _dao.getNumberOfUsers());
    User userA = new User();
    userA.setCreationTime(new Date());
    userA.setProperties(new UserPropertiesV1());
    _dao.saveOrUpdateUser(userA);
    assertEquals(1, _dao.getNumberOfUsers());
    User userB = new User();
    userB.setCreationTime(new Date());
    userB.setProperties(new UserPropertiesV1());
    _dao.saveOrUpdateUser(userB);
    assertEquals(2, _dao.getNumberOfUsers());
}
Also used : User(org.onebusaway.users.model.User) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Date(java.util.Date) Test(org.junit.Test)

Example 44 with User

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

the class UserDaoImplTest method test.

@Test
public void test() {
    assertEquals(0, _dao.getNumberOfUserRoles());
    UserRole adminRole = new UserRole("admin");
    UserRole userRole = new UserRole("user");
    _dao.saveOrUpdateUserRole(adminRole);
    _dao.saveOrUpdateUserRole(userRole);
    assertEquals(2, _dao.getNumberOfUserRoles());
    assertEquals(0, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(0, _dao.getNumberOfUsersWithRole(userRole));
    User userA = new User();
    userA.setCreationTime(new Date());
    userA.setProperties(new UserPropertiesV1());
    userA.getRoles().add(userRole);
    _dao.saveOrUpdateUser(userA);
    assertEquals(0, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
    User userB = new User();
    userB.setCreationTime(new Date());
    userB.setProperties(new UserPropertiesV1());
    userB.getRoles().add(adminRole);
    _dao.saveOrUpdateUser(userB);
    assertEquals(1, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
    userA.getRoles().add(adminRole);
    _dao.saveOrUpdateUser(userA);
    assertEquals(2, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
}
Also used : User(org.onebusaway.users.model.User) UserRole(org.onebusaway.users.model.UserRole) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Date(java.util.Date) Test(org.junit.Test)

Example 45 with User

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

User (org.onebusaway.users.model.User)56 UserIndex (org.onebusaway.users.model.UserIndex)23 UserIndexKey (org.onebusaway.users.model.UserIndexKey)16 Test (org.junit.Test)13 Date (java.util.Date)9 UserBean (org.onebusaway.users.client.model.UserBean)8 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)7 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 List (java.util.List)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)4 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)4 Criteria (org.hibernate.Criteria)4 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 UserDetail (org.onebusaway.admin.model.ui.UserDetail)4 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 UserRole (org.onebusaway.users.model.UserRole)3