Пример #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);
 }
Пример #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;
 }
Пример #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);
    }
  }
Пример #4
0
 @Override
 public User removeUser(long userId) {
   User u = userRepository.findOne(userId);
   this.userRepository.delete(userId);
   return u;
 }
Пример #5
0
 @Override
 public User findById(long userId) {
   User user = userRepository.findOne(userId);
   if (null == user) throw new UserNotFoundException(userId);
   return user;
 }
Пример #6
0
 @Override
 public User findUserByUsername(String username) {
   return userRepository.findByUsername(username);
 }