Search in sources :

Example 16 with UserServiceUnexpectedException

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

the class PermissionServiceImpl method revokePermission.

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

Example 17 with UserServiceUnexpectedException

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

Example 18 with UserServiceUnexpectedException

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

the class UserServiceImpl method getUserByEmail.

@Override
public User getUserByEmail(String userEmail) throws FieldValidationException, UserNotFoundException {
    Assert.notNull(userEmail, "user email must be provided");
    validateEmail(userEmail);
    User foundUser;
    try {
        foundUser = userDao.findUserByEmail(userEmail);
    } catch (Throwable t) {
        String msg = String.format("Failed to find user by email '%s'", userEmail);
        throw new UserServiceUnexpectedException(msg, t);
    }
    if (foundUser == null) {
        throw new UserNotFoundException(userEmail);
    }
    return foundUser;
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException)

Example 19 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException 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.validation.FieldValidationException) UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DuplicateUserValidationError(org.summerb.users.api.validation.DuplicateUserValidationError) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with UserServiceUnexpectedException

use of org.summerb.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.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException)

Aggregations

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