Creating process dynamically using Fluent API
sanket.mohile Dec 6, 2011 11:17 AMHi,
I want to create a process dynamically using Fluent API.
I tried this -
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("com.sample.process");
factory
// Header
.name("HelloWorldProcess")
.version("1.0")
.packageName("defaultPackage")
// Nodes
.startNode(1)
.name("Start")
.done()
.actionNode(2)
.name("Action")
.action("java", "System.out.println(\"Hello World\");")
.done().
endNode(3)
.name("End")
.done()
// Connections
.connection(1, 2)
.connection(2, 3);
But when I start the process, I get an exception
java.lang.RuntimeException: unable to execute Action
at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:49)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)
at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)
at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:302)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:154)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:124)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:116)
at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1090)
at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:301)
at com.sample.Example1.main(Example1.java:57)
Caused by: java.lang.NullPointerException
at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:47)
... 15 more
If I remove the actionNode, the code runs successfully.
Similarly in case of a human task node, when I use a .onEntryAction("java", "java.util.Map contentParam = new java.util.HashMap();"); it crashes.
Seems some problem with the "java" dialect. Just not able to figure that out...
Please help.
Also would be glad if someone could provide a sample code for creating dynamic process with fluent API..
Thanks,
Sanket.