T
- The type tested by the validator.public abstract class AbstractIntervalValidator<T> extends AbstractContentValidator implements Serviceable, Configurable
ContentValidator
validating the content by comparing one or more couples of values.
For each couple of values, the identified max value should be greater than or equal to the identified min value.Modifier and Type | Field and Description |
---|---|
private ContentHelper |
_contentHelper |
private boolean |
_mandatory |
private String |
_maxMetadataPath |
private String |
_minMetadataPath |
Constructor and Description |
---|
AbstractIntervalValidator() |
Modifier and Type | Method and Description |
---|---|
private void |
_checkMetadataDefinition(MetadataDefinition minDefinition,
MetadataDefinition maxDefinition) |
private List<SimpleField<T>> |
_getValues(Form form,
String metadataPath,
MetadataDefinition parentDefinition) |
protected void |
_validateInterval(Content content,
Errors errors,
MetadataDefinition minDefinition,
MetadataDefinition maxDefinition,
List<Object> minValues,
List<Object> maxValues)
Validate the interval values of a content
|
protected abstract void |
addErrorEmpty(Errors errors,
MetadataDefinition minDefinition,
MetadataDefinition maxDefinition,
I18nizableText emptyLabel)
Add an error when the max or the min value is empty but the interval is mandatory
|
protected abstract void |
addIntervalError(Errors errors,
MetadataDefinition minDefinition,
MetadataDefinition maxDefinition,
T min,
T max)
Add an error when the max value is less than the min value
|
void |
configure(Configuration configuration) |
protected abstract String |
configureMaxPath(Configuration configuration)
Get the metadata max path from the configuration
|
protected abstract String |
configureMinPath(Configuration configuration)
Get the metadata min path from the configuration
|
protected abstract SimpleField<T> |
getEmptyValue()
Get a value holder containing an empty value array.
|
protected abstract SimpleField<T> |
getValues(Form parentForm,
String fieldName)
Get the values of the field to validate from the form.
|
protected abstract boolean |
isLessThan(T n1,
T n2)
Test if the first number is less than the second one.
|
protected abstract boolean |
isSupportedType(MetadataType type)
Test if the metadata type is one expected by the validator
|
void |
service(ServiceManager manager) |
void |
validate(Content content,
Errors errors)
Validates a content.
|
void |
validate(Content content,
Form form,
MetadataSet metadataSet,
Errors errors)
Validates a content with the edited form.
|
getContentType, setContentType
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
private ContentHelper _contentHelper
private String _minMetadataPath
private String _maxMetadataPath
private boolean _mandatory
public AbstractIntervalValidator()
public void service(ServiceManager manager) throws ServiceException
service
in interface Serviceable
ServiceException
public void configure(Configuration configuration) throws ConfigurationException
configure
in interface Configurable
ConfigurationException
public void validate(Content content, Errors errors)
ContentValidator
validate
in interface ContentValidator
content
- the content to validateerrors
- the structure to populate if the validation failed.protected void _validateInterval(Content content, Errors errors, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, List<Object> minValues, List<Object> maxValues)
content
- The contenterrors
- The list of errors to fillminDefinition
- The definition for the min valuemaxDefinition
- The definition for the max valueminValues
- The list of min valuesmaxValues
- The list of max valuespublic void validate(Content content, Form form, MetadataSet metadataSet, Errors errors)
ContentValidator
validate
in interface ContentValidator
content
- the content to validateform
- the form to validatemetadataSet
- the edited metadata seterrors
- the structure to populate if the validation failed.private void _checkMetadataDefinition(MetadataDefinition minDefinition, MetadataDefinition maxDefinition)
private List<SimpleField<T>> _getValues(Form form, String metadataPath, MetadataDefinition parentDefinition)
protected abstract String configureMinPath(Configuration configuration) throws ConfigurationException
configuration
- The configurationConfigurationException
- If an error occursprotected abstract String configureMaxPath(Configuration configuration) throws ConfigurationException
configuration
- The configurationConfigurationException
- If an error occursprotected abstract SimpleField<T> getValues(Form parentForm, String fieldName)
parentForm
- The form containing the user values.fieldName
- The field name.protected abstract SimpleField<T> getEmptyValue()
protected abstract boolean isLessThan(T n1, T n2)
n1
- The first number to compare.n2
- The second number to compare.protected abstract boolean isSupportedType(MetadataType type)
type
- The metadata typeprotected abstract void addIntervalError(Errors errors, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, T min, T max)
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionmin
- The min valuemax
- The max valueprotected abstract void addErrorEmpty(Errors errors, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, I18nizableText emptyLabel)
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionemptyLabel
- The label of the empty field