Search in sources :

Example 16 with UserNotFoundException

use of io.gravitee.management.service.exceptions.UserNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class UserServiceImpl method findById.

@Override
public UserEntity findById(String id) {
    try {
        LOGGER.debug("Find user by ID: {}", id);
        Optional<User> optionalUser = userRepository.findById(id);
        if (optionalUser.isPresent()) {
            return convert(optionalUser.get(), false);
        }
        // should never happen
        throw new UserNotFoundException(id);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find user using its ID {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to find user using its ID " + id, ex);
    }
}
Also used : UserNotFoundException(io.gravitee.management.service.exceptions.UserNotFoundException) User(io.gravitee.repository.management.model.User) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 17 with UserNotFoundException

use of io.gravitee.management.service.exceptions.UserNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class UserServiceImpl method findByIdWithRoles.

@Override
public UserEntity findByIdWithRoles(String id) {
    try {
        LOGGER.debug("Find user by ID: {}", id);
        Optional<User> optionalUser = userRepository.findById(id);
        if (optionalUser.isPresent()) {
            return convert(optionalUser.get(), true);
        }
        // should never happen
        throw new UserNotFoundException(id);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find user using its ID {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to find user using its ID " + id, ex);
    }
}
Also used : UserNotFoundException(io.gravitee.management.service.exceptions.UserNotFoundException) User(io.gravitee.repository.management.model.User) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)17 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)6 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)6 User (io.gravitee.repository.management.model.User)6 UserDetails (io.gravitee.management.idp.api.authentication.UserDetails)5 AbstractResourceTest (io.gravitee.management.rest.resource.AbstractResourceTest)5 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 UserEntity (io.gravitee.management.model.UserEntity)4 NewExternalUserEntity (io.gravitee.management.model.NewExternalUserEntity)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 UpdateUserEntity (io.gravitee.management.model.UpdateUserEntity)2 JWTSigner (com.auth0.jwt.JWTSigner)1 JWTVerifier (com.auth0.jwt.JWTVerifier)1 io.gravitee.common.utils (io.gravitee.common.utils)1 UUID (io.gravitee.common.utils.UUID)1 UserDetailRole (io.gravitee.management.idp.api.authentication.UserDetailRole)1 io.gravitee.management.model (io.gravitee.management.model)1 EventEntity (io.gravitee.management.model.EventEntity)1 NewEventEntity (io.gravitee.management.model.NewEventEntity)1