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);
}
}
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));
}
Aggregations