public class ValidationSetDefault extends Object implements ValidationSet
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
VALIDATION_CODE_BLANK, VALIDATION_CODE_CAN_BE_CONVERTED_TO, VALIDATION_CODE_EMAIL, VALIDATION_CODE_EQUIVALENT, VALIDATION_CODE_EQUIVALENT_OR_GREATER, VALIDATION_CODE_EQUIVALENT_OR_LESS, VALIDATION_CODE_GREATER, VALIDATION_CODE_IS_OF_TYPE, VALIDATION_CODE_LENGTH, VALIDATION_CODE_LESS, VALIDATION_CODE_MAX_LENGTH, VALIDATION_CODE_MAX_SIZE, VALIDATION_CODE_MIN_LENGTH, VALIDATION_CODE_MIN_SIZE, VALIDATION_CODE_NOT_AN_ARRAY, VALIDATION_CODE_NOT_BLANK, VALIDATION_CODE_NOT_EQUIVALENT, VALIDATION_CODE_NOT_NULL, VALIDATION_CODE_NOT_PATTERN, VALIDATION_CODE_NULL, VALIDATION_CODE_PATTERN, VALIDATION_CODE_SIZE, VALIDATION_CODE_WHOLE_ARRAY_VALIDATION_RESULT_TYPE| Constructor and Description |
|---|
ValidationSetDefault(LinkedHashMap<String,List<ValidationMessage>> messages,
ValidationFactory validationFactory,
SpincastDictionary spincastDictionary,
JsonManager jsonManager,
XmlManager xmlManager,
ObjectConverter objectConverter)
Constructor
|
ValidationSetDefault(List<ValidationSet> existingResults,
ValidationFactory validationFactory,
SpincastDictionary spincastDictionary,
JsonManager jsonManager,
XmlManager xmlManager,
ObjectConverter objectConverter)
Constructor
|
ValidationSetDefault(String key,
List<ValidationMessage> messages,
ValidationFactory validationFactory,
SpincastDictionary spincastDictionary,
JsonManager jsonManager,
XmlManager xmlManager,
ObjectConverter objectConverter)
Constructor
|
ValidationSetDefault(String key,
ValidationMessage message,
ValidationFactory validationFactory,
SpincastDictionary spincastDictionary,
JsonManager jsonManager,
XmlManager xmlManager,
ObjectConverter objectConverter)
Constructor
|
ValidationSetDefault(ValidationFactory validationFactory,
SpincastDictionary spincastDictionary,
JsonManager jsonManager,
XmlManager xmlManager,
ObjectConverter objectConverter)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
ValidationSet |
addError(String validationKey,
String code,
String text)
Creates and adds a new Error validation Message.
|
ValidationSet |
addMessage(String validationKey,
ValidationLevel level,
String code,
String text)
Creates and adds a new validation Message.
|
ValidationSet |
addMessage(String validationKey,
ValidationMessage message)
Adds a new validation Message to this set, using the
specified validation key.
|
protected void |
addMessageFormattedSpecifickey(String key,
List<ValidationMessage> messages,
ValidationMessageFormatType formatType,
StringBuilder textBuilder,
JsonObject jsonObject) |
protected void |
addMessagesFormattedSpecifickeyHtml(String key,
StringBuilder textBuilder,
List<ValidationMessage> messages) |
protected void |
addMessagesFormattedSpecifickeyTextPlain(String key,
StringBuilder textBuilder,
List<ValidationMessage> messages) |
ValidationSet |
addSuccess(String validationKey,
String code,
String text)
Creates and adds a new Success validation Message.
|
ValidationSet |
addWarning(String validationKey,
String code,
String text)
Creates and adds a new Warning validation Message.
|
JsonObject |
convertToJsonObject()
Converts the set to a
JsonObject object. |
ValidationSet |
createValidationSet()
Creates a new, empty, validation set.
|
protected String |
getArrayItselfDefaultSuccessMessageText() |
protected String |
getArrayItselfDefaultValidationCode() |
protected String |
getArrayItselfDefaultValidationKey(String baseKey) |
protected SimpleValidator |
getBlankValidatorInfo() |
protected String |
getCssClassForErrorkey()
The css class to use for a key's <li> element.
|
protected String |
getCssClassForErrorMessage()
The css class to use for an error message's <li> element.
|
protected String |
getCssClassForSuccessMessage() |
protected String |
getCssClassForWarningMessage() |
protected String |
getDefaultErrorMessageText(String key) |
protected SimpleValidator |
getEmailValidatorInfo() |
protected SimpleValidator |
getEquivalentOrGreaterValidator(Object reference) |
protected SimpleValidator |
getEquivalentOrLessValidator(Object reference) |
protected SimpleValidator |
getEquivalentValidator(Object reference) |
protected SimpleValidator |
getGreaterValidator(Object reference) |
protected JsonManager |
getJsonManager() |
protected SimpleValidator |
getLengthValidator(int length) |
protected SimpleValidator |
getLessValidator(Object reference) |
protected SimpleValidator |
getMaxLengthValidator(int maxLength) |
protected SimpleValidator |
getMaxSizeValidator(int maxSize,
boolean ignoreNullValues) |
Map<String,List<ValidationMessage>> |
getMessages()
Gets the validation keys and their
associated messages.
|
List<ValidationMessage> |
getMessages(String key)
Gets the validation messages for the specified key.
|
String |
getMessagesFormatted(String jsonPath,
ValidationMessageFormatType formatType)
Quick way to get a formatted version of the validation
messages for the specified key.
|
String |
getMessagesFormatted(ValidationMessageFormatType formatType)
Quick way to get a formatted version of all validation
messages.
|
protected SimpleValidator |
getMinLengthValidator(int minLength) |
protected SimpleValidator |
getMinSizeValidator(int minSize,
boolean ignoreNullValues) |
protected SimpleValidator |
getNotBlankValidatorInfo() |
protected SimpleValidator |
getNotEquivalentValidator(Object reference) |
protected SimpleValidator |
getNotNullValidatorInfo() |
protected SimpleValidator |
getNotPatternValidator(String pattern) |
protected SimpleValidator |
getNullValidatorInfo() |
protected ObjectConverter |
getObjectConverter() |
protected SimpleValidator |
getPatternValidator(String pattern) |
protected String |
getSetItselfValidationKey() |
protected Integer |
getSize(Object element,
boolean ignoreNullValues) |
protected SimpleValidator |
getSizeValidator(int size,
boolean ignoreNullValues) |
protected SpincastDictionary |
getSpincastDictionary() |
protected ValidationFactory |
getValidationFactory() |
protected XmlManager |
getXmlManager() |
boolean |
hasMessages()
Does this validation set contain any validation
Messages?
|
boolean |
hasMessages(String key)
Does the the element at the specified key
contains validation Messages?
|
boolean |
isError()
Returns
true if the validation set
contains at least one ERROR message. |
boolean |
isError(String key)
Returns
true if the validation set
for the element at the specified key contains
at least one ERROR message. |
boolean |
isSuccess()
Returns
true if the validation set
only contains SUCCESS messages
(or contains no messages at all). |
boolean |
isSuccess(String key)
Returns
true if the validation set
for the element at the specified key only contains
SUCCESS messages
(or contains no messages at all). |
boolean |
isValid()
Returns
true if the validation set
does not contain ERROR messages. |
boolean |
isValid(String key)
Returns
true if the validation set
for the element at the specified key
does not contain ERROR messages. |
protected boolean |
isValidationDone() |
boolean |
isWarning()
Returns
true if the validation set
contains at least one WARNING message, but no
ERROR messages. |
boolean |
isWarning(String key)
Returns
true if the validation set
for the element at the specified key contains at
least one WARNING message, but no
ERROR messages. |
ValidationSet |
mergeValidationSet(String validationKeyPrefix,
ValidationSet set)
Adds an existing validation set and prefix all the
validation keys of this Set using the
validationKeyPrefix. |
ValidationSet |
mergeValidationSet(ValidationSet set)
Merges an existing validation set.
|
ValidationSet |
prefixValidationKeys(String prefix)
Prefix all the currently existing validation keys in this Set
with the specified prefix.
|
protected static LinkedHashMap<String,List<ValidationMessage>> |
toLinkedHashMap(String key,
List<ValidationMessage> messages) |
protected static LinkedHashMap<String,List<ValidationMessage>> |
toMessages(List<ValidationSet> existingResults) |
String |
toString() |
protected boolean |
usePrettyJson() |
protected boolean |
usePrettyXml() |
ValidationBuilderKey |
validation(SimpleValidator validator)
Starts a validation using a
custom
SimpleValidator. |
ValidationBuilderKey |
validationBlank()
Starts the creation of a "must be blank" validation.
|
ValidationBuilderKey |
validationEmail()
Starts the creation of a "email" validation.
|
ValidationBuilderKey |
validationEquivalent(Object reference)
Starts the creation of a "equivalent" validation.
|
ValidationBuilderKey |
validationEquivalentOrGreater(Object reference)
Starts the creation of a "equivalent or greater" validation.
|
ValidationBuilderKey |
validationEquivalentOrLess(Object reference)
Starts the creation of a "equivalent or less" validation.
|
ValidationBuilderKey |
validationGreater(Object reference)
Starts the creation of a "greater than" validation.
|
ValidationBuilderKey |
validationLength(int length)
Starts the creation of a "length" validation.
|
ValidationBuilderKey |
validationLess(Object reference)
Starts the creation of a "less than" validation.
|
ValidationBuilderKey |
validationMaxLength(int maxLength)
Starts the creation of a "maximum length" validation.
|
ValidationBuilderKey |
validationMaxSize(int maxSize,
boolean ignoreNullValues)
Starts the creation of a "maximum size" validation.
|
ValidationBuilderKey |
validationMinLength(int minLength)
Starts the creation of a "minimum length" validation.
|
ValidationBuilderKey |
validationMinSize(int minSize,
boolean ignoreNullValues)
Starts the creation of a "minimum size" validation.
|
ValidationBuilderKey |
validationNotBlank()
Starts the creation of a "not blank" validation.
|
ValidationBuilderKey |
validationNotEquivalent(Object reference)
Starts the creation of a "not equivalent" validation.
|
ValidationBuilderKey |
validationNotNull()
Starts the creation of a "not null" validation.
|
ValidationBuilderKey |
validationNotPattern(String pattern)
Starts the creation of a "pattern must not match" validation.
|
ValidationBuilderKey |
validationNull()
Starts the creation of a "must be null" validation.
|
ValidationBuilderKey |
validationPattern(String pattern)
Starts the creation of a "pattern must match" validation.
|
ValidationBuilderKey |
validationSize(int size,
boolean ignoreNullValues)
Starts the creation of a "size" validation.
|
public ValidationSetDefault(@Nullable LinkedHashMap<String,List<ValidationMessage>> messages, ValidationFactory validationFactory, SpincastDictionary spincastDictionary, JsonManager jsonManager, XmlManager xmlManager, ObjectConverter objectConverter)
public ValidationSetDefault(ValidationFactory validationFactory, SpincastDictionary spincastDictionary, JsonManager jsonManager, XmlManager xmlManager, ObjectConverter objectConverter)
public ValidationSetDefault(String key, List<ValidationMessage> messages, ValidationFactory validationFactory, SpincastDictionary spincastDictionary, JsonManager jsonManager, XmlManager xmlManager, ObjectConverter objectConverter)
public ValidationSetDefault(String key, ValidationMessage message, ValidationFactory validationFactory, SpincastDictionary spincastDictionary, JsonManager jsonManager, XmlManager xmlManager, ObjectConverter objectConverter)
public ValidationSetDefault(List<ValidationSet> existingResults, ValidationFactory validationFactory, SpincastDictionary spincastDictionary, JsonManager jsonManager, XmlManager xmlManager, ObjectConverter objectConverter)
protected static LinkedHashMap<String,List<ValidationMessage>> toLinkedHashMap(String key, List<ValidationMessage> messages)
protected static LinkedHashMap<String,List<ValidationMessage>> toMessages(List<ValidationSet> existingResults)
protected ValidationFactory getValidationFactory()
protected SpincastDictionary getSpincastDictionary()
protected JsonManager getJsonManager()
protected XmlManager getXmlManager()
protected ObjectConverter getObjectConverter()
protected boolean isValidationDone()
public ValidationSet createValidationSet()
ValidationSetcreateValidationSet in interface ValidationSetpublic ValidationSet addMessage(String validationKey, ValidationMessage message)
ValidationSetaddMessage in interface ValidationSetpublic ValidationSet addMessage(String validationKey, ValidationLevel level, String code, String text)
ValidationSetaddMessage in interface ValidationSetpublic ValidationSet addError(String validationKey, String code, String text)
ValidationSetaddError in interface ValidationSetpublic ValidationSet addWarning(String validationKey, String code, String text)
ValidationSetaddWarning in interface ValidationSetpublic ValidationSet addSuccess(String validationKey, String code, String text)
ValidationSetaddSuccess in interface ValidationSetpublic ValidationSet mergeValidationSet(ValidationSet set)
ValidationSetmergeValidationSet in interface ValidationSetpublic ValidationSet mergeValidationSet(String validationKeyPrefix, ValidationSet set)
ValidationSetvalidationKeyPrefix.mergeValidationSet in interface ValidationSetpublic boolean hasMessages()
ValidationSethasMessages in interface ValidationSetpublic boolean hasMessages(String key)
ValidationSethasMessages in interface ValidationSetpublic boolean isWarning()
ValidationSettrue if the validation set
contains at least one WARNING message, but no
ERROR messages.isWarning in interface ValidationSetpublic boolean isWarning(String key)
ValidationSettrue if the validation set
for the element at the specified key contains at
least one WARNING message, but no
ERROR messages.isWarning in interface ValidationSetpublic boolean isSuccess()
ValidationSettrue if the validation set
only contains SUCCESS messages
(or contains no messages at all).isSuccess in interface ValidationSetpublic boolean isSuccess(String key)
ValidationSettrue if the validation set
for the element at the specified key only contains
SUCCESS messages
(or contains no messages at all).isSuccess in interface ValidationSetpublic boolean isError()
ValidationSettrue if the validation set
contains at least one ERROR message.isError in interface ValidationSetpublic boolean isError(String key)
ValidationSettrue if the validation set
for the element at the specified key contains
at least one ERROR message.isError in interface ValidationSetpublic boolean isValid()
ValidationSettrue if the validation set
does not contain ERROR messages.
The set may contain
WARNING messages.
This is a synonym of !isError().
isValid in interface ValidationSetpublic boolean isValid(String key)
ValidationSettrue if the validation set
for the element at the specified key
does not contain ERROR messages.
The element may contains
WARNING messages.
This is a synonym of !isError(key).
isValid in interface ValidationSetpublic Map<String,List<ValidationMessage>> getMessages()
ValidationSetThe Map and the lists are immutable.
getMessages in interface ValidationSetpublic List<ValidationMessage> getMessages(String key)
ValidationSetThe list is immutable.
getMessages in interface ValidationSetpublic String getMessagesFormatted(ValidationMessageFormatType formatType)
ValidationSetgetMessagesFormatted in interface ValidationSetformatType - The type of output for the messages (Text, HTML, Json or XML).null if
there are no validation messages.public String getMessagesFormatted(String jsonPath, ValidationMessageFormatType formatType)
ValidationSetgetMessagesFormatted in interface ValidationSetformatType - The type of output for the messages (Text, HTML, Json or XML).null if
there are no validation messages.protected boolean usePrettyJson()
protected boolean usePrettyXml()
protected void addMessageFormattedSpecifickey(String key, List<ValidationMessage> messages, ValidationMessageFormatType formatType, StringBuilder textBuilder, JsonObject jsonObject)
protected void addMessagesFormattedSpecifickeyTextPlain(String key, StringBuilder textBuilder, List<ValidationMessage> messages)
protected void addMessagesFormattedSpecifickeyHtml(String key, StringBuilder textBuilder, List<ValidationMessage> messages)
protected String getCssClassForErrorkey()
protected String getCssClassForErrorMessage()
protected String getCssClassForSuccessMessage()
protected String getCssClassForWarningMessage()
public ValidationBuilderKey validation(SimpleValidator validator)
ValidationSetSimpleValidator.
This is useful when you have a validator that can be reuse in different contexts (as the ones provided by Spincast).
If you need full control over a validation, the number of
generated Messages for example, then you can instead run your
validations as you wish
and use #addMessage(ValidationMessage) and other
similar methods to add the resulting validation Messages to the
set.
validation in interface ValidationSetprotected String getArrayItselfDefaultValidationKey(String baseKey)
protected String getArrayItselfDefaultSuccessMessageText()
protected String getArrayItselfDefaultValidationCode()
protected SimpleValidator getNotBlankValidatorInfo()
public ValidationBuilderKey validationNotBlank()
ValidationSetvalidationNotBlank in interface ValidationSetprotected SimpleValidator getBlankValidatorInfo()
public ValidationBuilderKey validationBlank()
ValidationSetvalidationBlank in interface ValidationSetprotected SimpleValidator getEmailValidatorInfo()
public ValidationBuilderKey validationEmail()
ValidationSetvalidationEmail in interface ValidationSetprotected SimpleValidator getNullValidatorInfo()
public ValidationBuilderKey validationNull()
ValidationSetvalidationNull in interface ValidationSetprotected SimpleValidator getNotNullValidatorInfo()
public ValidationBuilderKey validationNotNull()
ValidationSetvalidationNotNull in interface ValidationSetprotected SimpleValidator getPatternValidator(String pattern)
public ValidationBuilderKey validationPattern(String pattern)
ValidationSetvalidationPattern in interface ValidationSetprotected SimpleValidator getNotPatternValidator(String pattern)
public ValidationBuilderKey validationNotPattern(String pattern)
ValidationSetvalidationNotPattern in interface ValidationSetprotected SimpleValidator getSizeValidator(int size, boolean ignoreNullValues)
public ValidationBuilderKey validationSize(int size, boolean ignoreNullValues)
ValidationSetvalidationSize in interface ValidationSetignoreNullValues - If true, null values will
be ignored in the total count. For example, if the size validation
is done on a JsonArray which is [null, null "abc"],
the size would be 3 if ignoreNullValues is false
and 1 if it's true.protected SimpleValidator getMinSizeValidator(int minSize, boolean ignoreNullValues)
public ValidationBuilderKey validationMinSize(int minSize, boolean ignoreNullValues)
ValidationSetvalidationMinSize in interface ValidationSetignoreNullValues - If true, null values will
be ignored in the total count. For example, if the size validation
is done on a JsonArray which is [null, null "abc"],
the size would be 3 if ignoreNullValues is false
and 1 if it's true.protected SimpleValidator getMaxSizeValidator(int maxSize, boolean ignoreNullValues)
public ValidationBuilderKey validationMaxSize(int maxSize, boolean ignoreNullValues)
ValidationSetvalidationMaxSize in interface ValidationSetignoreNullValues - If true, null values will
be ignored in the total count. For example, if the size validation
is done on a JsonArray which is [null, null "abc"],
the size would be 3 if ignoreNullValues is false
and 1 if it's true.protected SimpleValidator getLengthValidator(int length)
public ValidationBuilderKey validationLength(int length)
ValidationSetvalidationLength in interface ValidationSetprotected SimpleValidator getMinLengthValidator(int minLength)
public ValidationBuilderKey validationMinLength(int minLength)
ValidationSet
A null value returns false, otherwise
toString() is called on the other object to
check its "length".
validationMinLength in interface ValidationSetprotected SimpleValidator getMaxLengthValidator(int maxLength)
public ValidationBuilderKey validationMaxLength(int maxLength)
ValidationSet
A null value returns true, otherwise
toString() is called on the other object to
check its "length".
validationMaxLength in interface ValidationSetprotected SimpleValidator getEquivalentValidator(Object reference)
public ValidationBuilderKey validationEquivalent(Object reference)
ValidationSet
To validate if an element is equivalent to another,
one is converted to the type of the other if this is required.
If this conversion fails, they are not equivalent. When both
elements are of the same types, the #equals(Object)
method is used to compre them.
The exact logic to determine if two elements are equivalent
can be found in ObjectConverter.isEquivalent(Object, Object).
validationEquivalent in interface ValidationSetprotected SimpleValidator getNotEquivalentValidator(Object reference)
public ValidationBuilderKey validationNotEquivalent(Object reference)
ValidationSet
To validate if an element is equivalent to another,
one is converted to the type of the other if this is required.
If this conversion fails, they are not equivalent. When both
elements are of the same types, the #equals(Object)
method is used to compre them.
The exact logic to determine if two elements are equivalent
can be found in ObjectConverter.isEquivalent(Object, Object).
validationNotEquivalent in interface ValidationSetprotected SimpleValidator getLessValidator(Object reference)
public ValidationBuilderKey validationLess(Object reference)
ValidationSet
To validate if an element is less than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
validationLess in interface ValidationSetprotected SimpleValidator getGreaterValidator(Object reference)
public ValidationBuilderKey validationGreater(Object reference)
ValidationSet
To validate if an element is greater than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
validationGreater in interface ValidationSetprotected SimpleValidator getEquivalentOrLessValidator(Object reference)
public ValidationBuilderKey validationEquivalentOrLess(Object reference)
ValidationSet
To validate if an element is equivalent or less than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
validationEquivalentOrLess in interface ValidationSetprotected SimpleValidator getEquivalentOrGreaterValidator(Object reference)
public ValidationBuilderKey validationEquivalentOrGreater(Object reference)
ValidationSet
To validate if an element is equivalent or greater than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
validationEquivalentOrGreater in interface ValidationSetpublic JsonObject convertToJsonObject()
ValidationSetJsonObject object.
The resulting JsonObject object
is immutable.
convertToJsonObject in interface ToJsonObjectConvertibleconvertToJsonObject in interface ValidationSetprotected String getSetItselfValidationKey()
public ValidationSet prefixValidationKeys(String prefix)
ValidationSetprefixValidationKeys in interface ValidationSetCopyright © 2016. All rights reserved.