Tabnine Logo
HibernateConstraintValidatorContext
Code IndexAdd Tabnine to your IDE (free)

How to use
HibernateConstraintValidatorContext
in
org.hibernate.validator.constraintvalidation

Best Java code snippets using org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext (Showing top 20 results out of 315)

origin: graylog-labs/collector

  @Override
  public boolean isValid(String value, ConstraintValidatorContext context) {
    if (value == null) {
      return true;
    }
    final boolean valid = Arrays.asList(strings).contains(value);

    if (!valid) {
      HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
      hibernateContext.disableDefaultConstraintViolation();

      hibernateContext.addExpressionVariable("validValues", Joiner.on(" ").join(strings))
          .buildConstraintViolationWithTemplate(hibernateContext.getDefaultConstraintMessageTemplate())
          .addConstraintViolation();
    }

    return valid;
  }
}
origin: org.hibernate.validator/hibernate-validator

/**
 * @param collection the collection to validate
 * @param constraintValidatorContext context in which the constraint is evaluated
 *
 * @return true if the input collection is null or does not contain duplicate elements
 */
@Override
public boolean isValid(Collection collection, ConstraintValidatorContext constraintValidatorContext) {
  if ( collection == null || collection.size() < 2 ) {
    return true;
  }
  List<Object> duplicates = findDuplicates( collection );
  if ( duplicates.isEmpty() ) {
    return true;
  }
  if ( constraintValidatorContext instanceof HibernateConstraintValidatorContext ) {
    constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class )
        .addMessageParameter( "duplicates", duplicates.stream().map( String::valueOf ).collect( Collectors.joining( ", " ) ) )
        .withDynamicPayload( CollectionHelper.toImmutableList( duplicates ) );
  }
  return false;
}
origin: graylog-labs/collector

  private void setMessageTemplate(ConstraintValidatorContext context, String messageTemplate, String value) {
    HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
    hibernateContext.disableDefaultConstraintViolation();
    hibernateContext.addExpressionVariable("value", value).buildConstraintViolationWithTemplate(messageTemplate).addConstraintViolation();
  }
}
origin: stackoverflow.com

 public boolean isValid(Date value, ConstraintValidatorContext context) {
  Date now = GregorianCalendar.getInstance().getTime();

  if ( value.before( now ) ) {
    HibernateConstraintValidatorContext hibernateContext =
        context.unwrap( HibernateConstraintValidatorContext.class );

    hibernateContext.disableDefaultConstraintViolation();
    hibernateContext.addExpressionVariable( "now", now )
        .buildConstraintViolationWithTemplate( "Must be after ${now}" )
        .addConstraintViolation();

    return false;
  }

  return true;
}
origin: io.syndesis.rest/rest-dao

@Test
public void shouldAscertainPropertyUniqueness() {
  final HibernateConstraintValidatorContext context = mock(HibernateConstraintValidatorContext.class);
  when(context.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(context);
  when(context.addExpressionVariable(eq("nonUnique"), anyString())).thenReturn(context);
  when(context.getDefaultConstraintMessageTemplate()).thenReturn("template");
  final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
  when(context.buildConstraintViolationWithTemplate("template")).thenReturn(builder);
  when(builder.addPropertyNode(anyString())).thenReturn(mock(NodeBuilderCustomizableContext.class));
  assertThat(validator.isValid(connection, context)).isEqualTo(validity);
}
origin: io.syndesis/dao

@Override
public boolean isValid(final WithId<?> value, final ConstraintValidatorContext context) {
  if (value == null) {
    return true;
  }
  final PropertyAccessor bean = new BeanWrapperImpl(value);
  final String propertyValue = String.valueOf(bean.getPropertyValue(property));
  @SuppressWarnings({"rawtypes", "unchecked"})
  final Class<WithId> modelClass = (Class) value.getKind().modelClass;
  @SuppressWarnings("unchecked")
  final Set<String> ids = dataManager.fetchIdsByPropertyValue(modelClass, property, propertyValue);
  final boolean isUnique = ids.isEmpty() || value.getId().map(id -> ids.contains(id)).orElse(false);
  if (!isUnique) {
    if (ids.stream().allMatch(id -> consideredValidByException(modelClass, id))) {
      return true;
    }
    context.disableDefaultConstraintViolation();
    context.unwrap(HibernateConstraintValidatorContext.class).addExpressionVariable("nonUnique", propertyValue)
      .buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
      .addPropertyNode(property).addConstraintViolation();
  }
  return isUnique;
}
origin: com.typesafe.play/play-java-forms

/**
 * @param object            the object to check
 * @param constraintContext The JSR-303 validation context.
 * @return {@code true} if this value is valid for the given constraint.
 */
public boolean isValid(T object, ConstraintValidatorContext constraintContext) {
  return isValid(object, constraintContext.unwrap(HibernateConstraintValidatorContext.class).getConstraintValidatorPayload(ValidationPayload.class));
}
origin: com.typesafe.play/play-java-forms

  default boolean reportValidationStatus(final Object validationResult, final ConstraintValidatorContext constraintValidatorContext) {
    if(validationSuccessful(validationResult)) {
      return true;
    }
    constraintValidatorContext
      .unwrap(HibernateConstraintValidatorContext.class)
      .withDynamicPayload(validationResult);
    return false;
  }
}
origin: org.hibernate.validator/hibernate-validator

  @Override
  public boolean isValid(CharSequence value, ConstraintValidatorContext constraintValidatorContext) {
    if ( value == null ) {
      return true;
    }

    if ( constraintValidatorContext instanceof HibernateConstraintValidatorContext ) {
      constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class ).addMessageParameter( "regexp", escapedRegexp );
    }

    Matcher m = pattern.matcher( value );
    return m.matches();
  }
}
origin: com.typesafe.play/play-java-forms_2.11

/**
 * @param object            the object to check
 * @param constraintContext The JSR-303 validation context.
 * @return {@code true} if this value is valid for the given constraint.
 */
public boolean isValid(T object, ConstraintValidatorContext constraintContext) {
  return isValid(object, constraintContext.unwrap(HibernateConstraintValidatorContext.class).getConstraintValidatorPayload(ValidationPayload.class));
}
origin: com.typesafe.play/play-java-forms_2.12

  default boolean reportValidationStatus(final Object validationResult, final ConstraintValidatorContext constraintValidatorContext) {
    if(validationSuccessful(validationResult)) {
      return true;
    }
    constraintValidatorContext
      .unwrap(HibernateConstraintValidatorContext.class)
      .withDynamicPayload(validationResult);
    return false;
  }
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.hibernate-validator

  @Override
  public boolean isValid(CharSequence value, ConstraintValidatorContext constraintValidatorContext) {
    if ( value == null ) {
      return true;
    }

    if ( constraintValidatorContext instanceof HibernateConstraintValidatorContext ) {
      constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class ).addMessageParameter( "regexp", escapedRegexp );
    }

    Matcher m = pattern.matcher( value );
    return m.matches();
  }
}
origin: com.typesafe.play/play-java-forms_2.12

/**
 * @param object            the object to check
 * @param constraintContext The JSR-303 validation context.
 * @return {@code true} if this value is valid for the given constraint.
 */
public boolean isValid(T object, ConstraintValidatorContext constraintContext) {
  return isValid(object, constraintContext.unwrap(HibernateConstraintValidatorContext.class).getConstraintValidatorPayload(ValidationPayload.class));
}
origin: com.typesafe.play/play-java-forms_2.11

  default boolean reportValidationStatus(final Object validationResult, final ConstraintValidatorContext constraintValidatorContext) {
    if(validationSuccessful(validationResult)) {
      return true;
    }
    constraintValidatorContext
      .unwrap(HibernateConstraintValidatorContext.class)
      .withDynamicPayload(validationResult);
    return false;
  }
}
origin: org.hibernate.validator/hibernate-validator

@Override
public boolean isValid(Object[] arguments, ConstraintValidatorContext constraintValidatorContext) {
  if ( constraintValidatorContext instanceof HibernateConstraintValidatorContext ) {
    constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class ).addMessageParameter( "script", escapedScript );
  }
  List<String> parameterNames = ( (ConstraintValidatorContextImpl) constraintValidatorContext )
      .getMethodParameterNames();
  Map<String, Object> bindings = getBindings( arguments, parameterNames );
  return scriptAssertContext.evaluateScriptAssertExpression( bindings );
}
origin: com.typesafe.play/play-java-forms_2.11

  boolean isValid(final T value, final ValidationPayload payload, final ConstraintValidatorContext constraintValidatorContext);
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.hibernate-validator

@Override
public boolean isValid(Object[] arguments, ConstraintValidatorContext constraintValidatorContext) {
  if ( constraintValidatorContext instanceof HibernateConstraintValidatorContext ) {
    constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class ).addMessageParameter( "script", escapedScript );
  }
  List<String> parameterNames = ( (ConstraintValidatorContextImpl) constraintValidatorContext )
      .getMethodParameterNames();
  Map<String, Object> bindings = getBindings( arguments, parameterNames );
  return scriptAssertContext.evaluateScriptAssertExpression( bindings );
}
origin: com.typesafe.play/play-java-forms_2.12

  boolean isValid(final T value, final ValidationPayload payload, final ConstraintValidatorContext constraintValidatorContext);
}
origin: org.hibernate.validator/hibernate-validator

@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;
}
origin: com.typesafe.play/play-java-forms

  boolean isValid(final T value, final ValidationPayload payload, final ConstraintValidatorContext constraintValidatorContext);
}
org.hibernate.validator.constraintvalidationHibernateConstraintValidatorContext

Javadoc

A custom ConstraintValidatorContext which allows to set additional message parameters for interpolation.

Most used methods

  • addExpressionVariable
    Allows to set an additional expression variable which will be available as an EL variable during int
  • withDynamicPayload
    Allows to set an object that may further describe the violation. The user is responsible himself to
  • buildConstraintViolationWithTemplate
  • getConstraintValidatorPayload
    Returns an instance of the specified type or null if the current constraint validator payload isn't
  • addMessageParameter
    Allows to set an additional named parameter which can be interpolated in the constraint violation me
  • disableDefaultConstraintViolation
  • getDefaultConstraintMessageTemplate
  • getTimeProvider
    Returns the provider for obtaining the current time, e.g. when validating the Future and Pastconstra
  • unwrap

Popular in Java

  • Making http requests using okhttp
  • getResourceAsStream (ClassLoader)
  • addToBackStack (FragmentTransaction)
  • getContentResolver (Context)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now