Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. @Override
  2.     public ModelBO update(UserDTO userDto, long userId) throws NonExistingEntityException {
  3.         final ModelDTO dto = castToSpecificDto(userDto);
  4.         final ModelTable existing = castToSpecificTable(userRepository.findByUserId(userId));
  5.  
  6.         if (existing == null) {
  7.             throw new NonExistingEntityException(String.format("User with a given id='%d' doesn't exist.", userId));
  8.         }
  9.  
  10.         final ModelTable updated = new ModelTable(existing.getUserTablePK().getUserId(),
  11.                 dto.getEthnicity() != null ? dto.getEthnicity() : existing.getEthnicity(), dto.getHeight() != null ? dto.getHeight() : existing.getHeight(),
  12.                 dto.getBust() != null ? dto.getBust() : existing.getBust(), dto.getWaist() != null ? dto.getWaist() : existing.getWaist(),
  13.                 dto.getHips() != null ? dto.getHips() : existing.getHips(), dto.getShoes() != null ? dto.getShoes() : existing.getShoes(),
  14.                 dto.getEyes() != null ? dto.getEyes() : existing.getEyes(), dto.getHair() != null ? dto.getHair() : existing.getHair(), existing.getEmail(), // can't
  15.                                                                                                                                                              // change
  16.                                                                                                                                                              // email
  17.                                                                                                                                                              // here
  18.                 existing.getPassword(), // can't change password here
  19.                 dto.getFirstName() != null ? dto.getFirstName() : existing.getFirstName(),
  20.                 dto.getLastName() != null ? dto.getLastName() : existing.getLastName(),
  21.                 dto.getDateOfBirth() != null ? dto.getDateOfBirth() : existing.getDateOfBirth(),
  22.                 dto.getGender() != null ? dto.getGender() : existing.getGender(), existing.getProfileType(), // can't
  23.                                                                                                              // change
  24.                                                                                                              // profile
  25.                                                                                                              // type
  26.                 dto.getAboutMe() != null ? dto.getAboutMe() : existing.getAboutMe(), existing.getDateJoined(), // can't
  27.                                                                                                                // change
  28.                                                                                                                // date
  29.                                                                                                                // joined
  30.                 dto.getContactNumber() != null ? dto.getContactNumber() : existing.getContactNumber(),
  31.                 dto.getBase() != null ? dto.getBase() : existing.getBase());
  32.  
  33.         userRepository.save(updated);
  34.         return new ModelBO(updated);
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement