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 Details

  • 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 interface com.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 interface com.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 new Augmentation of type Classifiers.FIELD will not exceed the maximum field quantity defined in AugmentationProperties.getUseInQueryBuilderRestrictions().
      Parameters:
      augmentation - the augmentation to validate
      errors - an errors object bound to the Augmentation to be validated
      contextInfo - 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

      protected boolean methodRequiresArgument(String name)
      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

      protected FieldAugmentationPayload getFieldAugmentationPayload(Augmentation augmentation)
    • getAugmentationsByTargetKey

      protected Map<String,List<Augmentation>> getAugmentationsByTargetKey(List<Augmentation> augmentations)
      Groups all augmentations to each Augmentation.getTargetKey(). This method constructs the target key for augmentations of type AugmentationChangeType.INSERT, to match that of AugmentationChangeType.REMOVE or AugmentationChangeType.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 type Classifiers.FIELD where FieldAugmentationPayload.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

      protected String getTargetKeyForInsertAugmentation(Augmentation augmentation)
    • handleValidateCustomValidationMethod

      protected void handleValidateCustomValidationMethod(@NonNull @NonNull ValidationMethodAugmentationPayload method, @NonNull @NonNull org.springframework.validation.Errors errors)
      Hook-point for validating custom validation methods (not listed in ValidationMethodName).
      Parameters:
      method - The validation method payload
      errors - The errors object
    • getMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
    • getAugmentationProperties

      protected AugmentationProperties getAugmentationProperties()
    • setAugmentationProperties

      @Autowired public void setAugmentationProperties(AugmentationProperties augmentationProperties)
    • getAugmentationService

      protected AugmentationService<Augmentation> getAugmentationService()
    • setAugmentationService

      @Autowired @Lazy public void setAugmentationService(AugmentationService<Augmentation> augmentationService)