Search in sources :

Example 11 with ValidationContext

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

the class UserServiceImpl method validateEmail.

private void validateEmail(String email) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    validateEmail(email, ctx);
    ctx.throwIfHasErrors();
}
Also used : ValidationContext(org.summerb.validation.ValidationContext)

Example 12 with ValidationContext

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

the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectOkForConstant.

@Test
public void testValidateStringTemplate_blackbox_expectOkForConstant() throws Exception {
    StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
    String stringTemplate = "Constant text";
    ValidationContext ctx = new ValidationContext();
    String fieldToken = "fieldToken";
    StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
    assertEquals(false, ctx.getHasErrors());
}
Also used : StringTemplateCompilerlImpl(org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl) StringTemplateCompiler(org.summerb.stringtemplate.api.StringTemplateCompiler) ValidationContext(org.summerb.validation.ValidationContext) Test(org.junit.Test)

Example 13 with ValidationContext

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

the class UsersServiceFacadeImpl method getUserStatusByEmail.

@Override
public UserStatus getUserStatusByEmail(String email) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    ctx.validateNotEmpty(email, LoginParams.FN_EMAIL);
    ctx.throwIfHasErrors();
    // Check if user have record
    User user = null;
    try {
        user = userService.getUserByEmail(email);
    } catch (UserNotFoundException nfe) {
        return UserStatus.NotExists;
    }
    // Check if user has ROLE_USER
    List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
    if (permissions.contains(SecurityConstants.ROLE_USER)) {
        return UserStatus.NormalUser;
    }
    if (permissions.contains(SecurityConstants.MARKER_AWAITING_ACTIVATION)) {
        return UserStatus.AwaitingActivation;
    }
    return UserStatus.Provisioned;
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) ValidationContext(org.summerb.validation.ValidationContext)

Example 14 with ValidationContext

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

the class DaoExceptionToFveTranslatorPostgresImpl method throwIfDuplicate.

private void throwIfDuplicate(Throwable t) throws FieldValidationException {
    DuplicateKeyException dke = ExceptionUtils.findExceptionOfType(t, DuplicateKeyException.class);
    if (dke == null) {
        return;
    }
    PSQLException dkep = ExceptionUtils.findExceptionOfType(t, PSQLException.class);
    if (dkep == null) {
        return;
    }
    String detail = dkep.getServerErrorMessage().getDetail();
    if (!StringUtils.hasText(detail)) {
        return;
    }
    if (!detail.startsWith("Key (")) {
        return;
    }
    String fieldsStr = detail.substring(5, detail.indexOf(")"));
    String[] fields = fieldsStr.split(",");
    ValidationContext ctx = new ValidationContext();
    for (String field : fields) {
        ctx.add(new DuplicateRecordValidationError(JdbcUtils.convertUnderscoreNameToPropertyName(field.trim())));
    }
    ctx.throwIfHasErrors();
}
Also used : PSQLException(org.postgresql.util.PSQLException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) ValidationContext(org.summerb.validation.ValidationContext) DuplicateRecordValidationError(org.summerb.validation.errors.DuplicateRecordValidationError)

Aggregations

ValidationContext (org.summerb.validation.ValidationContext)14 FieldValidationException (org.summerb.validation.FieldValidationException)4 Test (org.junit.Test)3 StringTemplateCompiler (org.summerb.stringtemplate.api.StringTemplateCompiler)3 StringTemplateCompilerlImpl (org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl)3 User (org.summerb.users.api.dto.User)2 PSQLException (org.postgresql.util.PSQLException)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)1 DuplicateRecordValidationError (org.summerb.validation.errors.DuplicateRecordValidationError)1 UserStatus (org.summerb.webappboilerplate.security.dto.UserStatus)1 PasswordsDontMatchValidationError (org.summerb.webappboilerplate.security.ve.PasswordsDontMatchValidationError)1 RegistrationRequiredValidationError (org.summerb.webappboilerplate.security.ve.RegistrationRequiredValidationError)1