Information Technology Reference
In-Depth Information
ruleflow-group "ad-hoc-sub"
when
wf: WorkflowProcessInstance($nodes: nodeInstances)
dn: DynamicNodeInstance() from $nodes
eval(wf.getVariable("processVar1") == null)
then
System.out.println(drools.getRule().getName());
KieRuntime kr = kcontext.getKnowledgeRuntime();
Map params = new HashMap();
params.put("inVar1", wf.getVariable("processVar1"));
params.put("TaskName", "decide what's next");
DynamicUtils.addDynamicWorkItem(dn, kr, "Human Task",
params);
end
In the preceding rule, we are looking for a process instance, which has an active dynamic
node (which is jBPM6's internal representation for an ad hoc process) and has no process
variable assigned with the name processVar1 . This is done by checking for the
WorkflowProcessInstance objects we might have in the rule engine memory, and
checking whether its nodeInstances attribute (which we will assign to a $nodes
variable) contains a DynamicNodeInstance object. Finally, we evaluate whether a
process variable is not yet present in the process instance. When those conditions are met,
we start a dynamic Human task (with a WorkItemHandler registered in the KIE ses-
sion with the Human Task key). It is a responsibility of the "then" part of this rule to
provide all the information to the work item generated, including all parameters and refer-
ences to the KIE session and the node.
One more important step to know is which is the best way to start a process or invoke a
process signal inside a rule consequence. To do so, we need to understand a specific pre-
defined variable in the rules consequence called kcontext . This variable will have a
reference to the KIE session so that we can use it to invoke our process executions. Using
this variable, we can also call all the process related methods in the KIE session, such as
signalEvent , getProcessInstance , abortProcessInstance , and so on.
Runtime configurations to activate rules
Even though rules and processes share the same runtime, they have very different memory
scopes. The process instance memory (called process variables) and the rule memory
(called working memory) do not share information unless it is specified that they should
Search WWH ::




Custom Search