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 AugmentationPropertiesprotected Map<String,List<Augmentation>> getAugmentationsByTargetKey(List<Augmentation> augmentations) Groups allaugmentationsto eachAugmentation.getTargetKey().protected AugmentationService<Augmentation>protected FieldAugmentationPayloadgetFieldAugmentationPayload(Augmentation augmentation) protected com.fasterxml.jackson.databind.ObjectMapperprotected intgetNumberOfAugmentationsShownInQueryBuilders(Map<String, List<Augmentation>> augmentationsByTargetKey) Counts the number of augmentations of typeClassifiers.FIELDwhereFieldAugmentationPayload.getShowInQueryBuilder()is true.protected StringgetTargetKeyForInsertAugmentation(Augmentation augmentation) protected voidhandleValidateCustomValidationMethod(@NonNull ValidationMethodAugmentationPayload method, @NonNull org.springframework.validation.Errors errors) Hook-point for validating custom validation methods (not listed inValidationMethodName).protected booleanmethodRequiresArgument(String name) Determines whether the given validation method name requires arguments also be provided.voidsetAugmentationProperties(AugmentationProperties augmentationProperties) voidsetAugmentationService(AugmentationService<Augmentation> augmentationService) booleansupports(@NonNull Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidvalidate(@NonNull Object businessInstance, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateFieldPayload(@NonNull Augmentation augmentation, @NonNull org.springframework.validation.Errors errors) protected voidvalidateGroupPayload(@NonNull Augmentation augmentation, @NonNull org.springframework.validation.Errors errors) protected voidvalidateMaxAugmentationQuantity(Augmentation augmentation, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that creating a newAugmentationof typeClassifiers.FIELDwill not exceed the maximum field quantity defined inAugmentationProperties.getUseInQueryBuilderRestrictions().protected voidvalidateValidationSchema(@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, waitMethods 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:
supportsin 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:
validatein 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 newAugmentationof typeClassifiers.FIELDwill not exceed the maximum field quantity defined inAugmentationProperties.getUseInQueryBuilderRestrictions().- Parameters:
augmentation- the augmentation to validateerrors- an errors object bound to theAugmentationto 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 allaugmentationsto eachAugmentation.getTargetKey(). This method constructs the target key for augmentations of typeAugmentationChangeType.INSERT, to match that ofAugmentationChangeType.REMOVEorAugmentationChangeType.PATCHaugmentations 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.FIELDwhereFieldAugmentationPayload.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)
-