Rules

Rules are similar to functions. Their main purpose is to isolate complex decision tree which would otherwise impact the readability of the business logic. These rules can be called in many functions thereby enabling the reusability. The example below outlines the implementation of a simple rule and it's invocation inside a function.

Rule function

The following function checks the value of an input and return an appropriate response code.

naicsCode = v.?naicsCode;

if (naicsCode == "722511") {
  return 0.02;
} else if (naicsCode == "722513") {
  return 0.015;
} else if (naicsCode == "722514") {
  return 0.03;
} else if (naicsCode == "722515") {
  return 0.01;
} else {
  return 0.04;
}

An example invocation of above rule is shown below.

ruleParam = new HashMap();
ruleParam.naicsCode = v.naicsCode;
ruleRes = func.executeRule("Rating", ruleParam);

if (func.isResult(ruleRes) && func.isFailedResult(ruleRes)) {
  return ruleRes;
}