use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class AttachmentValidationStrategyImpl method validateForCreate.
@Override
public void validateForCreate(Attachment dto) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
if (ctx.validateNotEmpty(dto.getName(), Attachment.FN_NAME)) {
ctx.validateDataLengthLessOrEqual(dto.getName(), Attachment.FN_NAME_MAXSIZE, Attachment.FN_NAME);
}
ctx.validateNotEmpty(dto.getArticleId(), Attachment.FN_ARTICLE_ID);
ctx.validateNotEmpty(dto.getSize(), Attachment.FN_SIZE);
ctx.validateNotNull(dto.getContents(), Attachment.FN_CONTENTS);
if (ctx.getHasErrors()) {
throw new FieldValidationException(ctx.getErrors());
}
}
use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectOkForValidExpression.
@Test
public void testValidateStringTemplate_blackbox_expectOkForValidExpression() throws Exception {
StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
String stringTemplate = "Constant text plus ${vars['4444']}";
ValidationContext ctx = new ValidationContext();
String fieldToken = "fieldToken";
StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
assertEquals(false, ctx.getHasErrors());
}
use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectValidationErrorForWrongExpression.
@Test
public void testValidateStringTemplate_blackbox_expectValidationErrorForWrongExpression() throws Exception {
StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
String stringTemplate = "Constant text plus ${vars['4444";
ValidationContext ctx = new ValidationContext();
String fieldToken = "fieldToken";
StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
assertEquals(true, ctx.getHasErrors());
}
use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class UserServiceImpl method validateUser.
private void validateUser(User user) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
validateEmail(user.getEmail(), ctx);
ctx.validateDataLengthLessOrEqual(user.getDisplayName(), User.FN_DISPLAY_NAME_SIZE, User.FN_DISPLAY_NAME);
ctx.throwIfHasErrors();
}
use of org.summerb.validation.ValidationContext in project summerb by skarpushin.
the class UsersServiceFacadeImpl method validatePasswordChangeRequestValid.
protected User validatePasswordChangeRequestValid(String email, PasswordChange passwordChange) throws UserNotFoundException, FieldValidationException {
ValidationContext ctx = new ValidationContext();
ctx.lengthEqOrGreater(passwordChange.getPassword(), 4, LoginParams.FN_PASSWORD);
ctx.equals(passwordChange.getPassword(), SecurityMessageCodes.NEW_PASSWORD, passwordChange.getNewPasswordAgain(), SecurityMessageCodes.NEW_PASSWORD_AGAIN, PasswordChange.FN_NEW_PASSWORD_AGAIN);
User user = null;
if (ctx.hasText(passwordChange.getCurrentPassword(), PasswordChange.FN_CURRENT_PASSWORD)) {
user = userService.getUserByEmail(email);
ctx.isTrue(passwordService.isUserPasswordValid(user.getUuid(), passwordChange.getCurrentPassword()), InvalidPasswordException.ERROR_LOGIN_INVALID_PASSWORD, PasswordChange.FN_CURRENT_PASSWORD);
}
ctx.throwIfHasErrors();
return user;
}
Aggregations