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 1 commit
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 @@ -597,7 +597,7 @@ private void validateCascadedAnnotatedObjectForCurrentGroup(Object value, BaseBe
// already and need only to pass the current element
ValidationOrder validationOrder = validationOrderGenerator.getValidationOrder( currentGroup, currentGroup != originalGroup );

ValueContext<?, Object> cascadedValueContext = buildNewLocalExecutionContext( valueContext, value );
ValueContext<?, Object> cascadedValueContext = buildNewLocalExecutionContext( cascadingMetaData, valueContext, value );

validateInContext( validationContext, cascadedValueContext, validationOrder );
}
Expand Down Expand Up @@ -675,7 +675,7 @@ private void doValidate(Object value, String nodeName) {
// already and need only to pass the current element
ValidationOrder validationOrder = validationOrderGenerator.getValidationOrder( currentGroup, currentGroup != originalGroup );

ValueContext<?, Object> cascadedValueContext = buildNewLocalExecutionContext( valueContext, value );
ValueContext<?, Object> cascadedValueContext = buildNewLocalExecutionContext( cascadingMetaData, valueContext, value );

if ( cascadingMetaData.getDeclaredContainerClass() != null ) {
cascadedValueContext.setTypeParameter( cascadingMetaData.getDeclaredContainerClass(), cascadingMetaData.getDeclaredTypeParameterIndex() );
Expand All @@ -688,7 +688,7 @@ private void doValidate(Object value, String nodeName) {

// Cascade validation to container elements if we are dealing with a container element
if ( cascadingMetaData.hasContainerElementsMarkedForCascading() ) {
ValueContext<?, Object> cascadedTypeArgumentValueContext = buildNewLocalExecutionContext( valueContext, value );
ValueContext<?, Object> cascadedTypeArgumentValueContext = buildNewLocalExecutionContext( cascadingMetaData, valueContext, value );
if ( cascadingMetaData.getTypeParameter() != null ) {
cascadedValueContext.setTypeParameter( cascadingMetaData.getDeclaredContainerClass(), cascadingMetaData.getDeclaredTypeParameterIndex() );
}
Expand Down Expand Up @@ -737,13 +737,13 @@ private void validateCascadedContainerElementsInContext(Object value, BaseBeanVa
}
}

private ValueContext<?, Object> buildNewLocalExecutionContext(ValueContext<?, ?> valueContext, Object value) {
private ValueContext<?, Object> buildNewLocalExecutionContext(CascadingMetaData cascadingMetaData, ValueContext<?, ?> valueContext, Object value) {
ValueContext<?, Object> newValueContext;
Contracts.assertNotNull( value, "value cannot be null" );
newValueContext = ValueContext.getLocalExecutionContext(
validatorScopedContext.getParameterNameProvider(),
value,
beanMetaDataManager.getBeanMetaData( value.getClass() ),
cascadingMetaData.getBeanMetaDataForCascadable( beanMetaDataManager, value ),
Copy link
Member

Choose a reason for hiding this comment

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

Do you expect to have the metadata for the free form case in the beanMetaDataManager?

If not, I suspect we should push the beanMetaDataManager to the constructor (and we would have 2 implementations of CascadingMetaData in the end).

Not sure what you had in mind for that?

valueContext.getPropertyPath()
);
newValueContext.setCurrentValidatedValue( value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hibernate.validator.internal.engine.valueextraction.AnnotatedObject;
import org.hibernate.validator.internal.engine.valueextraction.ArrayElement;
import org.hibernate.validator.internal.engine.valueextraction.ValueExtractorManager;
import org.hibernate.validator.internal.metadata.BeanMetaDataManager;

/**
* An aggregated view of the cascading validation metadata. Note that it also includes the cascading validation metadata
Expand Down Expand Up @@ -59,4 +60,8 @@ public interface CascadingMetaData {
* time.
*/
CascadingMetaData addRuntimeContainerSupport(ValueExtractorManager valueExtractorManager, Class<?> valueClass);

default BeanMetaData<?> getBeanMetaDataForCascadable(BeanMetaDataManager beanMetaDataManager, Object value) {
return beanMetaDataManager.getBeanMetaData( value.getClass() );
}
}