JBPM4学习总结之10——复杂的子流程(sub-process)

父流程还可以根据子流程内部的流程变量而决定父流程的分支走向。

父流程图如下:
JBPM4学习总结之10——复杂的子流程(sub-process)
 咱们先给出父流程的Xml描述如下:

<?xml version="1.0" encoding="UTF-8"?>

<process name="ProcessFather2" xmlns="http://jbpm.org/4.4/jpdl">
	<start name="start1" g="12,134,48,48">
		<transition name="to review" to="review" g="-22,30" />
	</start>
	<sub-process name="review" g="115,132,92,52"
		sub-process-key="ProcessSub2" outcome="#{result}">
		<transition name="ok" to="ok" g="161,63:-56,-22" />
		<transition name="update" to="update" g="-20,-20" />
		<transition name="close" to="close" g="162,267:-56,-22" />
	</sub-process>
	<state name="ok" g="293,38,92,52" />
	<state name="update" g="292,132,92,52" />
	<state name="close" g="296,239,92,52" />
</process>

 子流程如下:

 流程xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<process name="ProcessSub2" xmlns="http://jbpm.org/4.4/jpdl">
   <start name="start1" g="34,119,48,48">
      <transition name="to task1" to="task1" g="-52,-22"/>
   </start>
   <task name="task1" g="139,117,92,52" assignee="liuyan">
      <transition name="to end1" to="end1" g="-50,-22"/>
   </task>
   <end name="end1" g="297,120,48,48"/>
</process>

 测试代码如下:

/**
	 * 开始父流程 传入参数
	 */
	public void test03StartFather() {

		// 开始process流程
		ProcessInstance processInstance = executionService
				.startProcessInstanceByKey("ProcessFather2");

		// 流程实例的ID
		String pid = processInstance.getId();

		System.out.println(pid);// ProcessFather2.20001
	}

	/**
	 * 结束子流程的任务,向父流程传输参数,转移流程
	 */
	public void test04completeTask() {
		List<Task> list = taskService.findPersonalTasks("liuyan");

		for (Task task : list) {
			String taskId = task.getId();

			// 传给父流程的参数
			Map<String, Object> res = new HashMap<String, Object>();
			res.put("result", "ok");

			taskService.setVariables(taskId, res);

			taskService.completeTask(taskId);
		}
	}

	/**
	 * 查找父流程的变量的最终归宿
	 */
	public void test05findFatherRes() {
		// 20001
		ProcessInstance processInstance = executionService
				.findProcessInstanceById("ProcessFather2.20001");

		Set<String> activeActivityNames = processInstance
				.findActiveActivityNames();

		System.out.println(activeActivityNames);
	}

 测试代码中在子流程中set一个子流程变量result,在父流程中,根据这个result决定了走向。

你可能感兴趣的:(xml,jbpm)