Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore FreeForm validation v2 #989

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.validation.valueextraction.ValueExtractor;

import org.hibernate.validator.cfg.ConstraintMapping;
import org.hibernate.validator.cfg.propertyholder.PropertyHolderConstraintMapping;
import org.hibernate.validator.constraints.ParameterScriptAssert;
import org.hibernate.validator.constraints.ScriptAssert;
import org.hibernate.validator.spi.properties.GetterPropertySelectionStrategy;
Expand Down Expand Up @@ -64,8 +65,8 @@ public interface HibernateValidatorConfiguration extends Configuration<Hibernate
String ALLOW_PARALLEL_METHODS_DEFINE_PARAMETER_CONSTRAINTS = "hibernate.validator.allow_parallel_method_parameter_constraint";

/**
* @deprecated planned for removal. Use hibernate.validator.constraint_mapping_contributors instead.
* @since 5.2
* @deprecated planned for removal. Use hibernate.validator.constraint_mapping_contributors instead.
*/
@Deprecated
String CONSTRAINT_MAPPING_CONTRIBUTOR = "hibernate.validator.constraint_mapping_contributor";
Expand Down Expand Up @@ -334,4 +335,10 @@ public interface HibernateValidatorConfiguration extends Configuration<Hibernate
*/
@Incubating
HibernateValidatorConfiguration getterPropertySelectionStrategy(GetterPropertySelectionStrategy getterPropertySelectionStrategy);

@Incubating
HibernateValidatorConfiguration addPropertyHolderMapping(PropertyHolderConstraintMapping mapping);

@Incubating
PropertyHolderConstraintMapping createPropertyHolderConstraintMapping();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Facet of a constraint mapping creational context which allows to mark the underlying
* element as to be validated in a cascaded way.
*
* @author Gunnar Morling
* @author Kevin Pollet &lt;kevin.pollet@serli.com&gt; (C) 2011 SERLI
*/
public interface Cascadable<C extends Cascadable<C>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very generic. Maybe CascadableProperty would be better?


/**
* Marks the current element (property, parameter etc.) as cascadable.
*
* @return The current creational context following the method chaining pattern.
*/
C valid(String mapping);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark about using a String.


/**
* Adds a group conversion for this cascadable element. Several conversions may be configured for one element.
*
* @param from the source group of the conversion to be configured
*
* @return a creational context allow to set the target group of the conversion
*/
GroupConversionTargetContext<C> convertGroup(Class<?> from);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* @author Marko Bekhta
*/
public interface CascadableContainerElementConstraintMappingContext extends ContainerElementConstraintMappingContext,
Cascadable<CascadableContainerElementConstraintMappingContext> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Constraint mapping creational context representing a property of a property holder. Allows
* to place constraints on the property, mark the property as cascadable and to
* navigate to other constraint targets.
*
* @author Gunnar Morling
* @author Kevin Pollet &lt;kevin.pollet@serli.com&gt; (C) 2011 SERLI
* @author Marko Bekhta
*/
public interface CascadablePropertyConstraintMappingContext extends Constrainable<CascadablePropertyConstraintMappingContext>,
PropertyHolderTarget,
PropertyTarget,
Cascadable<CascadablePropertyConstraintMappingContext> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

import org.hibernate.validator.cfg.ConstraintDef;

/**
* Facet of a property holder constraint mapping creational context which allows to place
* constraints on the underlying element.
*
* @author Gunnar Morling
* @author Kevin Pollet &lt;kevin.pollet@serli.com&gt; (C) 2011 SERLI
*/
public interface Constrainable<C extends Constrainable<C>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about it being generic. Maybe ConstrainableProperty would be better?

/**
* Adds a new constraint.
*
* @param definition The constraint to add.
*
* @return The current creational context following the method chaining pattern.
*/
C constraint(ConstraintDef<?, ?> definition);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Constraint mapping creational context representing a type argument of a property, parameter or method return value
* with a generic (return) type. Allows to place constraints on that type argument, mark it as cascadable and to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is far more restricted in the case of a property holder (e.g. no methods for instance)

* navigate to other constraint targets.
*
* @author Gunnar Morling
* @since 6.0
*/
public interface ContainerElementConstraintMappingContext extends Constrainable<ContainerElementConstraintMappingContext>,
PropertyTarget,
PropertyHolderTarget,
ContainerElementTarget {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

import org.hibernate.validator.Incubating;

/**
* Facet of a constraint mapping creational context which allows to select a type argument or the component type of the
* (return) type of the current property as target for the next operations.
*
* @author Marko Bekhta
*/
@Incubating
public interface ContainerElementTarget {

ContainerElementConstraintMappingContext containerElementType(Class<?> type);

ContainerElementConstraintMappingContext containerElementType(Class<?> type, int index, int... nestedIndexes);

CascadableContainerElementConstraintMappingContext containerElementType(String mapping);

CascadableContainerElementConstraintMappingContext containerElementType(String mapping, int index, int... nestedIndexes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Creational context which allows to set the target group of a group conversion configured via
* {@link Cascadable#convertGroup(Class)}.
*
* @author Gunnar Morling
*/
public interface GroupConversionTargetContext<C> {

/**
* Sets the target group of the conversion to be configured.
*
* @param to the target group of the conversion
*
* @return The current creational context following the method chaining pattern.
*/
C to(Class<?> to);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Constraint mapping creational context representing a property of a property holder. Allows
* to place constraints on the property, mark the property as cascadable and to
* navigate to other constraint targets.
*
* @author Gunnar Morling
* @author Kevin Pollet &lt;kevin.pollet@serli.com&gt; (C) 2011 SERLI
* @author Marko Bekhta
*/
public interface PropertyConstraintMappingContext extends Constrainable<PropertyConstraintMappingContext>,
PropertyTarget,
PropertyHolderTarget,
ContainerElementTarget {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Represents a property holder constraint mapping configured via the programmatic API.
*
* @author Marko Bekhta
*/
public interface PropertyHolderConstraintMapping {

/**
* Starts defining constraints for the specified unique mapping name. Each mapping name may only be used
* once within all property holder constraint mappings used for configuring one validator factory.
*
* @param propertyHolderMappingName The mapping name for which to define constraints. All constraints
* defined after calling this method are added to the bean of the type {@code beanClass} until the
* next call of {@link this#type(String)}.
*
* @return Instance allowing for defining constraints for the specified property holder mapping name.
*/
TypeConstraintMappingContext type(String propertyHolderMappingName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Constraint mapping creational context representing a property of a property holder. Allows
* to place constraints on the property, mark the property as cascadable and to
* navigate to other constraint targets.
*
* @author Gunnar Morling
* @author Kevin Pollet &lt;kevin.pollet@serli.com&gt; (C) 2011 SERLI
* @author Marko Bekhta
*/
public interface PropertyHolderConstraintMappingContext extends Constrainable<PropertyHolderConstraintMappingContext>,
PropertyHolderTarget,
PropertyTarget,
Cascadable<PropertyHolderConstraintMappingContext> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Facet of a property holder constraint mapping creational context which allows to specify the
* property to which the next operations should be apply.
*
* @author Marko Bekhta
*/
public interface PropertyHolderTarget {

/**
* Defines a property, that is a property holder itself, to which the next operations shall apply.
* <p>
* Until this method is called constraints apply on property holder level. After calling this method constraints
* apply on the specified property with the given property type.
* </p>
* <p>
* A given property may only be configured once.
* </p>
*
* @param property The property holder on which to apply the following constraints.
*
* @return A creational context representing the selected property.
*/
PropertyHolderConstraintMappingContext propertyHolder(String property);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Facet of a property holder constraint mapping creational context which allows to specify the
* property to which the next operations should be apply.
*
* @author Marko Bekhta
*/
public interface PropertyTarget {

/**
* Defines a property to which the next operations shall apply.
* <p>
* Until this method is called constraints apply on property holder level. After calling this method constraints
* apply on the specified property with the given property type.
* </p>
* <p>
* A given property may only be configured once.
* </p>
*
* @param property The property on which to apply the following constraints.
* @param propertyType The type of the specified property.
*
* @return A creational context representing the selected property.
*/
PropertyConstraintMappingContext property(String property, Class<?> propertyType);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.cfg.propertyholder;

/**
* Constraint mapping creational context representing a type. Allows place
* class-level constraints on that type, define its default group sequence (and provider)
* and to navigate to other constraint targets.
*
* @author Kevin Pollet &lt;kevin.pollet@serli.com&gt; (C) 2011 SERLI
* @author Gunnar Morling
*/
public interface TypeConstraintMappingContext extends PropertyTarget, PropertyHolderTarget {

/**
* Defines the default group sequence for current type.
*
* @param defaultGroupSequence the default group sequence.
*
* @return The current creational context following the method chaining pattern.
*/
TypeConstraintMappingContext defaultGroupSequence(Class<?>... defaultGroupSequence);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/

/**
* <p>Contains facet and creational context interfaces forming the API for programmatic constraint
* definition for property holders validation.</p>
* <p>This package is part of the public Hibernate Validator API.</p>
*/
package org.hibernate.validator.cfg.propertyholder;
Loading