Class AccountRoleValidator
- java.lang.Object
-
- com.broadleafcommerce.customer.service.validation.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 forAccountRole
.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 Summary
Constructors Constructor Description AccountRoleValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AccountRoleService<AccountRole>
getAccountRoleService()
protected String
prefixWithEntityValidationMessageKey(@NonNull String errorCode)
void
setAccountRoleService(AccountRoleService<AccountRole> accountRoleService)
Lazy injection since this validator is itself a service component.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)
void
validateForReplace(@NonNull Object businessInstance, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
protected void
validateParentRoleId(@NonNull AccountRole role, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, @NonNull org.springframework.validation.Errors errors)
At a minimum level,DefaultAccountRoleContextValidator
validates that the direct parent of the role (if specified) inAccountRole.getParentRoleId()
exists and is accessible from the child's context.protected void
validatePermissions(@NonNull AccountRole role, @NonNull org.springframework.validation.Errors errors)
Permissions are validated for existence and accessibility by theDefaultAccountRoleContextValidator
.
-
-
-
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 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
-
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 interfacecom.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 theDefaultAccountRoleContextValidator
.This validation serves purely to guarantee that each permission reference has
AccountPermissionRef.getId()
andAccountPermissionRef.getName()
.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'sSet
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 validateerrors
- the errors object bound to therole
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) inAccountRole.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 validatecontext
-errors
- the errors object bound to therole
on 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
-
prefixWithEntityValidationMessageKey
protected String prefixWithEntityValidationMessageKey(@NonNull @NonNull String errorCode)
-
getAccountRoleService
protected AccountRoleService<AccountRole> getAccountRoleService()
-
-