Search in sources :

Example 11 with UserPropertiesV3

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());
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) Test(org.junit.Test)

Example 12 with UserPropertiesV3

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with UserPropertiesV3

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;
        }
    }
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3)

Example 14 with UserPropertiesV3

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);
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3)

Example 15 with UserPropertiesV3

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());
}
Also used : UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3)

Aggregations

UserPropertiesV3 (org.onebusaway.users.model.properties.UserPropertiesV3)17 Bookmark (org.onebusaway.users.model.properties.Bookmark)6 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)3 Test (org.junit.Test)2 UserProperties (org.onebusaway.users.model.UserProperties)2 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 UserIndex (org.onebusaway.users.model.UserIndex)1 UserIndexKey (org.onebusaway.users.model.UserIndexKey)1 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)1 UserPropertiesV4 (org.onebusaway.users.model.properties.UserPropertiesV4)1