Skip to main content
Skip table of contents

Rules

Definition

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. The Choices 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. The ValidationResult 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

Library

LibraryInitializationOutcome run(final Context context);

Methods and classes meant to be used by other rules of any type (including Libraries), but of the same or compatible category

Rules are also considered usable for a certain category of usage, which dictates what information is available to the Rule upon execution.

These categories are:

  • Attribute: The rule is executed in the context of a single attribute, whose properties and value are made available

  • Object: The rule is executed in the context of an IM object that is being manipulated

  • Business policy: The rule is executed in the context of a trigger

  • Feature: The Rule is executed in the context of an feature operation

  • Scope: The rule is an inline groovy snippet in a scope

  • Access code policy: The rule is executed in the context of an access code policy execution

Choices rules

Choices rules are used to create a drop-down list of choices which will be displayed on the user portal (only if the value type = STRING).

The choice rule is combined with the validation rule (if there is one). The user will be block if he tries to set an unauthorized value.

The attribute will have to be configured via a Select Edit Widget in the feature (if not the drop-down list will not be available).

When configuring choices rules there are three possibilities :

How

UI Configuration

Example

1

Attribute

Other

2

By reference table : To use value of a Reference Table.

Before defining the choice rule, you must create a Reference Table.

(tick)

(error)

  • Reference Table Id: put the id of the Reference Table.

  • Column index: allows to define the values of which column will be displayed on user portal.

  • I18n prefix: ui.model.attributes."id of the attribute".values."value".label

The i18n key is used to display values in the choice list regardless of the language of the user portal.

3

By script groovy (list) : To list authorized values.

(tick)

(tick)

GROOVY
return ChoicesRuleResult.of("ui.model.attributes.scopedright.values", 
["adm.manager", "adm.directory", "adm.owner", "adm.boolean", "adm.string",
"adm.float", "adm.role-owner"]) 
GROOVY
return ChoicesRuleResult.ofFixed("my.i18n.key.label", 
[value1: [label_fr: "texte français", label_en: "english text", boolean_value: true, number_value: 1, instant_value: Instant.now()], 
value2: [label_fr: "texte2 français", label_en: "english text2", boolean_value: true, number_value: 2, instant_value: Instant.now()]
]) 

(info) With the 2nd syntax, the following parameters will be available in the translations

  • value => automatically created and valued at the value of the choice

  • All provided i18n params (label_fr, label_en, number_value….)

  • All provided i18n params prefixed by __has_ (automatically created and valued at true)

Compute rules

Compute rules are used to calculate the value each time the Object is modified. At each modification, the data is recorded in database.

When configuring Compute Rules there are two possibilities :

How

UI Configuration

Example

1

Attribute

Other

2

By Random Identifier Generator

(tick)

(error)

Not relevant on a Compute rule.

3

By groovy script: 
Used to combine several Attributes' values for another Attribute.

(tick)

(tick)

GROOVY
String login  = OBJECT.id
String firstName = OBJECT.firstName
String lastName = OBJECT.lastName
String fullName = ""
if (!lastName) {
    fullName = firstName + " " + lastName + " - " + login
}
return fullName.trim().toUpperCase()

In this case, at the modification, the "fullName" Attribute value is calculated with 3 others Attributes: "firstName", "lastName" and "id".

Normalization rules

Normalization rules are used to normalize data and therefore to modify the entered value of the Attribute before storing it in the database.

Several normalization rules can be configured for the same Attribute (by clicking on the "+" button).

When configuring normalization rules there are four possibilities :

How

UI Configuration

Example

1

Attribute

Other

2

Capitalization  : The value of the first letter will be in uppercase and the rest in lowercase.

The user can choose the word separator characters.
The "Full capitalization" checkbox allows the rule to be applied to the entire value chain.

(tick)

(error)

XML
<normalizeRules>
    <normalizeRule class="normalizeCapitalization">
      <config xsi:type="rule:CapitalizationNormalizeConfigurationType">
          <separators> -</separators>
          <full>false</full>
      </config>
    </normalizeRule>
</normalizeRules>
3

Lowercase : The value is stored in lowercase.

(tick)

(error)

XML
<normalizeRules>
  <normalizeRule class="normalizeLowercase"/>
</normalizeRules>
4

Uppercase : The value is stored in uppercase.

(tick)

(error)

XML
  <normalizeRules>
      <normalizeRule class="normalizeUppercase"/>
  </normalizeRules>
5

By groovy script: 
To configure more complex rule.

(tick)

(tick)

XML
<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.

(tick)

(tick)

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.

(tick)

(error)

In this case, an idcardrecto is valid if it’s an image in jpeg, gif or png format.

Capture d'écran 2024-02-07 144205.png

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.

(tick)

(error)

In this case, an idcardrecto is valid if it’s size is lower thant 768 ko.

Capture d'écran 2024-02-07 144434-20240207-134433.png

Binary attribute siza validation rule example

5

Email Validation: Allows to restrict the domain part of emails by configuring domains whitelist.

(tick)

(error)

In this case, only emails with explicit ending "ext.mpsa.com", "domain1" or "[172.16.47.45]" are allowed, and emails ending with implicit ending such as "subdomain2.org", "stellantis.domain2.com" or "subdomain3.accenture.com".

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.

(tick)

(error)

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.

(tick)

(error)

XML
<validationRules>
  <validationRule class="validationRegex">
    <config xsi:type="rule:RegexValidationConfigurationType"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <regex>[-'\. @a-zA-Z0-9]+</regex>
      <failureI18n>tenant.ui.attribute.firstName.validation.label</failureI18n>
    </config>
    </validationRule>
  </validationRules>
8

URL Validation: Allows to check if the value of the attribute is an URL.
You must to define one or several URL protocols (http, https...)

(tick)

(error)

XML
<validationRules>
    <validationRule class="validationUrl">
      <config xsi:type="rule:UrlValidationConfigurationType"/>
    </validationRule>
</validationRules>
9

X509 Certificate Validation: Allows to he check if the uuploaded data is a valid X509 Certificate .

(tick)

(error)

XML
<validationRules>
    <validationRule class="validationX509Certificate"/>
</validationRules>

Initialization rules

Initialization rules are used to calculate the value when the Object is created. It's mainly used to set a default value.

When configuring Initialization Rules there are two possibilities :

How

UI Configuration

Example

1

Attribute

Other

2

By Random Identifier Generator: Used to generate a random id from a given regular expression.

(tick)

(error)

In this case, at creation, the "login" will be created according to the regular expression patterns.

3

By groovy script :Used to associate one or more values of existing attributes to the created Object.

(tick)

(tick)

GROOVY
if (OBJECT.type == "Employee" && OBJECT.level == 2){
    return  true
} else {
return false
}

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.

(tick)

(error)

In this case, at creation, the "login" will have the generated Uuid value.

Read Next

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.