Class DataDrivenEnumValidator
java.lang.Object
com.broadleafcommerce.catalog.service.validation.DataDrivenEnumValidator
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
public class DataDrivenEnumValidator
extends Object
implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Basic validations for
DataDrivenEnum
.- Author:
- Sunny Yu
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkTypeAndValueAlreadyExists
(String id, DataDrivenEnum dataDrivenEnum, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that the type and value combination provided isn't already in use.protected DataDrivenEnumService<DataDrivenEnum>
protected String
prefixWithEntityValidationMessageKey
(String errorCode) protected Optional<DataDrivenEnum>
readByTypeAndValue
(String type, String value, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read a data driven enum by type and value.void
setDataDrivenEnumService
(DataDrivenEnumService<DataDrivenEnum> dataDrivenEnumService) Lazy injection since this validator is itself a service component.boolean
supports
(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) void
validate
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateDisplayValue
(org.springframework.validation.Errors errors) void
validateForReplace
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) void
validateForUpdate
(Object updatedBusinessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateType
(org.springframework.validation.Errors errors) protected void
validateUpdate
(DataDrivenEnum dataDrivenEnum, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
validateValue
(DataDrivenEnum dataDrivenEnum, org.springframework.validation.Errors errors) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
validateForCreate
-
Constructor Details
-
DataDrivenEnumValidator
public DataDrivenEnumValidator()
-
-
Method Details
-
setDataDrivenEnumService
@Autowired @Lazy public void setDataDrivenEnumService(DataDrivenEnumService<DataDrivenEnum> dataDrivenEnumService) Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
dataDrivenEnumService
- the data driven enum service
-
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
-
validate
public void validate(@NonNull Object businessInstance, @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
-
validateForUpdate
public void validateForUpdate(@NonNull Object updatedBusinessInstance, @NonNull org.springframework.validation.Errors errors, @Nullable 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 businessInstance, @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
-
validateUpdate
protected void validateUpdate(@NonNull DataDrivenEnum dataDrivenEnum, @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
validateType
protected void validateType(org.springframework.validation.Errors errors) -
validateValue
protected void validateValue(@NonNull DataDrivenEnum dataDrivenEnum, org.springframework.validation.Errors errors) -
validateDisplayValue
protected void validateDisplayValue(org.springframework.validation.Errors errors) -
checkTypeAndValueAlreadyExists
protected void checkTypeAndValueAlreadyExists(@Nullable String id, @NonNull DataDrivenEnum dataDrivenEnum, @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that the type and value combination provided isn't already in use.- Parameters:
id
- Optional. The id of the data driven enum being updated. If supplied, validation will pass if the data driven enum is already the owner of the type and value.dataDrivenEnum
- The data driven enum to validate.errors
- Errors object bound todataDrivenEnum
contextInfo
- The current context.
-
readByTypeAndValue
protected Optional<DataDrivenEnum> readByTypeAndValue(@Nullable String type, @Nullable String value, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read a data driven enum by type and value.- Parameters:
type
- The type of the enum.value
- The value of the enum.contextInfo
- The current context.- Returns:
- an
Optional
containing theDataDrivenEnum
with the type and value combination
-
prefixWithEntityValidationMessageKey
-
getEnumValuePattern
-
getDataDrivenEnumService
-