-
Notifications
You must be signed in to change notification settings - Fork 17
Rules API
For a given field of type DefaultFieldInfo
, it will delegate the
corresponding condition of type DefaultCondition
. For example, when you call
DefaultFieldInfo#isNull
, it delegate the rest of the DSL to
DefaultCondition#isNull
.
DefaultCondition
(javadoc)
Rules that are available on all fields such as eq
, isNull
, etc.
// The user last name is not null
DOOV.when(userLastName.isNotNull()).validate();
BooleanCondition
(javadoc)
Rules that are available on Boolean
fields such as isTrue
, isFalse
, etc.
// The account accept emails
DOOV.when(accountAcceptEmail.isTrue()).validate();
NumericCondition
(javadoc)
Rules that are available on Integer
, Double
, etc. fields such as
greaterThan
, lesserThan
, etc.
// The user ID is greater than 0
DOOV.when(userId.greaterThan(0)).validate();
IterableCondition
(javadoc)
Rules that are avaible on Collection
fields such as contains
, etc.
// The account preferences mail list contains 3 elements
DOOV.when(accountPreferencesMail.hasSize(3)).validate();
TemporalCondition
(javadoc)
Rules that are available on LocalDate
, LocalTime
fields such as after
,
before
, etc.
// The account creation date is less than 6 months ago
DOOV.when(accountCreationDate.monthsBetween(LocalDateSuppliers.today()).lesserThan(6)).validate();
StringCondition
(javadoc)
Rules that are avaible on String
fields such as matches
, length
, etc.
// The account email mathches email ending in .com
DOOV.when(accountEmail.matches("\\w+@\\w+[.]com")).validate();
Rules that makes composing rules possible.
LogicalBinaryCondition
(javadoc):
Rules that are available on any Condition
such as and
, or
, etc. The order
of declaration is important: the logical rules will get executed from left to
right. There is no logical operator precedence in dOOv!
// The user name is complete
DOOV.when(userFirstName.isNotNull()
.or(userLastName.isNotNull())
.validate();
LogicalNaryCondition
(javadoc):
Rules that are applicable to a list of Condition
such as count
, matchAll
,
etc. They are available on the DOOV
class.
You can use this syntax as you would use logical binary condition, since
matchAll
is like and
(and matchAny
is like or
), but takes a list of
conditions instead of two elements. It also makes possible to do logical
precedence, by giving you the control over the resulting syntax tree.
// The account is valid either if both first name AND last name is not
// null, OR the email is not null
DOOV.when(DOOV.matchAny(DOOV.matchAll(userFirstName.isNotNull(),
userLastName.isNotNull()),
accountEmail.isNotNull()))
.validate();
LogicalUnaryCondition
(javadoc):
Rules that are applicable to one Condition
such as negate
, etc. Note that
some are already available on DefaultCondition
. They are available on the
DOOV
class.
// Bob cannot have an account
DOOV.when(DOOV.negate(userFirstName.eq("bob"))).validate();