Class DefaultCustomerValidator<P extends Customer>
- java.lang.Object
-
- com.broadleafcommerce.customer.service.validation.DefaultCustomerValidator<P>
-
- Type Parameters:
P
- ACustomer
or 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 String
EMAIL_IN_USE
static String
EMAIL_INVALID
static String
USERNAME_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 void
addEmailAlreadyExistsError(org.springframework.validation.Errors errors)
protected void
addUsernameAlreadyExistsError(org.springframework.validation.Errors errors)
protected void
checkEmailAlreadyExists(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 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.protected P
fromRepositoryDomain(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.RsqlCrudEntityHelper
getHelper()
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.void
setHelper(com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
boolean
supports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
protected void
throwIfErrors(org.springframework.validation.Errors errors)
Throws aValidationException
ifErrors.hasErrors()
returns true.void
validate(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
protected void
validateCreate(P customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void
validateEmailFormat(P customer, org.springframework.validation.Errors errors)
Validates that the email provided is a valid format.void
validateForCreate(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
void
validateForReplace(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
void
validateForUpdate(Object customer, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
protected void
validateUpdate(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:
validate
in 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:
validateForCreate
in 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:
validateForUpdate
in 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:
validateForReplace
in 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:
supports
in 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 tocustomer
contextInfo
- 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 tocustomer
contextInfo
- The current context.
-
throwIfErrors
protected void throwIfErrors(org.springframework.validation.Errors errors)
Throws aValidationException
ifErrors.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()
-
-