Package org.onebusaway.users.model

Examples of org.onebusaway.users.model.UserIndex


    _authoritiesService = authoritiesService;
  }

  @Override
  public User getCurrentUser(boolean createUserIfAppropriate) {
    UserIndex userIndex = getCurrentUserIndex(createUserIfAppropriate);
    if (userIndex == null)
      return null;
    return userIndex.getUser();
  }
View Full Code Here


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

    User userA = new User();
    userA.setCreationTime(new Date());
    userA.setProperties(new UserPropertiesV2());

    UserIndex index = new UserIndex();
    index.setId(new UserIndexKey("test", "A"));
    index.setUser(userA);
    userA.getUserIndices().add(index);

    _dao.saveOrUpdateUser(userA);

    User userB = new User();
    userB.setCreationTime(new Date());
    userB.setProperties(new UserPropertiesV2());

    _dao.saveOrUpdateUser(userB);

    assertEquals(1, _dao.getUserForId(userA.getId()).getUserIndices().size());
    assertEquals(0, _dao.getUserForId(userB.getId()).getUserIndices().size());

    index.setUser(userB);
    userA.getUserIndices().remove(index);
    userB.getUserIndices().add(index);

    _dao.saveOrUpdateUsers(userA, userB);
View Full Code Here

    UserDao userDao = Mockito.mock(UserDao.class);
    _service.setUserDao(userDao);

    Mockito.when(userDao.getUserForId(1234)).thenReturn(userA);

    UserIndex migratedIndex = new UserIndex();
    migratedIndex.setId(key);
    migratedIndex.setUser(userA);
    migratedIndex.setCredentials("");
    Mockito.when(userDao.getUserIndexForId(key)).thenReturn(migratedIndex);

    UserIndexRegistrationService registrationService = Mockito.mock(UserIndexRegistrationService.class);
    _service.setUserIndexRegistrationService(registrationService);

    UserRegistration registration = new UserRegistration(1234, "5555");
    Mockito.when(registrationService.getRegistrationForUserIndexKey(key)).thenReturn(
        registration);

    UserPropertiesService userPropertiesService = Mockito.mock(UserPropertiesService.class);
    _service.setUserPropertiesService(userPropertiesService);

    User userB = createUser(1235);
    UserIndex index = createUserIndex(key.getType(), key.getValue(), userB);

    UserIndex updated = _service.completePhoneNumberRegistration(index, "5554");
    assertTrue(updated == null);

    updated = _service.completePhoneNumberRegistration(index, "5555");
    assertTrue(updated != null);
View Full Code Here

  }

  private UserIndex createUserIndex(String indexType, String indexValue,
      User user) {

    UserIndex index = new UserIndex();
    index.setId(new UserIndexKey(indexType, indexValue));
    index.setUser(user);
    index.setCredentials("");

    user.getUserIndices().add(index);

    return index;
  }
View Full Code Here

  @Override
  public UserIndex getOrCreateUserForIndexKey(UserIndexKey key,
      String credentials, boolean isAnonymous) {

    UserIndex userIndex = _userDao.getUserIndexForId(key);

    if (userIndex == null) {

      User user = new User();
      user.setCreationTime(new Date());
      user.setTemporary(true);
      user.setProperties(new UserPropertiesV1());
      Set<UserRole> roles = new HashSet<UserRole>();
      if (isAnonymous)
        roles.add(_authoritiesService.getAnonymousRole());
      else
        roles.add(_authoritiesService.getUserRole());
      user.setRoles(roles);

      userIndex = new UserIndex();
      userIndex.setId(key);
      userIndex.setCredentials(credentials);
      userIndex.setUser(user);

      user.getUserIndices().add(userIndex);

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

  }

  @Override
  public UserIndex addUserIndexToUser(User user, UserIndexKey key,
      String credentials) {
    UserIndex index = new UserIndex();
    index.setId(key);
    index.setCredentials(credentials);
    index.setUser(user);
    user.getUserIndices().add(index);
    _userDao.saveOrUpdateUser(user);
    return index;
  }
View Full Code Here

  @Override
  public Long getMinApiRequestIntervalForKey(String key,
      @CacheableArgument(cacheRefreshIndicator = true) boolean forceRefresh) {

    UserIndexKey indexKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
    UserIndex userIndex = getUserIndexForId(indexKey);

    if (userIndex == null) {
      return null;
    }

    User user = userIndex.getUser();
    UserBean bean = getUserAsBean(user);
    return bean.getMinApiRequestInterval();
  }
View Full Code Here

  @Transactional
  @Override
  public IndexedUserDetails getUserForIndexKey(UserIndexKey key)
      throws UsernameNotFoundException, DataAccessException {

    UserIndex userIndex = _userService.getUserIndexForId(key);

    if (userIndex == null)
      throw new UsernameNotFoundException(key.toString());
   
    setLastAccessTimeForUser(userIndex);
View Full Code Here

  @Override
  public IndexedUserDetails getOrCreateUserForIndexKey(UserIndexKey key,
      String credentials, boolean isAnonymous) throws DataAccessException {

    UserIndex userIndex = _userService.getOrCreateUserForIndexKey(key,
        credentials, isAnonymous);
   
    setLastAccessTimeForUser(userIndex);
   
    return new IndexedUserDetailsImpl(_authoritiesService, userIndex);
View Full Code Here

TOP

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

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.