Class AttributeValidator
java.lang.Object
org.gcube.informationsystem.types.impl.validator.AttributeValidator
Used to validate the value fo one attribute against the attribute definition
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AttributeDefinitionThe definition of the attribute to validate against.protected final AttributeValidatorReportThe report containing validation results.protected static org.slf4j.LoggerThe logger for this class.protected final booleanWhether to stop validation on the first error.protected final org.gcube.com.fasterxml.jackson.databind.JsonNodeThe JSON value of the attribute to validate. -
Constructor Summary
ConstructorsConstructorDescriptionAttributeValidator(AttributeDefinition attributeDefinition, org.gcube.com.fasterxml.jackson.databind.JsonNode value) Constructs a new validator.AttributeValidator(AttributeDefinition attributeDefinition, org.gcube.com.fasterxml.jackson.databind.JsonNode value, boolean stopOnError) Constructs a new validator with the option to stop on the first error. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddError(StringBuffer sb) Adds an error message to the report and logs it.protected booleancheckPropertyTypeCompliance(org.gcube.com.fasterxml.jackson.databind.JsonNode value, String expectedPropertyType, StringBuffer sb, boolean fromMultipleInstaces) Checks the property type compliance.Returns the attribute definition.Returns the attribute validator report.protected StringBufferReturns a new string buffer for logging.protected StringBuffergetPropertyStringBuffer(StringBuffer sb, String expectedPropertyType, boolean fromMultipleInstaces) Returns a string buffer for a property.org.gcube.com.fasterxml.jackson.databind.JsonNodegetValue()Returns the value of the attribute.booleanChecks if the validator stops on the first error.protected booleantypeNotCompliant(org.gcube.com.fasterxml.jackson.databind.JsonNode value, String expectedType, StringBuffer sb) Checks if the type is compliant.booleanvalidate()Validates the attribute's value against its definition.protected booleanvalidate(String expectedType, org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a value against an expected type.protected booleanvalidateByte(org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a byte.protected booleanvalidateDate(org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a date.protected booleanvalidateNumber(Number number, StringBuffer sb) Validates a number against the attribute's min/max constraints.protected booleanvalidateString(org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a string.
-
Field Details
-
logger
protected static org.slf4j.Logger loggerThe logger for this class. -
stopOnError
protected final boolean stopOnErrorWhether to stop validation on the first error. -
attributeDefinition
The definition of the attribute to validate against. -
value
protected final org.gcube.com.fasterxml.jackson.databind.JsonNode valueThe JSON value of the attribute to validate. -
attributeValidatorReport
The report containing validation results.
-
-
Constructor Details
-
AttributeValidator
public AttributeValidator(AttributeDefinition attributeDefinition, org.gcube.com.fasterxml.jackson.databind.JsonNode value) Constructs a new validator.- Parameters:
attributeDefinition- The attribute definition.value- The JSON value.
-
AttributeValidator
public AttributeValidator(AttributeDefinition attributeDefinition, org.gcube.com.fasterxml.jackson.databind.JsonNode value, boolean stopOnError) Constructs a new validator with the option to stop on the first error.- Parameters:
attributeDefinition- The attribute definition.value- The JSON value.stopOnError-trueto stop on the first error.
-
-
Method Details
-
isStopOnError
public boolean isStopOnError()Checks if the validator stops on the first error.- Returns:
trueif the validator stops on the first error.
-
getAttributeDefinition
Returns the attribute definition.- Returns:
- The attribute definition.
-
getValue
public org.gcube.com.fasterxml.jackson.databind.JsonNode getValue()Returns the value of the attribute.- Returns:
- The value of the attribute.
-
getAttributeValidatorReport
Returns the attribute validator report.- Returns:
- The attribute validator report.
-
addError
Adds an error message to the report and logs it.- Parameters:
sb- The string buffer containing the error message.
-
getNewStringBuffer
Returns a new string buffer for logging.- Parameters:
sb- The string buffer.- Returns:
- The new string buffer.
-
validateNumber
Validates a number against the attribute's min/max constraints.- Parameters:
number- The number to validate.sb- The string buffer for error messages.- Returns:
trueif the number is valid,falseotherwise.
-
typeNotCompliant
protected boolean typeNotCompliant(org.gcube.com.fasterxml.jackson.databind.JsonNode value, String expectedType, StringBuffer sb) Checks if the type is compliant.- Parameters:
value- The value.expectedType- The expected type.sb- The string buffer.- Returns:
trueif the type is compliant.
-
validateString
protected boolean validateString(org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a string.- Parameters:
value- The value.sb- The string buffer.- Returns:
trueif the string is valid.
-
validateDate
protected boolean validateDate(org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a date.- Parameters:
value- The value.sb- The string buffer.- Returns:
trueif the date is valid.
-
validateByte
protected boolean validateByte(org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a byte.- Parameters:
value- The value.sb- The string buffer.- Returns:
trueif the byte is valid.
-
getPropertyStringBuffer
protected StringBuffer getPropertyStringBuffer(StringBuffer sb, String expectedPropertyType, boolean fromMultipleInstaces) Returns a string buffer for a property.- Parameters:
sb- The string buffer.expectedPropertyType- The expected property type.fromMultipleInstaces- Whether there are multiple instances.- Returns:
- The string buffer.
-
checkPropertyTypeCompliance
protected boolean checkPropertyTypeCompliance(org.gcube.com.fasterxml.jackson.databind.JsonNode value, String expectedPropertyType, StringBuffer sb, boolean fromMultipleInstaces) Checks the property type compliance.- Parameters:
value- The value.expectedPropertyType- The expected property type.sb- The string buffer.fromMultipleInstaces- Whether there are multiple instances.- Returns:
trueif the property type is compliant.
-
validate
protected boolean validate(String expectedType, org.gcube.com.fasterxml.jackson.databind.JsonNode value, StringBuffer sb) Validates a value against an expected type.- Parameters:
expectedType- The expected type.value- The value.sb- The string buffer.- Returns:
trueif the value is valid.
-
validate
public boolean validate()Validates the attribute's value against its definition.- Returns:
trueif the value is valid,falseotherwise.
-