I'm new to Drools (5.0.1) and attempted to create a simple workflow
example using a WorkItem and can't seem to figure out how to have
parameters passed to the WorkItem. I must be missing something
obvious (not understanding variable scopes maybe?) but just can't see
it. Below is the code I'm using:
<?xml version="1.0" encoding="UTF-8"?>
<process
xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process
drools-processes-5.0.xsd"
type="RuleFlow" name="ruleflow"
id="com.sample.ruleflow"
package-name="com.sample" >
<header>
</header>
<nodes>
<start id="1" name="Start" x="16" y="16"
>
</start>
<workItem id="2" name="Test" x="435" y="97"
width="80" height="40" >
<work name="Test" >
</work>
<mapping type="in" from="p1" to="p1" />
</workItem>
<end id="3" name="End" x="240" y="16"
/>
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="3" />
</connections>
</process>
public class Test {
public static void main( String[] args ) {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(
ResourceFactory.newClassPathResource("process.rf"), ResourceType.DRF
);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.getWorkItemManager().registerWorkItemHandler("Test",
new TestWorkItemHandler());
Map<String, Object> params = new HashMap<String, Object>();
params.put("p1", "param1");
ksession.startProcess("com.sample.ruleflow", params);
}
}
public class TestWorkItemHandler implements WorkItemHandler {
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println(workItem.getParameters());
manager.completeWorkItem(workItem.getId(), null);
}
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
}
and the output:
Could not find variable scope for variable p1
when trying to execute Work Item Test
Continuing without setting parameter.
{}
Thanks in advance,
-geoff