Exemplo n.º 1
0
 @Override
 public User updateUser(
     long userId, String username, String password, String firstName, String lastName) {
   User user = userRepository.findOne(userId);
   user.setUsername(username);
   user.setFirstName(firstName);
   user.setLastName(lastName);
   user.setPassword(password);
   return this.userRepository.save(user);
 }
Exemplo n.º 2
0
 @Override
 public Customer removeCustomer(long userId, long customerId) {
   User user = userRepository.findOne(userId);
   Customer customer = customerRepository.findOne(customerId);
   user.getCustomers().remove(customer);
   this.userRepository.save(user);
   customer.setUser(null);
   this.customerRepository.delete(customer);
   return customer;
 }
Exemplo n.º 3
0
  @Override
  public void writeUserProfilePhoto(long userId, MediaType ext, byte[] bytesForProfilePhoto) {

    User user = findById(userId);
    user.setProfilePhotoMediaType(ext.toString());
    user.setProfilePhotoImported(true);
    userRepository.save(user);

    ByteArrayInputStream byteArrayInputStream = null;
    FileOutputStream fileOutputStream = null;
    try {
      fileOutputStream = new FileOutputStream(fileForPhoto(userId));
      byteArrayInputStream = new ByteArrayInputStream(bytesForProfilePhoto);
      IOUtils.copy(byteArrayInputStream, fileOutputStream);
    } catch (IOException e) {
      throw new UserProfilePhotoWriteException(userId, e);
    } finally {
      IOUtils.closeQuietly(fileOutputStream);
      IOUtils.closeQuietly(byteArrayInputStream);
    }
  }
Exemplo n.º 4
0
 @Override
 public User removeUser(long userId) {
   User u = userRepository.findOne(userId);
   this.userRepository.delete(userId);
   return u;
 }
Exemplo n.º 5
0
 @Override
 public User findById(long userId) {
   User user = userRepository.findOne(userId);
   if (null == user) throw new UserNotFoundException(userId);
   return user;
 }
Exemplo n.º 6
0
 @Override
 public User findUserByUsername(String username) {
   return userRepository.findByUsername(username);
 }