Skip to content

Validation Engine

vbergeron edited this page Mar 11, 2019 · 4 revisions


See latest version in maven central.


<!-- The dependency for doov-core -->
<!-- The dependency on your generated DSL -->


dependencies {
  compile project(':doov-sample-generated')

Sample project

This documentation is based on the sample project in dOOv. You can replace the package name io.doov.sample by your package name as com.example.myapp and classes name Sample with MyApp.


Execute rule

To use the dOOv validation engine, you just need to pass your instanciated model to the rule.

package io.dooov.sample.validation;

import static io.doov.sample.validation.SampleRules.RULE_EMAIL;

public class Execute {
    public static void main(String... args) {
        Account account = new Account();

        Model model = new Model();

        System.out.println("Validation model " + model + 
                           " with rule " +;
        Result result = RULE_EMAIL.executeOn(model);
        System.out.println("> " + result.isTrue());

        if (result.isFalse()) {
            System.out.println("Failure cause is: " + result.getFailureCause());


Syntax tree

The rules provides an AST that can be printed as a human readable format with the Readable#readable method that is available on any DSL object. By default the output is from AstLineVisitor that outputs the string in plain text.

> When user email matches '\w+[@]\w+\.com', validate with empty message

You can print the syntax tree by calling (or creating your own) MetadataVisitor, such as AstHtmlVisitor. The method to call is ValidationRule#accept(MetadataVisitor). For example, the HTML renderer will output a tree of tokenized conditions.

<div class='dsl-validation-rule'>
<li><span class='dsl-token-rule'>Rule</span>
  <li><span class='dsl-token-when'>When</span></li>
<li>validate with message <span class='dsl-validation-message'>empty</span></li></ul>

Performance and evaluation

Predicate evaluation in dOOv is very similar to Java's lambda predicate evaluation. It differs from bare metal or / and since there is no operator precedence in dOOv, only tree evaluation order precedence. In general, you can consider:

  • predicates evaluates dept first, left to right (that means multiple chained and / or predicates might not evaluate the same way as bare metal Java)
  • predicates short-circuits the same way as Java logical operators and streams do (but that can be deactivated)

If you want to deactivate short-circuiting, you can do it with ValidationRule#withShortCircuit and use false (it is true by default). It will impact performance, but it is useful if you want complete runtime metrics ("what nodes trigger on my production server", etc.).




See Testing Rules

You can’t perform that action at this time.