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