Class DefaultCustomerValidator<P extends Customer>
- java.lang.Object
-
- com.broadleafcommerce.customer.service.validation.DefaultCustomerValidator<P>
-
- Type Parameters:
P- ACustomeror subclass of Customer.
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
public class DefaultCustomerValidator<P extends Customer> extends Object implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Default customer validator. Validates that username and email address are unique, and email is formatted correctly for a particular customer context.
-
-
Field Summary
Fields Modifier and Type Field Description static StringEMAIL_IN_USEstatic StringEMAIL_INVALIDstatic StringUSERNAME_IN_USE
-
Constructor Summary
Constructors Constructor Description DefaultCustomerValidator(CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable> customerRepository)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddEmailAlreadyExistsError(org.springframework.validation.Errors errors)protected voidaddUsernameAlreadyExistsError(org.springframework.validation.Errors errors)protected voidcheckEmailAlreadyExists(String id, Customer customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Validates that the e-mail address provided isn't already in use.protected voidcheckUsernameAlreadyExists(String id, P customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Validates that the username provided isn't already in use.protected PfromRepositoryDomain(com.broadleafcommerce.data.tracking.core.Trackable trackable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)protected CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable>getCustomerRepository()protected com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelpergetHelper()protected Optional<P>readByEmail(String email, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Read a customer by email address.protected Optional<P>readByUsername(String username, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Read a customer by username.voidsetHelper(com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)booleansupports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected voidthrowIfErrors(org.springframework.validation.Errors errors)Throws aValidationExceptionifErrors.hasErrors()returns true.voidvalidate(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected voidvalidateCreate(P customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)protected voidvalidateEmailFormat(P customer, org.springframework.validation.Errors errors)Validates that the email provided is a valid format.voidvalidateForCreate(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)voidvalidateForReplace(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)voidvalidateForUpdate(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected voidvalidateUpdate(String id, P customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
-
-
Field Detail
-
EMAIL_IN_USE
public static final String EMAIL_IN_USE
- See Also:
- Constant Field Values
-
USERNAME_IN_USE
public static final String USERNAME_IN_USE
- See Also:
- Constant Field Values
-
EMAIL_INVALID
public static final String EMAIL_INVALID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultCustomerValidator
public DefaultCustomerValidator(CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable> customerRepository)
-
-
Method Detail
-
validate
public void validate(@NonNull Object customer, @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
-
validateForCreate
public void validateForCreate(@NonNull Object customer, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)- Specified by:
validateForCreatein interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateForUpdate
public void validateForUpdate(@NonNull Object customer, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)- Specified by:
validateForUpdatein interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateForReplace
public void validateForReplace(@NonNull Object customer, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)- Specified by:
validateForReplacein interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
setHelper
@Autowired @Lazy public void setHelper(com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
-
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
-
validateCreate
protected void validateCreate(@NonNull P customer, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
validateUpdate
protected void validateUpdate(@Nullable String id, @NonNull P customer, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
validateEmailFormat
protected void validateEmailFormat(P customer, org.springframework.validation.Errors errors)
Validates that the email provided is a valid format.- Parameters:
customer- The customer to validate.errors- Errors object bound tocustomer
-
checkUsernameAlreadyExists
protected void checkUsernameAlreadyExists(String id, P customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Validates that the username provided isn't already in use.- Parameters:
id- Optional. The id of the customer being updated. If supplied, validation will pass if the customer is already the owner of the username.customer- The customer to validate.errors- Errors object bound tocustomercontextInfo- The current context.
-
checkEmailAlreadyExists
protected void checkEmailAlreadyExists(@Nullable String id, Customer customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Validates that the e-mail address provided isn't already in use.- Parameters:
id- Optional. The id of the customer being updated. If supplied, validation will pass if the customer is already the owner of the e-mail address.customer- The customer to validate.errors- Errors object bound tocustomercontextInfo- The current context.
-
throwIfErrors
protected void throwIfErrors(org.springframework.validation.Errors errors)
Throws aValidationExceptionifErrors.hasErrors()returns true. May be overridden if throwing a runtime exception is undesirable.- Parameters:
errors- The errors object bound to the customer that has been validated.
-
addEmailAlreadyExistsError
protected void addEmailAlreadyExistsError(org.springframework.validation.Errors errors)
-
addUsernameAlreadyExistsError
protected void addUsernameAlreadyExistsError(org.springframework.validation.Errors errors)
-
readByEmail
protected Optional<P> readByEmail(String email, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Read a customer by email address.- Parameters:
email- The username of the customer.contextInfo- The current context.- Returns:
- The customer who is assigned this e-mail address, or null if there is no customer with this e-mail address.
-
readByUsername
protected Optional<P> readByUsername(String username, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Read a customer by username.- Parameters:
username- The username of the customer.contextInfo- The current context.- Returns:
- The customer who is assigned this username, or null if there is no customer with this username.
-
fromRepositoryDomain
protected P fromRepositoryDomain(com.broadleafcommerce.data.tracking.core.Trackable trackable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
getCustomerRepository
protected CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCustomerRepository()
-
getHelper
protected com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper getHelper()
-
-