@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); } }
@PreAuthorize("isAuthenticated()") @Transactional @Override public UserDto get(Long id) { User userEntity = userDao.get(id); return Converter.getTransferObject(userEntity); }
@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; }
@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); }
@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); }
private void throwExceptionIfBirthNumberExists(String birthNumber) throws UserAlreadyExists { Long id = userDao.getIdByBirthNumber(birthNumber); if (id > 0) { throw new UserAlreadyExists("User already exists!"); } }