Rules. We have known this word since childhood. First, parents teach us how to do the right thing, then we come to school, where teachers dictate their own rules. At the university, we are again faced with the rules that teachers and the dean's office set for us. As we grow up, we begin to follow the laws that are developed by the state. What do all these rules have in common? The fact that they have been verified over the years, decades, and some even generations. Imagine what our life would be like if the rules were changed often: every week or every day!
, Mediascope, : , . . -. , , .
?
, . ( ) - . BRMS Business Rule Management System. ,
- , -. , - , - .
, , «», . . : , , , , . , !
BRMS . : IBM, Red Hat, Agiloft, SAS Bosch. β , . JBoss Drools. , , , , - DRL, Excel-. UI- . , UI Excel-.
- ?
- , . , , , . .
, (gender). (SEX). , gender = male, «» 1. 2. DRL :
rule "Rule 1 Example 1"
when
$s: Respondent($s.gender == "male")
then
$s.addResult("SEX", "1");
end
rule "Rule 2 Example 2"
when
$s: Respondent($s.gender == "female")
then
$s.addResult("SEX", "2");
end
, , Gherkin. , ( when) , ( then). Drools Left Hand Side ( LHS), - Right Hand Side ( RHS). : Respondent. fact, Drools, . gender result. , , framework . $.
Excel-:
?
, , , , . , Drools , Miscrosoft Excel OpenOffice, CSV. DRL-.
: . RuleSet, β RuleTable. , .
DRL- . - . . :
RuleSet β DRL.
Import β , Java-, , , java.lang.Math
Functions β , RuleSetβ. DRL-.
, RuleTable, , , Drools DRL-. . nameforRuleTable.
:
NAME β . .
DESCRIPTION β . . , .
CONDITION β Left Hand Side , ACTION. .
ACTION β , . addResult, Map . . ACTION Java-, . .
, CONDITION ACTION .
, $s Respondent. , , , Import. CONDITION , . CONDITION-: , Import.
, , CONDITION ACTION, . , . . (Text-Parameter-Result ). . /, , Drools . .
?
, , . .
, Respondent. β , . (, , ). , , Drools, Respondent. , Map<String, String> result, . , Respondent :
public class Respondent {
public int id;
public String gender;
public Boolean isActive;
public Integer age;
public List<String> pets;
public String city;
public List<String> devices;
public Map<String, String> properties;
public Car car;
public MobileBrand mobileBrand;
public Household household;
public Map<String, String> result = new HashMap<>();
public void addResult(String key, String value) {
result.put(key, value);
}
// getters, setters, constructor
}
, , . , , ? isActive. true β , false β .
, : . , , , . Respondent. DRL:
rule "name_for_RuleTable_20"
when
$s: Respondent(isActive == true, gender == "male")
then
$s.addResult("SEX", "M");
end
rule "name_for_RuleTable_21"
when
$s: Respondent(isActive == true, gender == "female")
then
$s.addResult("SEX", "F");
end
$param - . isActive == $param isActive == true. . Drools , . , gender.
. :
, - 17 18 . , .
, β . , . , , PHONE_SALES_PER 2019 . , $param . , MobileBrand Import .
, . , ACTION $param, . . in:
: SAMSUNG APPLE, PREMIUM. , HUAWEI XIAOMI, NOT_PREMIUM. ( , :) ) , .
, ? contains. java.util.Collection. Respondent pets. , . , , . Β« Β» β , $param .
: forall(<>){<>}. . , . , , . . , , , param. , β ($s). , , Drools , - (city devices), CONDITION .
, β . size:
- , , . Β«-Β». Drools :
, . . , Car c : , , . , , . , -, . from:
, . , , Car, Respondent, Map<String, String> properties . POWER. Drools getValue. Functions :
:
, . : , PlayStation. , Household Respondent TVDevices PlayStation. :
?
. ACTION? , Java. . , , ACTION .
Drools, :
set β , Drools ;
update β , set;
modify β , , ;
insert β .
modify.
RuleTable , - 99 0. , $r, Respondentβa false. RuleTable isActive REJECTED TRUE.
CONDITION. , . , , . . Drools . , , , .
Drools (https://github.com/sxexesx/drools-decision-table).
Thanks for attention! I hope this article will be useful for those who want to dive into the wonderful world of BRMS!