码迷,mamicode.com
首页 > 其他好文 > 详细

activiti(二)

时间:2020-07-16 12:10:28      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:let   osi   key   object   HERE   Pageable   run   payload   deploy   

1.获取服务列表

  

ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        List tasks = engine.getTaskService().createTaskQuery().taskAssignee("oo").list();
        
        for(Object task:tasks){
            System.out.println(task.toString());
        }

 

2.完成任务

ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

engine.getTaskService().complete("100");

3.部署工作流

ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

engine.getRepositoryService().createDeployment().name("oo").addClasspathResource("*.bnmp").deploy();

4.启动任务

ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder
.start()
.withProcessDefinitionKey("pid")
.withName("Processing Content: " + content)
.withVariable("content", content)
.build());
pid是在bnmp中定义的id
5.完成指定任务
public void checkAndWorkOnTasksWhenAvailable() {
        securityUtil.logInAs("bob");

        Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10));
        if (tasks.getTotalItems() > 0) {
            for (Task t : tasks.getContent()) {

                logger.info("> Claiming task: " + t.getId());
                taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(t.getId()).build());

                List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(t.getId()).build());
                VariableInstance variableInstance = variables.get(0);
                if (variableInstance.getName().equals("content")) {
                    Content contentToProcess = variableInstance.getValue();
                    logger.info("> Content received inside the task to approve: " + contentToProcess);

                    if (contentToProcess.getBody().contains("activiti")) {
                        logger.info("> User Approving content");
                        contentToProcess.setApproved(true);
                    } else {
                        logger.info("> User Discarding content");
                        contentToProcess.setApproved(false);
                    }
                    taskRuntime.complete(TaskPayloadBuilder.complete()
                            .withTaskId(t.getId()).withVariable("content", contentToProcess).build());
                }


            }

        } else {
            logger.info("> There are no task for me to work on.");
        }

    }

 

activiti(二)

标签:let   osi   key   object   HERE   Pageable   run   payload   deploy   

原文地址:https://www.cnblogs.com/yangyang12138/p/13313670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!