Category: Modules
Subcategory: Import/Export


New validation approach by creating and reusing Attribute Validations per Entity. By combining individual Attribute Validations into ValidationProcesses you create all your application validations in a structured, flexible and reusable way.


Validate: a structured, reusable approach to validations in Mendix

The Validate module provides a non-persistent Validation entity that is to be associated with each entity that is to be validated.
Storing validations on an object into associated non-persistent Validation objects gives you flexibility to handle and show validations in the way you choose.

The approach is to break validations down to Attribute level per Entity. By creating Attribute Validation microflows for each Entity, you’ll get a clear overview of all validations in your application.
By combining individual Attribute Validations into static or dynamic ValidationProcesses you create all your application validations in a structured, flexible and reusable way.
ValidationProcesses are used in pages (eg. Save), in create/update microflows (eg. imports) or just in jobs to check the data quality of your application regularly.
It is recommended to store all Entity_Attribute validations and static ValidationProcesses of a module in a Validations folder with subfolders per Entity. Like this maintaining and reusing validations of a module will be clear and easy.

Created with Mendix 9.6.4.
Depends on CommunityCommons module for dynamically starting microflows for dynamic ValidationProcesses
So please install that first when you do not have it installed already.

How to configure:
Simply download Validate module package into your application

How to use:
Associate the entity you want to validate with Validate.Validation entity
Then start creating your attibute  and process validation microflows per entity following the microflow templates documented below.
Please be aware that following the microflow templates is essential for the approach to work!
Per entity create SAVE microflow that validates the entity object and gives feedback before actual commit. 
On Save: call this SAVE microflow!

It is recommended to store all validations of a module in a Validations folder with subfolder per entity.
Like this maintaining and reusing validations will be clear and easy.
Each Validations\ subfolder holds:
- Attribute validation microflow(s) per validated attribute
- Entity ValidationProcess microflow(s) per entity process

How to use dynamic ValidationProcesses:
Having created all entity attribute validations you will have a pool of validations that you can use to check the quality of the data in your application (per entity).
To check data quality of an entity simply create a microflow Sub_RUNAttributeValidation_EntityName (in the involved module)  that loops over all objects of the entity that you want to validate. 
Hint: For performance it's best to only consider all objects changed since last validation rundate.
Once you have created the Sub_RUNAttributeValidation_EntityName microflow you can hit link on the ValidationProcess page to have all entity validations available on the page. There you can run them manually when needed.
To monitor data quality you can set the ScheduleInterval of each entity validation process to schedule it regularly.
Note: the scheduling itself is not part of this Validate module

Validation Microflow Templates

Attribute Validations
An attribute validation microflow must be named as
Val_EntityName_AttibuteName_Description (short free text)
Or for association
Val_EntityName_Associated EntityName (or part)_Description (short free text)

An attribute validation microflow ideally starts with the same 3 activities always before doing the actual checking. AttributeName should be set to the name of the attribute. Message should be set to the default message.
Java module deleteValidationAttribute must be called to clear any existing validation for the attribute, so repeating validation will only give one (last, current) validation result. It needs  entityObject and AttributeName as parameters and returns EntityName.
When checking finds irregularities the validation microflow must create a Validation associated to the entityObject and containing ValidationMessage, AttributeName and EntityName.

A validation microflow returns the ValidationMessage or empty string in case all is fine
So an attribute validation microflow should look like the sample attribute validation screenshot.

Validation Processes
An validation process microflow must be named as
Val_Process_EntityName_Description (short free text)

A validation process microflow clears all existing validations associated with the entity object, calls all relevant attribute validation microflows and returns a string with all resulting ValidationMessages (concatenated with ‘|’) associated with the entity object.
So an entity validation process microflow should look like the sample validation process screenshot.

Many entity types have only 1 validation process, but please be aware there can be more than 1 validation process microflow per entity type as actions (like New, Edit or Delete) can require different validations.  
Java modules deleteValidations and getValidation need entityObject as parameter.

SAVE microflows
On custom Save (also eg. Add or Delete) entity action of the entity object the relevant entity process validation microflow is called and the resulting validations are checked. On validations raised the validation messages are shown on page via generic giveFeedback Java module. Only when no validation is raised the changes are committed to the entity object. 

So an entity action with validations should look like the sample save microflow screenshot.

Java module giveFeedback needs entityObject as parameter. This Java module provides the  ValidationFeedback for all validations associated with the entityObject.


Version: 1.0.1
Framework Version: 9.6.4
Release Notes: 1.0.1 Added ValidationProcess.ScheduleInterval
Version: 1.0.0
Framework Version: 9.6.4
Release Notes: First Release