Search in sources :

Example 26 with FieldValidationException

use of org.summerb.validation.FieldValidationException in project summerb by skarpushin.

the class UsersServiceFacadeImpl method resetPassword.

@Transactional(rollbackFor = Throwable.class)
@Override
public void resetPassword(String email, String passwordResetToken, PasswordReset resetPasswordRequest) throws UserNotFoundException, FieldValidationException {
    try {
        String userUuid = assertPasswordResetOperationValid(email, passwordResetToken, resetPasswordRequest);
        passwordService.setUserPassword(userUuid, resetPasswordRequest.getPassword());
        // generate new token in order to invalidate current
        passwordService.getNewRestorationTokenForUser(userUuid);
        // If account requires activation, do it
        if (isAccountRequiresActivation(userUuid)) {
            activateAccount(userUuid);
        }
    } catch (Throwable e) {
        Throwables.throwIfInstanceOf(e, FieldValidationException.class);
        throw new UserServiceUnexpectedException("Failed to arrange password reset", e);
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with FieldValidationException

use of org.summerb.validation.FieldValidationException in project summerb by skarpushin.

the class DaoExceptionToFveTranslatorMySqlImpl method throwIfDuplicate.

private void throwIfDuplicate(Throwable t) throws FieldValidationException {
    DuplicateKeyException dke = ExceptionUtils.findExceptionOfType(t, DuplicateKeyException.class);
    if (dke == null) {
        return;
    }
    String constraint = findViolatedConstraintName(dke);
    if (constraint == null) {
        // should log it
        return;
    }
    // Handle case when uuid is duplicated
    if (DaoExceptionToFveTranslatorMySqlImpl.MYSQL_CONSTRAINT_PRIMARY.equals(constraint)) {
        throw new FieldValidationException(new DuplicateRecordValidationError(HasId.FN_ID));
    }
    if (!constraint.contains(DaoExceptionToFveTranslatorMySqlImpl.MYSQL_CONSTRAINT_UNIQUE)) {
        throw new IllegalArgumentException("Constraint violation " + constraint, dke);
    }
    String fieldName = constraint.substring(0, constraint.indexOf(DaoExceptionToFveTranslatorMySqlImpl.MYSQL_CONSTRAINT_UNIQUE));
    if (fieldName.contains("_")) {
        fieldName = JdbcUtils.convertUnderscoreNameToPropertyName(fieldName);
    }
    throw new FieldValidationException(new DuplicateRecordValidationError(fieldName));
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DuplicateRecordValidationError(org.summerb.validation.errors.DuplicateRecordValidationError)

Aggregations

FieldValidationException (org.summerb.validation.FieldValidationException)27 User (org.summerb.users.api.dto.User)11 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)11 Transactional (org.springframework.transaction.annotation.Transactional)9 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)8 ValidationContext (org.summerb.validation.ValidationContext)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 AuthToken (org.summerb.users.api.dto.AuthToken)3 InvalidPasswordException (org.summerb.users.api.exceptions.InvalidPasswordException)3 ValidationError (org.summerb.validation.ValidationError)3 ValidationErrorsVm (org.summerb.webappboilerplate.model.ValidationErrorsVm)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 NotAuthorizedResult (org.summerb.security.api.dto.NotAuthorizedResult)2 NotAuthorizedException (org.summerb.security.api.exceptions.NotAuthorizedException)2 DuplicateUserValidationError (org.summerb.users.api.validation.DuplicateUserValidationError)2 GenericException (org.summerb.utils.exceptions.GenericException)2 ExceptionInfo (org.summerb.utils.exceptions.dto.ExceptionInfo)2 GenericServerErrorResult (org.summerb.utils.exceptions.dto.GenericServerErrorResult)2 UserStatus (org.summerb.webappboilerplate.security.dto.UserStatus)2