RiskyAccount流程如下:
如上,主流程Start节点为Script Task,运行时执行如下Java代码:
System.out.println("Mainprocess - Start, " + "Process ID: " + kcontext.getProcessInstance().getId()); RiskyAccounts account = (RiskyAccounts) kcontext.getKnowledgeRuntime().getGlobal("risky"); System.out.println("Current risky account: "+ account); Account acc = new Account(-20, "Kobe Bryant"); account.add(acc); System.out.println("Add " + acc + " to risky acount list");
System.out.println("Current risky account: "+kcontext.getKnowledgeRuntime().getGlobal("risky"));
我们使用drools规则判断账户是否为危险账户,subprocess-enoughMoney.drl内容如下:
package org.jbpm.quickstarts import org.jbpm.quickstarts.subprocess.Account import org.jbpm.quickstarts.subprocess.RiskyAccounts global RiskyAccounts risky; rule "enoughMoney" when $account : Account( money < 0 ) then System.out.println( "Not enough money on the account!"); risky.add($account); end
package org.jbpm.quickstarts.subprocess; import org.drools.runtime.StatefulKnowledgeSession; import org.jbpm.quickstarts.QuickStartBase; public class SubProcessStart extends QuickStartBase{ public void test() { StatefulKnowledgeSession ksession = createKnowledgeSessionWithDrl("quickstarts/subprocess-enoughMoney.drl", "quickstarts/subprocess-main.bpmn", "quickstarts/subprocess-sub.bpmn"); // Set the Global variable RiskyAccounts risky = new RiskyAccounts(); ksession.setGlobal( "risky", risky ); // Fire the enoughMoney rule ksession.insert(new Account(-10, "Kylin Soong")); ksession.fireAllRules(); // Start the Main Process ksession.startProcess("org.jbpm.quickstarts.subprocess-main"); } public static void main(String[] args) { new SubProcessStart().test(); } }
Current risky account: [money=-10, name=Kylin Soong] Add [money=-20, name=Kobe Bryant] to risky acount list Subprocess - Start, Process ID: 2 Current risky account: [money=-10, name=Kylin Soong] [money=-20, name=Kobe Bryant] Subprocess - Done, Process ID: 2 Mainprocess - Done, Process ID: 1