Task任务驳回到指定节点

把Task任务驳回到指定节点

public class FlowServiceTest2 {
    ProcessEngine processEngine;
    String jdplPath;
    String pdKey;

    @Before
    public void setUp() throws Exception {
        processEngine = Configuration.getProcessEngine();// 获取流程引擎
        //jdplPath = "F:/workspace/jdome/jbpm_dome/src/main/resource/jpdl/reject.jpdl.xml";
        //pdKey = "reject";
        jdplPath = "F:/workspace/jdome/jbpm_dome/src/main/resource/jpdl/reject3.jpdl.xml";
        pdKey = "reject3";
    }

    /**
     * @description 发布流程 no.1
     */
    @Test
    public void deploy() {
        try {
            RepositoryService repositoryService = processEngine.getRepositoryService();
            File file = new File(jdplPath);
            repositoryService.createDeployment().addResourceFromFile(file).deploy();

        } catch (Exception e) {

            e.printStackTrace();
            throw new RuntimeException();
        }

    }

    /**
     * @description 提交申请 no.2
     */
    @Test
    public void testApply() {
        Map<String, Object> values = new HashMap<String, Object>();
        List<Integer> deptIds = new ArrayList<Integer>();
        deptIds.add(1);
        deptIds.add(2);

        values.put("deptIds", deptIds);
        values.put("deptIdsLenght", deptIds.size());


        ExecutionService executionService = processEngine.getExecutionService();
        executionService.startProcessInstanceByKey(pdKey, values);
    }

    /**
     * @description 完成任务 no.3
     */
    @Test
    public void takeTask() {
        String taskId = "10005";    //直接接查数据库任务表获取

        TaskService taskService = processEngine.getTaskService();
        taskService.completeTask(taskId);
    }

    /**
     * 把任务20001驳回到  task0节点
	http://blog.csdn.net/xxb2008
     */
    @Test
    public void takeTaskForkOut () {

        processEngine.execute(new Command<Object>() {

            @Override
            public Object execute(Environment environment) throws Exception {
                String taskId = "20001";    //直接接查数据库任务表获取
                String activityName = "task0";    //需要驳回到的指定节点名称

                TaskService taskService = environment.get(TaskService.class);
                RepositoryService repositoryService = (RepositoryServiceImpl) environment.get(RepositoryServiceImpl.class);

                TaskImpl task = (TaskImpl) taskService.getTask(taskId);
                ExecutionImpl processInstance = task.getExecution();
                ExecutionImpl execution = processInstance;
                ProcessDefinitionImpl procDefi = (ProcessDefinitionImpl) repositoryService.createProcessDefinitionQuery().
                        processDefinitionId(execution.getProcessDefinitionId()).uniqueResult();

                ActivityImpl activity = execution.getActivity();
                TransitionImpl transition = activity.createOutgoingTransition();
                transition.setSource(activity);
                transition.setDestination(procDefi.getActivity(activityName));
                String transitionName = "" + new Date().getTime(); //随便取个不重复的名字
                transition.setName(transitionName);
                activity.setDefaultOutgoingTransition(transition);

                if (execution.getIsProcessInstance()) { //主实际,不是fork\foreach分支出来的实例
                    task.take("feifei");//指定当前任务人
                    task.complete(transitionName);
                }else{  //fork\foreach分支出来的实例,往外驳出
                    processInstance = execution.getProcessInstance();
                    processInstance.setState(ExecutionImpl.STATE_ACTIVE_ROOT);

                    processInstance.setTransition(transition);
                    processInstance.setActivity(activity);
                    processInstance.take(transition);

                    Collection<ExecutionImpl> executions = processInstance.getExecutions();
                    ExecutionImpl[] executionArray = new ExecutionImpl[executions.size()];
                    executions.toArray(executionArray);
                    for (ExecutionImpl e : executionArray) {
                        e.end();
                    }
                }
                return null;
            }
        });
    }


}

流程定义文件

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

<process name="reject3" key="reject3" xmlns="http://jbpm.org/4.4/jpdl">
    <start name="start1" g="314,45,48,48">
        <transition to="task0"/>
    </start>

    <task name="task0" g="295,389,92,52" assignee="task0">
        <transition to="task1"/>
    </task>

    <task name="task1" g="295,389,92,52" assignee="task1">
        <transition to="fork1"/>
    </task>

    <fork name="fork1" g="317,127,48,48">
        <transition to="task2"/>
        <transition to="task4"/>
    </fork>

    <task name="task2" g="205,206,92,52" assignee="task2">
        <transition to="task3"/>
    </task>

    <task name="task3" g="205,206,92,52" assignee="task3">
        <transition to="join1"/>
    </task>

    <task name="task4" g="392,212,92,52" assignee="task4">
        <transition to="join1"/>
    </task>

    <join name="join1" g="314,311,48,48" multiplicity="2">
        <transition to="end1"/>
    </join>

    <end name="end1" g="319,472,48,48"/>
</process>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值