Search in sources :

Example 86 with TechnicalManagementException

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

the class UserServiceImpl method findByIds.

@Override
public Set<UserEntity> findByIds(List<String> ids) {
    try {
        LOGGER.debug("Find users by ID: {}", ids);
        Set<User> users = userRepository.findByIds(ids);
        if (!users.isEmpty()) {
            return users.stream().map(u -> this.convert(u, false)).collect(Collectors.toSet());
        }
        Optional<String> idsAsString = ids.stream().reduce((a, b) -> a + '/' + b);
        if (idsAsString.isPresent()) {
            throw new UserNotFoundException(idsAsString.get());
        } else {
            throw new UserNotFoundException("?");
        }
    } catch (TechnicalException ex) {
        Optional<String> idsAsString = ids.stream().reduce((a, b) -> a + '/' + b);
        LOGGER.error("An error occurs while trying to find users using their ID {}", idsAsString, ex);
        throw new TechnicalManagementException("An error occurs while trying to find users using their ID " + idsAsString, ex);
    }
}
Also used : RoleScope(io.gravitee.repository.management.model.RoleScope) java.util(java.util) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) NotificationParamsBuilder(io.gravitee.management.service.notification.NotificationParamsBuilder) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) MembershipDefaultReferenceId(io.gravitee.repository.management.model.MembershipDefaultReferenceId) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EmailNotificationBuilder(io.gravitee.management.service.builder.EmailNotificationBuilder) StringUtils(org.apache.commons.lang3.StringUtils) Value(org.springframework.beans.factory.annotation.Value) DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER(io.gravitee.management.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER) JWTVerifier(com.auth0.jwt.JWTVerifier) UUID(io.gravitee.common.utils.UUID) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) io.gravitee.management.model(io.gravitee.management.model) UserRepository(io.gravitee.repository.management.api.UserRepository) JWTSigner(com.auth0.jwt.JWTSigner) DEFAULT_JWT_ISSUER(io.gravitee.management.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER) UserNotFoundException(io.gravitee.management.service.exceptions.UserNotFoundException) Claims(io.gravitee.management.service.common.JWTHelper.Claims) MembershipReferenceType(io.gravitee.repository.management.model.MembershipReferenceType) UsernameAlreadyExistsException(io.gravitee.management.service.exceptions.UsernameAlreadyExistsException) Logger(org.slf4j.Logger) DefaultRoleNotFoundException(io.gravitee.management.service.exceptions.DefaultRoleNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PortalHook(io.gravitee.management.service.notification.PortalHook) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) Component(org.springframework.stereotype.Component) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) USER(io.gravitee.repository.management.model.Audit.AuditProperties.USER) io.gravitee.management.service(io.gravitee.management.service) User(io.gravitee.repository.management.model.User) io.gravitee.common.utils(io.gravitee.common.utils) DatatypeConverter(javax.xml.bind.DatatypeConverter) 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 87 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException 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 88 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException 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)

Example 89 with TechnicalManagementException

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

the class UserServiceImpl method create.

/**
 * Allows to pre-create a user.
 * @param newExternalUserEntity
 * @return
 */
@Override
public UserEntity create(NewExternalUserEntity newExternalUserEntity, boolean addDefaultRole) {
    try {
        LOGGER.debug("Create an external user {}", newExternalUserEntity);
        Optional<User> checkUser = userRepository.findById(newExternalUserEntity.getUsername());
        if (checkUser.isPresent()) {
            throw new UsernameAlreadyExistsException(newExternalUserEntity.getUsername());
        }
        User user = convert(newExternalUserEntity);
        user.setId(UUID.toString(UUID.random()));
        // Set date fields
        user.setCreatedAt(new Date());
        user.setUpdatedAt(user.getCreatedAt());
        User createdUser = userRepository.create(user);
        auditService.createPortalAuditLog(Collections.singletonMap(USER, user.getUsername()), User.AuditEvent.USER_CREATED, user.getCreatedAt(), null, user);
        if (addDefaultRole) {
            addDefaultMembership(createdUser);
        }
        return convert(createdUser, true);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to create an external user {}", newExternalUserEntity, ex);
        throw new TechnicalManagementException("An error occurs while trying to create an external user" + newExternalUserEntity, ex);
    }
}
Also used : UsernameAlreadyExistsException(io.gravitee.management.service.exceptions.UsernameAlreadyExistsException) User(io.gravitee.repository.management.model.User) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 90 with TechnicalManagementException

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

the class ViewServiceImpl method update.

@Override
public List<ViewEntity> update(final List<UpdateViewEntity> viewEntities) {
    final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
    viewEntities.forEach(viewEntity -> {
        try {
            View view = convert(viewEntity);
            Optional<View> viewOptional = viewRepository.findById(view.getId());
            if (viewOptional.isPresent()) {
                savedViews.add(convert(viewRepository.update(view)));
                auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_UPDATED, new Date(), viewOptional.get(), view);
            }
        } catch (TechnicalException ex) {
            LOGGER.error("An error occurs while trying to update view {}", viewEntity.getName(), ex);
            throw new TechnicalManagementException("An error occurs while trying to update view " + viewEntity.getName(), ex);
        }
    });
    return savedViews;
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ViewEntity(io.gravitee.management.model.ViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) NewViewEntity(io.gravitee.management.model.NewViewEntity) View(io.gravitee.repository.management.model.View) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)90 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)83 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 Component (org.springframework.stereotype.Component)17 Collectors (java.util.stream.Collectors)13 java.util (java.util)11 Date (java.util.Date)11 AuditService (io.gravitee.management.service.AuditService)10 IdGenerator (io.gravitee.common.utils.IdGenerator)9 io.gravitee.management.model (io.gravitee.management.model)9 User (io.gravitee.repository.management.model.User)9 ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)8 UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)8 Metadata (io.gravitee.repository.management.model.Metadata)8 Rating (io.gravitee.repository.management.model.Rating)8 DuplicateMetadataNameException (io.gravitee.management.service.exceptions.DuplicateMetadataNameException)7 ApiService (io.gravitee.management.service.ApiService)6 MetadataService (io.gravitee.management.service.MetadataService)6