DroolsStep - bluesoft-rnd/aperte-workflow-core GitHub Wiki

This step implementation is part of Drools Step plugin. It provides means to invoke a predefined Drools rule. During rule evaluation process instance object and all of it's attributes are available as rule facts. This not only provides an easy way to read process information, but also allows rules to set new attributes, if something more than just a single rule result is required. The actual rule result is always stored inside result process variable.

Parameters

Parameter name Type Required Default value Description
ruleUrl String True - Resource path of the drools rule .drl source file. If the path is not absolute, it is going to be prepended with drools.rules.baseurl setting from pt_setting table.

Example

This example shows how to define a new Drools rule and use it as jBPM automatic step with DroolsStep. This simple rule shown below, provides a decision mechanism for processing monetary transactions. After evaluating the estimatedCost process attribute the result value can be set to AUTO, GROUP or MANUAL string literal. In two latter casses a new process attribute is going to be set.

package org.aperteworkflow.drools.rule;

import java.util.Map;
import java.lang.Double;
import pl.net.bluesoft.rnd.processtool.model.ProcessInstance;
import pl.net.bluesoft.rnd.processtool.model.ProcessInstanceSimpleAttribute;

global Map result;

rule 'below 5000'
dialect 'mvel'
when
	$pi : ProcessInstance()
	$inAttr : ProcessInstanceSimpleAttribute(key=="estimatedCost", eval(Double.parseDouble(value) <= 5000.0))
then
    result.put("value", "AUTO");
end

rule 'between 5000 and 10000'
dialect 'mvel'
when
	$pi : ProcessInstance()
	$inAttr : ProcessInstanceSimpleAttribute(key=="estimatedCost",
	                    eval(Double.parseDouble(value) > 5000.0 && Double.parseDouble(value) <= 10000.0))
then
    result.put("value", "GROUP");

    ProcessInstanceSimpleAttribute attr = new ProcessInstanceSimpleAttribute();
    attr.setKey("financialAcceptanceGroup");
    attr.setBpmVariableName("financialAcceptanceGroup");
    attr.setValue("GROUP_ACCEPT_QUEUE");
    $pi.addAttribute(attr);
end

rule 'above 10000'
dialect 'mvel'
when
	$pi : ProcessInstance()
	$inAttr : ProcessInstanceSimpleAttribute(key=="estimatedCost", eval(Double.parseDouble(value) > 10000.0))
then
    result.put("value", "MANUAL");

    ProcessInstanceSimpleAttribute attr = new ProcessInstanceSimpleAttribute();
    attr.setKey("financialAcceptanceGroup");
    attr.setBpmVariableName("financialAcceptanceGroup");
    attr.setValue("MANUAL_ACCEPT_QUEUE");
    $pi.addAttribute(attr);
end
<java name="RULES_DECIDE_ACC" g="232,185,221,52"
          class="pl.net.bluesoft.rnd.pt.ext.jbpm.JbpmStepAction"
          method="invoke"
          var="result"
          auto-wire="true"
          cache="false">
    <field name="stepName">
        <string value="DroolsStep"/>
    </field>
    <field name="params">
        <map>
            <entry>
                <key><string value="ruleUrl"/></key>
                <value><string value="decideAcc.drl"/></value>
            </entry>
        </map>
    </field>
    <transition name="to exclusive1" to="exclusive1" g="20,-14"/>
</java>
⚠️ **GitHub.com Fallback** ⚠️