Search in sources :

Example 11 with UserNotFoundException

use of org.summerb.microservices.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.

the class UserServiceImpl method getUserByUuid.

@Override
public User getUserByUuid(String userUuid) throws UserNotFoundException {
    Assert.hasText(userUuid, "userUuid must be provided");
    User foundUser;
    try {
        foundUser = userDao.findUserByUuid(userUuid);
    } catch (Throwable t) {
        String msg = String.format("Failed to find user '%s'", userUuid);
        throw new UserServiceUnexpectedException(msg, t);
    }
    if (foundUser == null) {
        throw new UserNotFoundException(userUuid);
    }
    return foundUser;
}
Also used : UserNotFoundException(org.summerb.microservices.users.api.exceptions.UserNotFoundException) User(org.summerb.microservices.users.api.dto.User) UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)

Example 12 with UserNotFoundException

use of org.summerb.microservices.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.

the class UserServiceImpl method updateUser.

@Override
@Transactional(rollbackFor = Throwable.class)
public void updateUser(User user) throws FieldValidationException, UserNotFoundException {
    Preconditions.checkArgument(user != null, "User reference required");
    Preconditions.checkArgument(StringUtils.hasText(user.getUuid()), "User uuid must be provided");
    validateUser(user);
    boolean isUpdatedSuccessfully;
    try {
        isUpdatedSuccessfully = userDao.updateUser(user);
        eventBus.post(EntityChangedEvent.updated(user));
    } catch (DuplicateKeyException dke) {
        throw new FieldValidationException(new DuplicateUserValidationError(User.FN_EMAIL));
    } catch (Throwable t) {
        String msg = String.format("Failed to update user '%s'", user.getUuid());
        throw new UserServiceUnexpectedException(msg, t);
    }
    if (!isUpdatedSuccessfully) {
        throw new UserNotFoundException(user.getUuid());
    }
}
Also used : FieldValidationException(org.summerb.approaches.validation.FieldValidationException) UserNotFoundException(org.summerb.microservices.users.api.exceptions.UserNotFoundException) UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DuplicateUserValidationError(org.summerb.microservices.users.api.validation.DuplicateUserValidationError) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with UserNotFoundException

use of org.summerb.microservices.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.

the class UserCachedTest method testDeleteUser_expectUserNotFoundException.

// (expected=UserNotFoundException.class)
@Test
public void testDeleteUser_expectUserNotFoundException() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    userService.getUserByUuid(userToCreate.getUuid());
    userService.deleteUserByUuid(userToCreate.getUuid());
    try {
        userService.getUserByUuid(userToCreate.getUuid());
        fail();
    } catch (UserNotFoundException e) {
    }
}
Also used : UserNotFoundException(org.summerb.microservices.users.api.exceptions.UserNotFoundException) User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Example 14 with UserNotFoundException

use of org.summerb.microservices.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.

the class UserDaoImplTest method testDeleteUser_expectUserWillNotBeFoundAfterDeletition.

@Test
public void testDeleteUser_expectUserWillNotBeFoundAfterDeletition() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    userService.deleteUserByUuid(userToCreate.getUuid());
    try {
        userService.getUserByEmail(userToCreate.getEmail());
        fail();
    } catch (UserNotFoundException e) {
    // it's expected
    }
}
Also used : UserNotFoundException(org.summerb.microservices.users.api.exceptions.UserNotFoundException) User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Aggregations

UserNotFoundException (org.summerb.microservices.users.api.exceptions.UserNotFoundException)14 User (org.summerb.microservices.users.api.dto.User)13 UserServiceUnexpectedException (org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)9 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)7 Transactional (org.springframework.transaction.annotation.Transactional)6 AuthToken (org.summerb.microservices.users.api.dto.AuthToken)3 InvalidPasswordException (org.summerb.microservices.users.api.exceptions.InvalidPasswordException)3 Test (org.junit.Test)2 UserDetailsImpl (org.summerb.approaches.springmvc.security.dto.UserDetailsImpl)2 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 UserStatus (org.summerb.approaches.springmvc.security.dto.UserStatus)1 PasswordInvalidValidationError (org.summerb.approaches.springmvc.security.ve.PasswordInvalidValidationError)1 RegistrationAlreadyRequestedValidationError (org.summerb.approaches.springmvc.security.ve.RegistrationAlreadyRequestedValidationError)1 UserNotFoundValidationError (org.summerb.approaches.springmvc.security.ve.UserNotFoundValidationError)1 ValidationContext (org.summerb.approaches.validation.ValidationContext)1 AuthTokenNotFoundException (org.summerb.microservices.users.api.exceptions.AuthTokenNotFoundException)1