Search in sources :

Example 21 with UserServiceUnexpectedException

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

the class PermissionServiceImpl method revokeUserPermissions.

@Override
@Transactional(rollbackFor = Throwable.class)
public void revokeUserPermissions(String optionalDomainName, String userUuid) {
    Preconditions.checkArgument(StringUtils.hasText(userUuid));
    String domainName = getOptionalParamValue(optionalDomainName);
    try {
        permissionDao.revokeUserPermissions(domainName, userUuid);
    } catch (Throwable t) {
        String msg = String.format("Failed to revoke user '%s' permissions in domain '%s'", userUuid, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with UserServiceUnexpectedException

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

the class PermissionServiceImpl method revokeAllPermissionsForSubject.

@Override
@Transactional(rollbackFor = Throwable.class)
public void revokeAllPermissionsForSubject(String optionalDomainName, String optionalSubjectId) {
    String domainName = getOptionalParamValue(optionalDomainName);
    String subjectId = getOptionalParamValue(optionalSubjectId);
    try {
        permissionDao.clearSubjectPermissions(domainName, subjectId);
    } catch (Throwable t) {
        String msg = String.format("Failed to clear subject '%s' permissions in domain '%s'", subjectId, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with UserServiceUnexpectedException

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

the class PermissionServiceImpl method findUsersAndTheirPermissionsForSubject.

@Override
public Map<String, List<String>> findUsersAndTheirPermissionsForSubject(String optionalDomainName, String optionalSubjectId) {
    String domainName = getOptionalParamValue(optionalDomainName);
    String subjectId = getOptionalParamValue(optionalSubjectId);
    try {
        return permissionDao.getUsersAndTheirPermissionsForSubject(domainName, subjectId);
    } catch (Throwable t) {
        String msg = String.format("Failed to get users and their permissions for subject '%s' in domain '%s'", subjectId, domainName);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)

Example 24 with UserServiceUnexpectedException

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

the class UserServiceImpl method deleteUserByUuid.

@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteUserByUuid(String userUuid) throws UserNotFoundException {
    Preconditions.checkArgument(userUuid != null, "User uuid required");
    Preconditions.checkArgument(StringUtils.hasText(userUuid), "User uuid must be provided");
    boolean isDeletedSucceessfully = false;
    try {
        User userToDelete = userDao.findUserByUuid(userUuid);
        if (userToDelete != null) {
            isDeletedSucceessfully = userDao.deleteUser(userUuid);
            // NOTE: Assumed, that all related stuff will be deleted
            // automatically using CASCADE DELETE in the database
            eventBus.post(EntityChangedEvent.removedObject(userToDelete));
        }
    } catch (Throwable t) {
        String msg = String.format("Failed to delete user '%s'", userUuid);
        throw new UserServiceUnexpectedException(msg, t);
    }
    if (!isDeletedSucceessfully) {
        throw new UserNotFoundException(userUuid);
    }
}
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with UserServiceUnexpectedException

use of org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException 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)

Aggregations

UserServiceUnexpectedException (org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)27 Transactional (org.springframework.transaction.annotation.Transactional)18 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)11 User (org.summerb.microservices.users.api.dto.User)11 UserNotFoundException (org.summerb.microservices.users.api.exceptions.UserNotFoundException)9 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 AuthToken (org.summerb.microservices.users.api.dto.AuthToken)3 AuthTokenNotFoundException (org.summerb.microservices.users.api.exceptions.AuthTokenNotFoundException)3 InvalidPasswordException (org.summerb.microservices.users.api.exceptions.InvalidPasswordException)2 DuplicateUserValidationError (org.summerb.microservices.users.api.validation.DuplicateUserValidationError)2 Password (org.summerb.microservices.users.impl.dom.Password)2 Date (java.util.Date)1 UserStatus (org.summerb.approaches.springmvc.security.dto.UserStatus)1 RegistrationAlreadyRequestedValidationError (org.summerb.approaches.springmvc.security.ve.RegistrationAlreadyRequestedValidationError)1 ValidationError (org.summerb.approaches.validation.ValidationError)1 FieldRequiredValidationError (org.summerb.approaches.validation.errors.FieldRequiredValidationError)1