A rule is an extension point of the application to implement custom behavior, for example (validation ....).
Rule Types & Categories
There are several rule types supported by Memority , that are listed in the table below:
Type
Signature
Description
Choices
Choices choices(final Context context);
Return a set of choices to choose from. Typically used to populate a select box in the UI. TheChoices expected return type is a static inner class of the com.memority.toolkit.rule.api.ChoicesRule API interface.
Compute
Object compute(final Context context);
Compute a value from the context. The value can be anything (it is up to the caller to safely cast the returned value)
Condition
boolean accept(final Context context);
Decide whether or not a condition is fulfilled (according to the given context), returning a true or false result.
Normalize
Object normalize(Object value, final Context context);
Normalize a given value. The context may be used to perform the normalization, but it is neither mandatory nor common.
Select
<T> T select(List<T> choices, final Context context);
Select a value amongst a list of choices.
Transform
void transform(T context);
Modify the Context, applying a direct modification. Note that modifications are limited to certain values only. There is no return type.
Validate
ValidationResult validate(Object value, final Context context);
Validate the given value, optionally using the context to do so. TheValidationResult expected return type is a static inner class of the com.memority.toolkit.rule.api.ValidationRule API interface.
Action
ActionOutcome run(final Context context);
Custom code to attach to business policies, features and workflows
<normalizeRules>
<normalizeRule>
<script><![CDATA[
OBJECT.firstNameService.toLowerCase().replaceAll(/(^|\P{L})(\p{L})/) {List<String> match ->
def space = match[1] as String
def letter = match[2] as String
return space+letter.capitalize()
}]]></script>
</normalizeRule>
</normalizeRules>
Validation rules
Validation rules are used to validate the data before saving to the database. For example, to prohibit special characters for an Attribute.
When configuring validation rules there are different possibilities :
Validation rules
How to validate the data
UI Configuration
Example
1
Attribute
Other
2
Groovy Script: Allows to configure validation rules by using a Groovy script. It is advisable to define a validation error message.
In this case, a date of birth is valid if it is less than 100 years and more than 10 years.
GROOVY
LocalDate now = LocalDate.now()
if (date.isBefore(now.minusYears(10)) && date.isAfter(now.minusYears(100))) {
return ValidationRuleResult.valid()
}
return ValidationRuleResult.invalid("The birth date is invalid",
"ui.errors.attributes.birthDate.invalid.msg")
3
Binary Attribute Media Types Validation: Allows to checks that the uploaded binary file’s media-type is one of an acceptable value.
In this case, an idcardrecto is valid if it’s an image in jpeg, gif or png format.
Media types validation rule example
4
Binary Attribute Size Limit Validation: Only for binary Attribute. The tested value is valid if the binary Attribute size is lower than the configured one.
In this case, an idcardrecto is valid if it’s size is lower thant 768 ko.
Binary attribute siza validation rule example
5
Email Validation: Allows to restrict the domain part of emails by configuring domains whitelist.
The wildcard (asterisk) stands for an entire subdomain, domain or extension.
Email validation rule exemple
6
Email Validation - Reference Table: Allows to restrict the domain part of emails by configuring a reference table.
Allows to indicate the Reference Table with authorized domains, with the same syntax as for Email Validation.
Email validation rule with reference table example
7
Regex Validation:Allows to define a character string. This validation rule is described using operators, values and variables.
The validation failure i18n key allows to configure a personalized i18n key. This key will be displayed when the user enters an incorrect value of the attribute.
In this case, at the creation, if "type" Attribute is set to "Employee" and "level" attribute is set to "2", then the "badgeAuthorized" attribute will be set to "true".
4
By Uuid Idenfier Genreator : Used to generate a random id based on Uuid.
In this case, at creation, the "login" will have the generated Uuid value.