@Override public boolean isValid(Object value, ConstraintValidatorContext context) { List<Field> fieldsErros = new ArrayList<>(); Arrays.asList(value.getClass().getDeclaredFields()).forEach(f -> { f.setAccessible(true); try { if (!f.getName().equals(ID) && f.get(value) == null) { fieldsErros.add(f); context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()) .addPropertyNode(f.getName()) .addConstraintViolation(); } } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } }); return fieldsErros.isEmpty(); } }
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { List<Field> fieldsErros = new ArrayList<>(); Arrays.asList(value.getClass().getDeclaredFields()).forEach(f -> { f.setAccessible(true); try { if (!f.getName().equals(ID) && f.get(value) == null) { fieldsErros.add(f); context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()) .addPropertyNode(f.getName()) .addConstraintViolation(); } } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } }); return fieldsErros.isEmpty(); } }
@Override public boolean isValid(ValidPerson value, ConstraintValidatorContext context) { if (value.expectsAutowiredValidator) { assertNotNull(this.environment); } boolean valid = (value.name == null || !value.address.street.contains(value.name)); if (!valid && "Phil".equals(value.name)) { context.buildConstraintViolationWithTemplate( context.getDefaultConstraintMessageTemplate()).addPropertyNode("address").addConstraintViolation().disableDefaultConstraintViolation(); } return valid; } }
@Override public IConstraintValidationContext addError(String location, String message, Object... messageArgs) { location = validateLocation(location); addErrors().buildConstraintViolationWithTemplate(String.format(message, messageArgs)).addPropertyNode(location).addConstraintViolation(); return this; }
private void switchContext(final ConstraintValidatorContext pcontext) { pcontext.disableDefaultConstraintViolation(); pcontext.buildConstraintViolationWithTemplate(message).addPropertyNode(fieldCheckName) .addConstraintViolation(); pcontext.buildConstraintViolationWithTemplate(message).addPropertyNode(fieldAlternateCheckName) .addConstraintViolation(); } }
private void switchContext(final ConstraintValidatorContext pcontext) { pcontext.disableDefaultConstraintViolation(); pcontext.buildConstraintViolationWithTemplate(message).addPropertyNode(fieldCheckName) .addConstraintViolation(); pcontext.buildConstraintViolationWithTemplate(message).addPropertyNode(fieldAlternateCheckName) .addConstraintViolation(); } }
private void switchContext(final ConstraintValidatorContext pcontext) { pcontext.disableDefaultConstraintViolation(); pcontext.buildConstraintViolationWithTemplate(this.message) .addPropertyNode(this.fieldPhoneNumber).addConstraintViolation(); } }
private void switchContext(final ConstraintValidatorContext pcontext) { pcontext.disableDefaultConstraintViolation(); pcontext.buildConstraintViolationWithTemplate(message).addPropertyNode(fieldCheckName) .addConstraintViolation(); } }
private void switchContext(final ConstraintValidatorContext pcontext) { pcontext.disableDefaultConstraintViolation(); pcontext.buildConstraintViolationWithTemplate(message).addPropertyNode(fieldCheckName) .addConstraintViolation(); } }
@Override public boolean isValid(final Domain object, final ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (SyncopeConstants.MASTER_DOMAIN.equals(object.getKey())) { context.buildConstraintViolationWithTemplate( getTemplate(EntityViolationType.InvalidKey, "Reserved: " + SyncopeConstants.MASTER_DOMAIN)). addPropertyNode("key").addConstraintViolation(); return false; } return true; } }
@Override public boolean isValid(final Role role, final ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (role.getKey() == null || !KEY_PATTERN.matcher(role.getKey()).matches()) { context.buildConstraintViolationWithTemplate( getTemplate(EntityViolationType.InvalidKey, "Invalid role key")). addPropertyNode("key").addConstraintViolation(); return false; } return true; } }
@Override public boolean isValid(final AnyObject anyObject, final ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); boolean isValid = anyObject.getName() != null && KEY_PATTERN.matcher(anyObject.getName()).matches(); if (!isValid) { context.buildConstraintViolationWithTemplate( getTemplate(EntityViolationType.InvalidName, "Invalid any object name")). addPropertyNode("name").addConstraintViolation(); } return isValid; } }
@Override public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) { if ( constraintValidatorContext instanceof HibernateConstraintValidatorContext ) { constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class ).addMessageParameter( "script", escapedScript ); } boolean validationResult = scriptAssertContext.evaluateScriptAssertExpression( value, alias ); if ( !validationResult && !reportOn.isEmpty() ) { constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate( message ).addPropertyNode( reportOn ).addConstraintViolation(); } return validationResult; }
private boolean validateMinimal(String name, ConstraintValidatorContext context) { for (String illegalName : NAME_MAY_NOT_BE) { if (illegalName.equals(name)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( "name may not be " + illegalName) .addPropertyNode("name") .addConstraintViolation(); return false; } } for (String illegalContent : NAME_MAY_NOT_CONTAIN) { if (name.contains(illegalContent)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( "name may not contain " + illegalContent) .addPropertyNode("name") .addConstraintViolation(); return false; } } return true; } }
private boolean validateRegex(String name, ConstraintValidatorContext context) { if (!name.matches(regexp)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( "{io.fabric8.kubernetes.api.model.Pattern.message}") .addPropertyNode("name") .addConstraintViolation(); return false; } if (0 <= max && max < name.length()) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( "{io.fabric8.kubernetes.api.model.MaxLength.message}") .addPropertyNode("name") .addConstraintViolation(); return false; } return true; }
public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); Object fieldValue = beanWrapper.getPropertyValue(field); Object comparingFieldValue = beanWrapper.getPropertyValue(comparingField); boolean matched = ObjectUtils.nullSafeEquals(fieldValue, comparingFieldValue); if (matched) { return true; } else { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message) .addPropertyNode(field) .addConstraintViolation(); return false; } } }
public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); Object fieldValue = beanWrapper.getPropertyValue(field); Object comparingFieldValue = beanWrapper.getPropertyValue(comparingField); boolean matched = ObjectUtils.nullSafeEquals(fieldValue, comparingFieldValue); if (matched) { return true; } else { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message) .addPropertyNode(field) .addConstraintViolation(); return false; } } }
@Override public boolean isValid(ValidPerson value, ConstraintValidatorContext context) { if (value.expectsAutowiredValidator) { assertNotNull(this.environment); } boolean valid = (value.name == null || !value.address.street.contains(value.name)); if (!valid && "Phil".equals(value.name)) { context.buildConstraintViolationWithTemplate( context.getDefaultConstraintMessageTemplate()).addPropertyNode("address").addConstraintViolation().disableDefaultConstraintViolation(); } return valid; } }
@Override public boolean isValid(InnerBean bean, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (bean.getValue() == null) { context.buildConstraintViolationWithTemplate("NULL").addPropertyNode("value").addConstraintViolation(); return false; } return true; } }
@Override public boolean isValid(InnerBean bean, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (bean.getValue() == null) { context.buildConstraintViolationWithTemplate("NULL").addPropertyNode("value").addConstraintViolation(); return false; } return true; } }