Package org.faktorips.runtime.validation
Class DefaultDatabaseLengthValidationConfiguration
java.lang.Object
org.faktorips.runtime.validation.DefaultDatabaseLengthValidationConfiguration
- All Implemented Interfaces:
IDatabaseLengthValidationConfiguration
public class DefaultDatabaseLengthValidationConfiguration
extends Object
implements IDatabaseLengthValidationConfiguration
Default
configuration for the
DatabaseLengthValidation.
It offers a number of with~ methods for a fluent configuration.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new configuration using the givenLocaleusing the defaultResourceBundleforRESOURCE_BUNDLE_NAME.DefaultDatabaseLengthValidationConfiguration(Locale locale, ResourceBundle resourceBundle) Creates a new configuration using the givenLocaleandResourceBundleto create validation messages. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddMarker(Message.Builder messageBuilder) Adds thegetTechnicalConstraintViolationMarker()to the givenMessage.Builder.protected MessagecreateMessage(String msgKey, String msgCode, IModelObject modelObject, PolicyAttribute attribute, int actualValue, int maxValue) Returns a message, using the given parameters as follows:.createMessageForPrecisionViolation(PolicyAttribute attribute, IModelObject modelObject, Class<? extends Number> numericDatatype, int actualPrecision, int precisionLimit) Creates a message to indicate that the given attribute's value on the given model object exceeds the configuredNumericConstraint`sprecision.createMessageForScaleViolation(PolicyAttribute attribute, IModelObject modelObject, Class<? extends Number> numericDatatype, int actualScale, int scaleLimit) Creates a message to indicate that the given attribute's value on the given model object exceeds the configuredNumericConstraint`sscale.createMessageForStringLengthViolation(PolicyAttribute attribute, IModelObject modelObject, int actualLength, int lengthLimit) Creates a message to indicate that the given attribute's value on the given model object exceeds the configuredStringLengthConstraint.Returns the locale to be used for validation messages.getNumericConstraint(Class<? extends Number> numericDatatype) Returns the constraint to be used to validate numeric attributes of the given type.protected ResourceBundleReturns the used resource bundle.Returns the constraint to be used to validate String attributes.Returns the marker to be used for validation messages.booleanshouldValidate(PolicyAttribute policyAttribute, IModelObject modelObject) Decides whether the givenPolicyAttributeshould be validated for the givenIModelObject.withAttributeFilter(BiPredicate<PolicyAttribute, IModelObject> shouldValidate) Returns this configuration, updated to use the given predicate to determine which attributes to validate.withNumericConstraint(Class<? extends Number> numericDatatype, int precision) Returns this configuration, updated to use a new constraint created from the given precision (and no scale) to check numeric values of the given data type.withNumericConstraint(Class<? extends Number> numericDatatype, int precision, int scale) Returns this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of the given data type.withNumericConstraint(Class<? extends Number> numericDatatype, NumericConstraint numericConstraint) Returns this configuration, updated to use the given constraint to check numeric values of the given data type.withNumericConstraintForAllNumbers(int precision, int scale) Returns this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of any numeric data type.withStringLengthConstraint(int maxStringByteLength) Returns this configuration, updated to use a new constraint created from the given length to check String values in UTF-8.withStringLengthConstraint(Charset stringEncoding, int maxStringByteLength) Returns this configuration, updated to use a new constraint created from the given encoding and length to check String values.withStringLengthConstraint(StringLengthConstraint stringLengthConstraint) Returns this configuration, updated to use the given constraint to check String values.withTechnicalConstraintViolationMarker(IMarker technicalConstraintViolationMarker) Returns this configuration, updated to use the given marker on validation messages.
-
Field Details
-
MSGCODE_STRING_TOO_LONG
- See Also:
-
MSGKEY_STRING_TOO_LONG
- See Also:
-
MSGCODE_NUMBER_EXCEEDS_PRECISION
- See Also:
-
MSGKEY_NUMBER_EXCEEDS_PRECISION
- See Also:
-
MSGCODE_NUMBER_EXCEEDS_SCALE
- See Also:
-
MSGKEY_NUMBER_EXCEEDS_SCALE
- See Also:
-
RESOURCE_BUNDLE_NAME
-
-
Constructor Details
-
DefaultDatabaseLengthValidationConfiguration
Creates a new configuration using the givenLocaleandResourceBundleto create validation messages.- Parameters:
locale- the locale to be usedresourceBundle- a resource bundle; it should contain messages for the validation messages in the given locale
-
DefaultDatabaseLengthValidationConfiguration
Creates a new configuration using the givenLocaleusing the defaultResourceBundleforRESOURCE_BUNDLE_NAME.- Parameters:
locale- the locale to be used
-
-
Method Details
-
getLocale
Description copied from interface:IDatabaseLengthValidationConfigurationReturns the locale to be used for validation messages.- Specified by:
getLocalein interfaceIDatabaseLengthValidationConfiguration- Returns:
- the locale to be used for validation messages
-
getResourceBundle
Returns the used resource bundle.- Returns:
- the used resource bundle
-
withTechnicalConstraintViolationMarker
public DefaultDatabaseLengthValidationConfiguration withTechnicalConstraintViolationMarker(IMarker technicalConstraintViolationMarker) Returns this configuration, updated to use the given marker on validation messages.- Parameters:
technicalConstraintViolationMarker- a marker to be used on all validation messages created by this configuration- Returns:
- this configuration, updated to use the given marker on validation messages
-
getTechnicalConstraintViolationMarker
Description copied from interface:IDatabaseLengthValidationConfigurationReturns the marker to be used for validation messages.- Specified by:
getTechnicalConstraintViolationMarkerin interfaceIDatabaseLengthValidationConfiguration- Returns:
- the marker to be used for validation messages
-
withStringLengthConstraint
public DefaultDatabaseLengthValidationConfiguration withStringLengthConstraint(StringLengthConstraint stringLengthConstraint) Returns this configuration, updated to use the given constraint to check String values.- Parameters:
stringLengthConstraint- aStringLengthConstraintto be used to check String values- Returns:
- this configuration, updated to use the given constraint to check String values
-
withStringLengthConstraint
public DefaultDatabaseLengthValidationConfiguration withStringLengthConstraint(Charset stringEncoding, int maxStringByteLength) Returns this configuration, updated to use a new constraint created from the given encoding and length to check String values.- Parameters:
stringEncoding- aCharsetto be used to convert Strings into their Byte representationmaxStringByteLength- the maximum number of Bytes a String representation may have- Returns:
- this configuration, updated to use a new constraint created from the given encoding and length to check String values
- See Also:
-
withStringLengthConstraint
public DefaultDatabaseLengthValidationConfiguration withStringLengthConstraint(int maxStringByteLength) Returns this configuration, updated to use a new constraint created from the given length to check String values in UTF-8.- Parameters:
maxStringByteLength- the maximum number of Bytes a String representation inStandardCharsets.UTF_8may have- Returns:
- this configuration, updated to use a new constraint created from the given length to check String values in UTF-8
- See Also:
-
getStringLengthConstraint
Description copied from interface:IDatabaseLengthValidationConfigurationReturns the constraint to be used to validate String attributes.- Specified by:
getStringLengthConstraintin interfaceIDatabaseLengthValidationConfiguration- Returns:
- the constraint to be used to validate String attributes
-
withNumericConstraint
public DefaultDatabaseLengthValidationConfiguration withNumericConstraint(Class<? extends Number> numericDatatype, NumericConstraint numericConstraint) Returns this configuration, updated to use the given constraint to check numeric values of the given data type.- Parameters:
numericDatatype- a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.numericConstraint- aNumericConstraintto be used to check numeric values- Returns:
- this configuration, updated to use the given constraint to check numeric values of the given data type
-
withNumericConstraint
public DefaultDatabaseLengthValidationConfiguration withNumericConstraint(Class<? extends Number> numericDatatype, int precision, int scale) Returns this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of the given data type.- Parameters:
numericDatatype- a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.precision- the maximum total number of digits usable to represent a number of the given typescale- the maximum number of decimal places usable to represent a number of the given type- Returns:
- this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of the given data type
- See Also:
-
withNumericConstraint
public DefaultDatabaseLengthValidationConfiguration withNumericConstraint(Class<? extends Number> numericDatatype, int precision) Returns this configuration, updated to use a new constraint created from the given precision (and no scale) to check numeric values of the given data type.- Parameters:
numericDatatype- a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.precision- the maximum total number of digits usable to represent a number of the given type- Returns:
- this configuration, updated to use a new constraint created from the given precision (and no scale) to check numeric values of the given data type
- See Also:
-
withNumericConstraintForAllNumbers
public DefaultDatabaseLengthValidationConfiguration withNumericConstraintForAllNumbers(int precision, int scale) Returns this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of any numeric data type.- Parameters:
precision- the maximum total number of digits usable to represent a number of the given typescale- the maximum number of decimal places usable to represent a number of the given type- Returns:
- this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of any numeric data type
- See Also:
-
getNumericConstraint
Description copied from interface:IDatabaseLengthValidationConfigurationReturns the constraint to be used to validate numeric attributes of the given type.- Specified by:
getNumericConstraintin interfaceIDatabaseLengthValidationConfiguration- Parameters:
numericDatatype- a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.- Returns:
- the constraint to be used to validate numeric attributes of the given type
-
shouldValidate
Description copied from interface:IDatabaseLengthValidationConfigurationDecides whether the givenPolicyAttributeshould be validated for the givenIModelObject.- Specified by:
shouldValidatein interfaceIDatabaseLengthValidationConfiguration- Parameters:
policyAttribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute may be validated- Returns:
- whether validation for the given combination of
PolicyAttributeandIModelObjectshould run
-
withAttributeFilter
public DefaultDatabaseLengthValidationConfiguration withAttributeFilter(BiPredicate<PolicyAttribute, IModelObject> shouldValidate) Returns this configuration, updated to use the given predicate to determine which attributes to validate.- Parameters:
shouldValidate- a predicate, returningtruefor attributes that should be validated- Returns:
- this configuration, updated to use the given predicate to determine which attributes to validate
- See Also:
-
createMessageForStringLengthViolation
public Message createMessageForStringLengthViolation(PolicyAttribute attribute, IModelObject modelObject, int actualLength, int lengthLimit) Description copied from interface:IDatabaseLengthValidationConfigurationCreates a message to indicate that the given attribute's value on the given model object exceeds the configuredStringLengthConstraint.- Specified by:
createMessageForStringLengthViolationin interfaceIDatabaseLengthValidationConfiguration- Parameters:
attribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validatedactualLength- the actual value's length in bytes according to theCharsetused in the constraintlengthLimit- the exceeded limit, set in the constraint
-
createMessageForPrecisionViolation
public Message createMessageForPrecisionViolation(PolicyAttribute attribute, IModelObject modelObject, Class<? extends Number> numericDatatype, int actualPrecision, int precisionLimit) Description copied from interface:IDatabaseLengthValidationConfigurationCreates a message to indicate that the given attribute's value on the given model object exceeds the configuredNumericConstraint`sprecision.- Specified by:
createMessageForPrecisionViolationin interfaceIDatabaseLengthValidationConfiguration- Parameters:
attribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validatedactualPrecision- the actual value's length in digitsprecisionLimit- the exceeded limit, set in the constraint
-
createMessageForScaleViolation
public Message createMessageForScaleViolation(PolicyAttribute attribute, IModelObject modelObject, Class<? extends Number> numericDatatype, int actualScale, int scaleLimit) Description copied from interface:IDatabaseLengthValidationConfigurationCreates a message to indicate that the given attribute's value on the given model object exceeds the configuredNumericConstraint`sscale.- Specified by:
createMessageForScaleViolationin interfaceIDatabaseLengthValidationConfiguration- Parameters:
attribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validatedactualScale- the actual value's amount of decimal placesscaleLimit- the exceeded limit, set in the constraint
-
createMessage
protected Message createMessage(String msgKey, String msgCode, IModelObject modelObject, PolicyAttribute attribute, int actualValue, int maxValue) Returns a message, using the given parameters as follows:.- Parameters:
msgKey- is used to retrieve the message text from theResourceBundlemsgCode- is used forMessage.getCode()modelObject- is used to determine the invalidObjectProperty.getObject()attribute- is used to determine the invalidObjectProperty.getProperty()actualValue- the invalid valuemaxValue- the limit that was exceeded- Returns:
- a message, using the given parameters as follows:
-
addMarker
Adds thegetTechnicalConstraintViolationMarker()to the givenMessage.Builder.- Parameters:
messageBuilder- a message builder, usually used insidecreateMessage(String, String, IModelObject, PolicyAttribute, int, int)
-