activiti(二)
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."); } }