Class AccountRoleValidator

  • All Implemented Interfaces:
    com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator

    public class AccountRoleValidator
    extends Object
    implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
    Basic validations for AccountRole.

    Validations related to context (and any basic prerequisite validation for that) are performed by AccountRoleContextValidator, which is invoked before this validator.

    Author:
    Samarth Dhruva (samarthd), Chris Kittrell (ckittrell)
    See Also:
    AccountRoleContextValidator
    • Constructor Detail

      • AccountRoleValidator

        public AccountRoleValidator()
    • Method Detail

      • setAccountRoleService

        @Autowired
        @Lazy
        public void setAccountRoleService​(AccountRoleService<AccountRole> accountRoleService)
        Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions
        Parameters:
        accountRoleService - the role service
      • 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
      • validateForReplace

        public void validateForReplace​(@NonNull
                                       @NonNull Object businessInstance,
                                       @NonNull
                                       @NonNull org.springframework.validation.Errors errors,
                                       @Nullable
                                       com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        validateForReplace in interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
      • validatePermissions

        protected void validatePermissions​(@NonNull
                                           @NonNull AccountRole role,
                                           @NonNull
                                           @NonNull org.springframework.validation.Errors errors)
        Permissions are validated for existence and accessibility by the DefaultAccountRoleContextValidator.

        This validation serves purely to guarantee that each permission reference has AccountPermissionRef.getId() and AccountPermissionRef.getName().

        In the JPA domain, each permission's Object.equals(Object) and Object.hashCode() excludes the id field from comparison. Thus, in our refs, if we have no field but the id, they will collide with each other when added to the role's Set of permissions.

        Since we expect the AccountPermission.getName() to be unique, those fields should be hydrated on the references, thereby preventing collisions.

        Parameters:
        role - the role to validate
        errors - the errors object bound to the role on which errors can be registered
      • validateParentRoleId

        protected void validateParentRoleId​(@NonNull
                                            @NonNull AccountRole role,
                                            @Nullable
                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo context,
                                            @NonNull
                                            @NonNull org.springframework.validation.Errors errors)
        At a minimum level, DefaultAccountRoleContextValidator validates that the direct parent of the role (if specified) in AccountRole.getParentRoleId() exists and is accessible from the child's context.

        On top of those validations, this validation:

        • traverses the full ancestry of the role to confirm each ancestor still exists and there are no cycles, either in the case that the ancestors already had cycles, or in the case that this role itself causes a cycle. See validateRoleAncestry(AccountRole, ContextInfo, Errors) for more information.
        Parameters:
        role - the role to validate
        context -
        errors - the errors object bound to the role on which errors can be registered
      • prefixWithEntityValidationMessageKey

        protected String prefixWithEntityValidationMessageKey​(@NonNull
                                                              @NonNull String errorCode)