The rulengine is used to execute logic against data. You can apply very complex logic and also update the data. The rulengine is written in Java and thus can be integrated into your Java program, Java based web site, Java based scripting languages such as groovy and others. It can e.g. also be integrated with Apache Nifi, Hadoop or Kafka. Please check it out.

It is a generic tool and swiss-army knife for applying logic. There are two patterns that are most commonly used:

1) Update-only modeIf you do not want to quality check your data, but update it. The logic of the rules will determine under which conditions the data is updated or not. E.g. based on the content of one field, another field of a record is updated. Or based on a value in one field a lookup/mapping is done and stored in another field. So the main interest here is to update, enhance or complete the data.

2) Quality-check modeYou want to check if the data is according to certain logic/rules. The main focus here is not to update the data, but to check if it is correct. And you may want to separate the correct data from the incorrect data. E.g. if an applicant has a valid drivers license, is above the age of 25 and has a credit card and is not from a certain list of countries, then this data would pass the logic. Otherwise it fails and can be processed futher or the info is e.g. sent to somebody.

Here is how it works: One or multiple rules are composed in a rulegroup. This way you can have rules that pass and rules that fail but the rulegroup as such passes. E.g. if you have two rules: one checks if the age is smaller than 50 and the other checks if the age is greater or equal to 50. The rules are connected using an "or" operator. If we have now a person at the age of 40, the first rule will pass and the other one will fail. But the rulegroup in which both rulesare collected, will pass.

Based on the failed or passed status of a rulegroup you can execute one or multiple actions, which update the data. My previous post shows which actions are available. And based on this status, or the number of rules failed or the number of rulegroups failed you can also make decisions how to futher handle the data.

fter my last two posts you might ask: "What can I do with the ruleengine?".

There are two main components that the ruleengine uses: Rules and Actions.

Rules are based on so called checks. There are a lot of predefined checks available:

CheckIsEqual

CheckIsNotEqual

CheckContains

CheckNotContains

CheckIsBetween

CheckIsNotBetween

CheckIsEmpty

CheckIsNotEmpty

CheckIsEven

CheckIsNotEven

CheckIsGreater

CheckIsGreaterOrEqual

CheckIsSmaller

CheckIsSmallerOrEqual

CheckIsInList

CheckIsNotInList

CheckIsLowerCase

CheckIsUpperCase

CheckMatches

CheckNotMatches

CheckSoundsLike

CheckNotSoundsLike

CheckIsNegativNumber

CheckIsNotNegativeNumber

CheckLength

CheckListHasMember

CheckListNotHasMember

CheckStartsWith

CheckNotStartsWith

CheckEndsWith

CheckNotEndsWith

CheckIsNull

CheckIsNotNull

CheckIsNumeric

CheckIsPrime

CheckIsNotPrime

CheckLevenShteinDistanceIsEqual

CheckLevenShteinDistanceIsGreater

CheckLevenShteinDistanceIsGreaterOrEqual

CheckLevenShteinDistanceIsSmaller

CheckLevenShteinDistanceIsSmallerOrEqual

You can use and combine all these checks to build complex logic. You can connect individual rules with "and" and "or" conditions and group them. And you can connect different groups of rules with "and" and "or" conditions and combine those. So you have total flexibility to construct the logic.

The ruleengine will run the rules against given data and the result will be a "passed" or "failed" status. You can also run group of rules, if another group of rules passed or failed.

Based on this status of the rules you can then decide to implement actions. Actions update or modify the data. Following actions are available:

AddLeadingSpaces

AddLeadingZeros

AppendValue

PrependValue

TrimValue

ConcatenateValue

LowercaseValue

UppercaseValue

ReplaceValue

ReplaceValueFromMappingFile

ReplaceValueFromList

SetValue

SubstringValue

SetTodaysDate

SetLastDayOfMonth

SetFirstDayOfMonth

SetMidDayOfMOnth

AbsoluteValue

Acosinus

Cosinus

Cosinush

Sinus

Sinush

SquareRoot

AddValues

SubstractValues

AddPercentage

SubstractPercentage

DevideValue

MultiplyValues

RoundValue

RandomValue

RemainderValue

AddMinutes

So you can apply actions to one or multiple fields. And of course you can have multiple actions. Actions can run based on if a group of rules passed or failed (or both).

Both rules and actions can be extended. Implementing your own ones is easy and so you can integrate your personal logic and encapsulate it to run with the ruleengine.