Class AdminRoleValidator
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
AdminRole.
Validations related to context (and any basic prerequisite validation for that) are performed by
AdminRoleContextValidator, which is invoked before this validator.
- Author:
- Samarth Dhruva (samarthd)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected AdminRoleService<AdminRole>protected StringprefixWithEntityValidationMessageKey(String errorCode) voidsetAdminRoleService(AdminRoleService<AdminRole> adminRoleService) Lazy injection since this validator is itself a service component.booleansupports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidvalidate(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidvalidateForReplace(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateName(org.springframework.validation.Errors errors) protected voidvalidateParentRoleId(AdminRole role, org.springframework.validation.Errors errors) At a minimum level,DefaultAdminRoleContextValidatorvalidates that the direct parent of the role (if specified) inAdminRole.parentRoleIdexists and is accessible from the child's context.protected voidvalidatePermissions(AdminRole role, org.springframework.validation.Errors errors) Permissions are validated for existence and accessibility by theDefaultAdminRoleContextValidator.protected voidvalidateRoleAncestry(AdminRole role, org.springframework.validation.Errors errors) For a cycle check, we could theoretically just compare the role's id against each of its ancestors instead of keeping a set of all seen ancestors.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, validateForUpdate
-
Constructor Details
-
AdminRoleValidator
public AdminRoleValidator()
-
-
Method Details
-
setAdminRoleService
Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
adminRoleService- the role service
-
supports
public boolean supports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
supportsin interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validate
public void validate(@NonNull Object businessInstance, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
validatein interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateForReplace
public void validateForReplace(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
validateForReplacein interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateName
protected void validateName(org.springframework.validation.Errors errors) -
validatePermissions
Permissions are validated for existence and accessibility by theDefaultAdminRoleContextValidator.This validation serves purely to guarantee that each permission reference has
AdminPermissionRef.idandAdminPermissionRef.name.In the JPA domain, each permission's
Object.equals(Object)andObject.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'sSetof permissions.Since we expect the
AdminPermission.nameandAdminPermission.tenantIdcombined to be unique, those fields should be hydrated on the references, thereby preventing collisions.AdminPermission.tenantIdcan be null for global permissions, so we will only validateAdminPermission.nameis present.- Parameters:
role- the role to validateerrors- the errors object bound to theroleon which errors can be registered
-
validateParentRoleId
At a minimum level,DefaultAdminRoleContextValidatorvalidates that the direct parent of the role (if specified) inAdminRole.parentRoleIdexists 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(AdminRole, Errors)for more information.
- Parameters:
role- the role to validateerrors- the errors object bound to theroleon which errors can be registered
- 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
For a cycle check, we could theoretically just compare the role's id against each of its ancestors instead of keeping a set of all seen ancestors. This is because we can be fairly confident that each already-persisted ancestor was also validated against having cycles in its own ancestry, and thus any cycle will almost definitely be caused by this role becoming a parent of itself.However, just in case there is a pre-existing cycle (perhaps an ancestor was persisted without any validation), we will check for it here. This also helps guard against an infinite loop in this logic which could be caused by such a cycle.
- Parameters:
role- the role whose ancestry should be validatederrors- the errors object bound to theroleon which errors can be registered
-
prefixWithEntityValidationMessageKey
-
getAdminRoleService
-