JBoss 系列三十八:jBPM5示例之 Reusable Sub-Process

jBPM5中的Reusable Sub-Process是在主流程里面执行另为一个流程(子流程),当流程执行到Reusable Sub-Process节点时jBPM5流程执行引擎根据提供的流程(子流程)ID,Reusable Sub-Process示例流程如下(主流程和子流程):

JBoss 系列三十八:jBPM5示例之 Reusable Sub-Process_第1张图片

主流程

JBoss 系列三十八:jBPM5示例之 Reusable Sub-Process_第2张图片

子流程

Reusable Sub-Process示例流程运行时传入三条字符串message 1,message 2和message 3,在流程运行时主流程的Format tag节点中生成一个tag,在子流程Apply Tag中将生成的tsg添加到每一条消息的末尾,流程运行结束输出三条消息确认设定tag情况。主流程的Format tag节点为Service Task节点,运行时执行的Java代码如下:

System.out.println("Parent-process id = "+kcontext.getProcessInstance().getId());
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("mm-dd-yyyy");
kcontext.setVariable("tag",  sdf.format(new java.util.Date(System.currentTimeMillis())));

子流程Apply Tag节点为Service Task节点,运行时执行的Java代码如下:

System.out.println("Child-process id = "+kcontext.getProcessInstance().getId());
java.util.List<String> taggedMessages = new java.util.ArrayList<String>();
for (Object message : internalMessages){
    taggedMessages.add(((String)message)+" - "+internalTag);    
}
kcontext.setVariable("internalMessages",taggedMessages);

  • Reusable Sub-Process示例流程运行代码:https://github.com/kylinsoong/.../ReusableSubProcessStart.java
  • Reusable Sub-Process示例流程:https://github.com/kylinsoong/.../reusableSubProcess-Parent.bpmn, https://github.com/kylinsoong/.../reusableSubProcess-Child.bpmn

运行org.jbpm.quickstarts.subprocess.ReusableSubProcessStart将会运行Reusable Sub-Process示例流程,ReusableSubProcessStart代码如下:

package org.jbpm.quickstarts.subprocess;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkflowProcessInstance;
import org.jbpm.quickstarts.QuickStartBase;

public class ReusableSubProcessStart extends QuickStartBase {

	public static void main(String[] args) {
		new ReusableSubProcessStart().test();
	}

	public void test() {
		StatefulKnowledgeSession ksession = createKnowledgeSession("quickstarts/reusableSubProcess-Parent.bpmn", "quickstarts/reusableSubProcess-Child.bpmn");
		List<String> messages = new ArrayList<String>();
        messages.add("message 1");
        messages.add("message 2");
        messages.add("message 3");
        
        Map<String,Object> parameters = new HashMap<String, Object>();
        parameters.put("messages", messages); 
        
        //Start the process using its id
        ProcessInstance process = ksession.startProcess("org.jbpm.quickstarts.reusablesubprocessparent",parameters);
        messages = (List<String>) ((WorkflowProcessInstance)process).getVariable("messages");
        for (String message : messages) {
            System.out.println("Message = "+message);
        }
        ksession.dispose();
	}

}

Reusable Sub-Process示例流程运行输出结果如下:

Parent-process id = 1
Child-process id = 2
Message = message 1 - 01-31-2013
Message = message 2 - 01-31-2013
Message = message 3 - 01-31-2013

如上01-31-2013为设定的tag。

你可能感兴趣的:(jboss,jbpm,BPM,JBPM5,Reusable,Sub-Process)