예제 #1
0
 @PreAuthorize("isAuthenticated()")
 @Transactional
 @Override
 public void edit(UserDto userDto) {
   if (userDto == null) {
     throw new IllegalArgumentException("User is null");
   }
   User userEntity = Converter.getEntity(userDto);
   UserDto persistedUser = get(userDto.getId());
   if (userDto.getBirthNumber().equals(persistedUser.getBirthNumber())) {
     userDao.edit(userEntity);
   } else {
     throwExceptionIfBirthNumberExists(userEntity.getBirthNumber());
     userDao.edit(userEntity);
   }
 }
예제 #2
0
 @PreAuthorize("isAuthenticated()")
 @Transactional
 @Override
 public UserDto get(Long id) {
   User userEntity = userDao.get(id);
   return Converter.getTransferObject(userEntity);
 }
예제 #3
0
 @PreAuthorize("isAuthenticated()")
 @Transactional
 @Override
 public List<UserDto> getAllWithRent() {
   List<UserDto> userDtoList = new ArrayList<UserDto>();
   for (User user : userDao.getAllWithRent()) {
     userDtoList.add(Converter.getTransferObject(user));
   }
   return userDtoList;
 }
예제 #4
0
 @PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_BUILT_IN_ADMIN')")
 @Transactional
 @Override
 public Long add(UserDto userDto) {
   if (userDto == null) {
     throw new IllegalArgumentException("User is null");
   }
   User userEntity = Converter.getEntity(userDto);
   throwExceptionIfBirthNumberExists(userEntity.getBirthNumber());
   return userDao.add(userEntity);
 }
예제 #5
0
  @PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_BUILT_IN_ADMIN')")
  @Transactional
  @Override
  public void delete(UserDto userDto) {
    User userEntity = Converter.getEntity(userDto);

    OfficeDto office = officeService.getOffice(userDto.getOfficeDto().getId());
    if (office.getManager() != null && office.getManager().getId() == userDto.getId()) {
      office.setManager(null);
      officeService.editOffice(office);
    }

    userDao.delete(userEntity);
  }
예제 #6
0
 private void throwExceptionIfBirthNumberExists(String birthNumber) throws UserAlreadyExists {
   Long id = userDao.getIdByBirthNumber(birthNumber);
   if (id > 0) {
     throw new UserAlreadyExists("User already exists!");
   }
 }