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