Information Technology Reference
In-Depth Information
Rule engines
Business processes are good to express a sequence of activities in a visually simple way.
However, sometimes, specially when we want to express complex business logic for spe-
cific decisions, writing business process can become too complex and cryptic; also, de-
pending on the number of decisions that are taken, they could make our processes look like
a labyrinth. To implement complex business logic inside activities or the business logic sur-
rounding all the processes, we can use a declarative expression language that writes those
decisions as business rules.
The Drools rule engine, which will be introduced in detail in Chapter 9 , Integration with
Other Knowledge Definitions , allows us to define business rules using the Drools Rule
Language ( DRL ). DRL is an expressive declarative language to define business situations
and a way to interact with them. There are mappings that can be created by transforming
from natural language to DRL in order to make them user friendly to read and write by
business analysts.
A DRL-based business rule looks like the following:
rule "Driver License only for apt applicants over 18 y.o."
when
$a: Applicant(age > 18)
$md: MedicalRevision(
applicant == $a,
status == "Approved")
then
startProcess("driverLicenceProcess", $a);
end
Rules are described using two main sections: one for finding the conditions and the other
for the consequences that will follow when those conditions are met. The first is called a
conditional section, Left-Hand Side ( LHS ), or simply "the when part". It will wait for all
the conditions to be true to activate the rule. In the case of the previously defined rule, it
will wait for an Applicant object to exist with an age over eighteen. When found, it will
search for a MedicalRevision object related to that applicant that has been approved.
Once both are found, it goes to the then part of the rule—the consequence section or Right-
Hand Side ( RHS ) of the rule—to execute the actions associated with that condition. In this
case, it will call a previously defined function to start a specific process for that applicant.
Search WWH ::




Custom Search