Package org.onebusaway.users.model

Examples of org.onebusaway.users.model.UserPropertiesV1


    return v2;
  }

  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;
  }
View Full Code Here


  }

  @Test
  public void testNeedsMigration() {

    UserPropertiesV1 v1 = new UserPropertiesV1();
    assertFalse(_service.needsMigration(v1, UserPropertiesV1.class));
    assertTrue(_service.needsMigration(v1, UserPropertiesV2.class));

    UserPropertiesV2 v2 = new UserPropertiesV2();
    assertTrue(_service.needsMigration(v2, UserPropertiesV1.class));
View Full Code Here

  }

  @Test
  public void testV1ToV2Migration() {

    UserPropertiesV1 v1 = new UserPropertiesV1();
    v1.setDefaultLocationLat(47.0);
    v1.setDefaultLocationLon(-122.0);
    v1.setDefaultLocationName("Seattle");
    v1.setLastSelectedStopId("1_29214");
    v1.setRememberPreferencesEnabled(true);
    v1.setBookmarkedStopIds(Arrays.asList("1_29214", "1_75403"));

    UserPropertiesV1 result = _service.migrate(v1, UserPropertiesV1.class);
    assertTrue(v1 == result);

    UserPropertiesV2 v2 = _service.migrate(v1, UserPropertiesV2.class);

    assertTrue(v2.isRememberPreferencesEnabled());
View Full Code Here

    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());
  }
View Full Code Here

    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));
View Full Code Here

    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());
  }
View Full Code Here

    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());
    }
View Full Code Here

  }

  @Override
  public UserBean getUserAsBean(User user, UserBean bean) {

    UserPropertiesV1 properties = getProperties(user);

    bean.setRememberPreferencesEnabled(properties.isRememberPreferencesEnabled());

    bean.setHasDefaultLocation(properties.hasDefaultLocationLat()
        && properties.hasDefaultLocationLon());

    bean.setDefaultLocationName(properties.getDefaultLocationName());
    bean.setDefaultLocationLat(properties.getDefaultLocationLat());
    bean.setDefaultLocationLon(properties.getDefaultLocationLon());

    if (properties.getLastSelectedStopId() != null)
      bean.setLastSelectedStopIds(Arrays.asList(properties.getLastSelectedStopId()));

    int bookmarkIndex = 0;
    for (String stopId : properties.getBookmarkedStopIds()) {
      BookmarkBean bookmark = new BookmarkBean();
      bookmark.setId(bookmarkIndex++);
      bookmark.setStopIds(Arrays.asList(stopId));
      bean.addBookmark(bookmark);
    }
View Full Code Here

  }

  @Override
  public void setRememberUserPreferencesEnabled(User user,
      boolean rememberPreferencesEnabled) {
    UserPropertiesV1 properties = getProperties(user);
    properties.setRememberPreferencesEnabled(rememberPreferencesEnabled);
    if (!rememberPreferencesEnabled)
      properties.clear();
    _userDao.saveOrUpdateUser(user);
  }
View Full Code Here

  @Override
  public void setDefaultLocation(User user, String locationName, double lat,
      double lon) {

    UserPropertiesV1 properties = getProperties(user);

    if (!properties.isRememberPreferencesEnabled())
      return;

    properties.setDefaultLocationName(locationName);
    properties.setDefaultLocationLat(lat);
    properties.setDefaultLocationLon(lon);

    _userDao.saveOrUpdateUser(user);
  }
View Full Code Here

TOP

Related Classes of org.onebusaway.users.model.UserPropertiesV1

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.