Class AugmentationValidator
java.lang.Object
com.broadleafcommerce.metadata.core.service.validation.AugmentationValidator
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
public class AugmentationValidator
extends Object
implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for
Augmentation
.- Author:
- Vitalii Voronkov (vvoronkov)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected AugmentationProperties
protected Map<String,
List<Augmentation>> getAugmentationsByTargetKey
(List<Augmentation> augmentations) Groups allaugmentations
to eachAugmentation.getTargetKey()
.protected AugmentationService<Augmentation>
protected FieldAugmentationPayload
getFieldAugmentationPayload
(Augmentation augmentation) protected com.fasterxml.jackson.databind.ObjectMapper
protected int
getNumberOfAugmentationsShownInQueryBuilders
(Map<String, List<Augmentation>> augmentationsByTargetKey) Counts the number of augmentations of typeClassifiers.FIELD
whereFieldAugmentationPayload.getShowInQueryBuilder()
is true.protected String
getTargetKeyForInsertAugmentation
(Augmentation augmentation) protected void
handleValidateCustomValidationMethod
(@NonNull ValidationMethodAugmentationPayload method, @NonNull org.springframework.validation.Errors errors) Hook-point for validating custom validation methods (not listed inValidationMethodName
).protected boolean
methodRequiresArgument
(String name) Determines whether the given validation method name requires arguments also be provided.void
setAugmentationProperties
(AugmentationProperties augmentationProperties) void
setAugmentationService
(AugmentationService<Augmentation> augmentationService) boolean
supports
(@NonNull Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) void
validate
(@NonNull Object businessInstance, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateFieldPayload
(@NonNull Augmentation augmentation, @NonNull org.springframework.validation.Errors errors) protected void
validateGroupPayload
(@NonNull Augmentation augmentation, @NonNull org.springframework.validation.Errors errors) protected void
validateMaxAugmentationQuantity
(Augmentation augmentation, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that creating a newAugmentation
of typeClassifiers.FIELD
will not exceed the maximum field quantity defined inAugmentationProperties.getUseInQueryBuilderRestrictions()
.protected void
validateValidationSchema
(@NonNull ValidationMethodAugmentationPayload method, @NonNull org.springframework.validation.Errors errors) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
validateForCreate, validateForReplace, validateForUpdate
-
Field Details
-
INVALID_FIELD_PAYLOAD
- See Also:
-
INVALID_GROUP_PAYLOAD
- See Also:
-
EXCEEDS_MAX_FIELD_QUANTITY
- See Also:
-
UNDEFINED_QUERY_BUILDER_RESTRICTIONS
- See Also:
-
-
Constructor Details
-
AugmentationValidator
public AugmentationValidator(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Details
-
supports
public boolean supports(@NonNull @NonNull Class<?> serviceClass, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
supports
in interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validate
public void validate(@NonNull @NonNull Object businessInstance, @NonNull @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
validate
in interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateMaxAugmentationQuantity
protected void validateMaxAugmentationQuantity(Augmentation augmentation, @NonNull @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that creating a newAugmentation
of typeClassifiers.FIELD
will not exceed the maximum field quantity defined inAugmentationProperties.getUseInQueryBuilderRestrictions()
.- Parameters:
augmentation
- the augmentation to validateerrors
- an errors object bound to theAugmentation
to be validatedcontextInfo
- the current context- Since:
- 2.0.2-GA
-
validateFieldPayload
protected void validateFieldPayload(@NonNull @NonNull Augmentation augmentation, @NonNull @NonNull org.springframework.validation.Errors errors) -
validateValidationSchema
protected void validateValidationSchema(@NonNull @NonNull ValidationMethodAugmentationPayload method, @NonNull @NonNull org.springframework.validation.Errors errors) -
methodRequiresArgument
Determines whether the given validation method name requires arguments also be provided. If the method name provided does not exist, returns false. This is in case a custom validation method is introduced.- Parameters:
name
- The name of a validation method. Does not have to exist.- Returns:
- Whether the given validation method name requires arguments also be provided
-
validateGroupPayload
protected void validateGroupPayload(@NonNull @NonNull Augmentation augmentation, @NonNull @NonNull org.springframework.validation.Errors errors) -
getFieldAugmentationPayload
-
getAugmentationsByTargetKey
protected Map<String,List<Augmentation>> getAugmentationsByTargetKey(List<Augmentation> augmentations) Groups allaugmentations
to eachAugmentation.getTargetKey()
. This method constructs the target key for augmentations of typeAugmentationChangeType.INSERT
, to match that ofAugmentationChangeType.REMOVE
orAugmentationChangeType.PATCH
augmentations targeting the same container.- Parameters:
augmentations
- the list of all augmentations- Returns:
- the map of augmentations to target keys
-
getNumberOfAugmentationsShownInQueryBuilders
protected int getNumberOfAugmentationsShownInQueryBuilders(Map<String, List<Augmentation>> augmentationsByTargetKey) Counts the number of augmentations of typeClassifiers.FIELD
whereFieldAugmentationPayload.getShowInQueryBuilder()
is true. This method only takes into account the most recent of all augmentations for each target container.- Parameters:
augmentationsByTargetKey
- the map of current augmentations mapped by their target key- Returns:
- the count of relevant augmentations
-
getTargetKeyForInsertAugmentation
-
handleValidateCustomValidationMethod
protected void handleValidateCustomValidationMethod(@NonNull @NonNull ValidationMethodAugmentationPayload method, @NonNull @NonNull org.springframework.validation.Errors errors) Hook-point for validating custom validation methods (not listed inValidationMethodName
).- Parameters:
method
- The validation method payloaderrors
- The errors object
-
getMapper
protected com.fasterxml.jackson.databind.ObjectMapper getMapper() -
getAugmentationProperties
-
setAugmentationProperties
-
getAugmentationService
-
setAugmentationService
@Autowired @Lazy public void setAugmentationService(AugmentationService<Augmentation> augmentationService)
-