private boolean exists(User user) { if (user == null || user.getId() == null) { return false; } if (!userRepository.exists(user.getId())) { return false; } return true; }
private User saveUser(User user) { if (!exists(user)) { user.setCreated(new Date()); } if (isUserNameAlreadyTaken(user.getName())) { throw new UserNameIsTakenException("Name " + user.getName() + " has already been taken."); } User u = userRepository.save(user); return u; }
@Override public List<User> findAllSpenders() { return userRepository.findAllUsersHavingAuthority(SPENDER_AUTHORITY_NAME); }
@Override public Page<User> findAll(Pageable pageable) { return userRepository.findAll(pageable); }
@Override public List<User> findAll() { return listFromIterable(userRepository.findAll()); }
@Override public User findByName(String name) { return userRepository.findByName(name); }
private boolean isUserNameAlreadyTaken(String name) { return userRepository.findByName(name) != null; }