Ready to go in 3 min.

Prerequisites

You need Java version 8 or higher. Here you can download the corresponding JRE 1.8.

1. Installation

You need openvalidation.jar to generate code. openvalidation.jar is a simple Java command line interface. You can download the openvalidation.jar here:

Best you create a new directory under your personal Temp folder and download the openvalidation.jar into this folder:

cd %temp%
mkdir openvalidation
cd openvalidation
curl http://download.openvalidation.io/openvalidation.jar

2. Create a rule

Ok, now you are ready to start and can program your first validation rule in openVALIDATION. Create a file called rules.ov and add the following content:

rules.ov
  IF the message IS Hello
THEN hello openVALIDATION!

This rule is formatted so that it best illustrates the keywords and syntax of the openVALIDATION language. You could also just write If the message is Hello then hello openVALIDATION! and it would work just the same.

In addition to the actual rule, you also need a schema. The schema defines the data structure of the data set to be validated. You can use a simple JSON object from which a JSON schema is automatically derived. Our schema consists only of a text field called "Message".

Message : Text

3. Generate code

Since our validation rule and the corresponding schema are already fixed, we can now generate the corresponding code.


java -jar openvalidation.jar /
     -r rules.ov /
     -s "{Message : \"Text\"}" /
     -l javascript /
     -o myRules.js /
     -c en /
     -f

Congratulations! You have just created your first validation rule in JavaScript. This can be found in the file myRules.js. This is the result:

...

huml.appendRule("",
     ["Message"],
     "Hello openVALIDATION!",
     function(model) { return  huml.EQUALS(model.Message, "Hello");},
     false
);

...

4. Rules integration

Now we'd like to see if our rule works. We create a file called test.html and add the following code:

test.html
<html>
  <body>

    <input id="message" />
    <div id="error"></div>

    <script src="myRules.js"></script>
    <script type="text/javascript">

      window.addEventListener('load', (event) => {

        var validator = new HUMLValidator();

        document.getElementById('message').onkeyup = function(e){
            var result = validator.validate({Message:e.target.value});

            if (result.hasErrors)
              document.getElementById('error').textContent = result.errors[0].error;
            else
              document.getElementById('error').textContent = "";
        };
      });

    </script>
  </body>
</html>

We call the test.html in the browser and type "Hello" into the input field:

As expected, when entering the value "Hello", our error message appears.

5. No-Code Development

You can now extend the rules by filling the file rules.ov with additional rules and then doing the generation process again using openVALIDATION CLI. Just follow steps 2 to 4.

The nice thing about it is that the file rules.ov can now be edited by a domain expert without having to be familiar with the technology! As soon as he has changed the rules, openVALIDATION can automatically generate program code from them. This is what we call No-Code Development.

If you would like to try out another detailed implementation example, then have a look at the Integration section.

Last updated