use of org.onebusaway.users.model.properties.UserPropertiesV3 in project onebusaway-application-modules by camsys.
the class UserPropertiesMigrationImplTest method testV3ToV2Migration.
@Test
public void testV3ToV2Migration() {
UserPropertiesV3 v3 = new UserPropertiesV3();
v3.setDefaultLocationLat(47.0);
v3.setDefaultLocationLon(-122.0);
v3.setDefaultLocationName("Seattle");
v3.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());
v3.setBookmarks(Arrays.asList(b1, b2));
UserPropertiesV3 result = _service.migrate(v3, UserPropertiesV3.class);
assertTrue(v3 == result);
UserPropertiesV2 v2 = _service.migrate(v3, UserPropertiesV2.class);
assertTrue(v2.isRememberPreferencesEnabled());
assertEquals(47.0, v2.getDefaultLocationLat(), 0.0);
assertEquals(-122.0, v2.getDefaultLocationLon(), 0.0);
assertEquals("Seattle", v2.getDefaultLocationName());
List<Bookmark> bookmarks = v2.getBookmarks();
assertEquals(2, bookmarks.size());
Bookmark bookmark = bookmarks.get(0);
assertEquals(0, bookmark.getId());
assertNull(bookmark.getName());
assertEquals(Arrays.asList("1_29214"), bookmark.getStopIds());
assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
bookmark = bookmarks.get(1);
assertEquals(1, bookmark.getId());
assertNull(bookmark.getName());
assertEquals(Arrays.asList("1_75403", "1_75414"), bookmark.getStopIds());
assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
}
use of org.onebusaway.users.model.properties.UserPropertiesV3 in project onebusaway-application-modules by camsys.
the class KeysResource method listEmails.
@Path("/list-emails")
@GET
@Produces("application/json")
public Response listEmails() throws JsonGenerationException, JsonMappingException, IOException {
log.info("Starting listEmails");
try {
validateSecurity();
List<String> apiKeys = _userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
List<String> emails = new ArrayList<String>();
int count = 0;
for (String apiKey : apiKeys) {
UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = _userService.getUserIndexForId(key);
count++;
if (userIndex != null) {
if (userIndex.getUser() != null) {
if (userIndex.getUser().getProperties() != null) {
Object o = userIndex.getUser().getProperties();
if (o instanceof UserPropertiesV3) {
UserPropertiesV3 v3 = (UserPropertiesV3) o;
if (!StringUtils.isBlank(v3.getContactEmail())) {
emails.add(v3.getContactEmail());
}
}
}
}
}
if (count % 100 == 0)
log.info("processed " + count + " users....");
}
log.info("processing complete of " + count + " users!");
Response response = constructResponse(emails);
log.info("Returning response from listEmails");
return response;
} catch (Exception e) {
log.error(e.getMessage());
throw new WebApplicationException(e, Response.serverError().build());
}
}
use of org.onebusaway.users.model.properties.UserPropertiesV3 in project onebusaway-application-modules by camsys.
the class UserPropertiesServiceV3Impl method updateStopBookmark.
@Override
public void updateStopBookmark(User user, int id, String name, List<String> stopIds, RouteFilter routeFilter) {
UserPropertiesV3 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.UserPropertiesV3 in project onebusaway-application-modules by camsys.
the class UserPropertiesServiceV3Impl method deleteStopBookmarks.
@Override
public void deleteStopBookmarks(User user, int id) {
UserPropertiesV3 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.UserPropertiesV3 in project onebusaway-application-modules by camsys.
the class UserPropertiesServiceV3Impl method resetUser.
@Override
public void resetUser(User user) {
user.setProperties(new UserPropertiesV3());
_userDao.saveOrUpdateUser(user);
_lastSelectedStopService.clearLastSelectedStopForUser(user.getId());
}
Aggregations