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();
}
}
}
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);
}
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());
}
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));
}
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));
}
Aggregations