Activiti7工作流引擎:进阶篇 ProcessRuntime和TaskRuntime
Posted vbirdbest
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti7工作流引擎:进阶篇 ProcessRuntime和TaskRuntime相关的知识,希望对你有一定的参考价值。
医者仁心,以人为本 --- 致西安中被拒绝的生命。
一:ProcessRuntime和TaskRuntime
Activiti7提供了两个Runtime类用于对Service提供了进一步封装,并且和Spring Security进行高度耦合。
@PreAuthorize("hasRole('ACTIVITI_USER')")
public class ProcessRuntimeImpl implements ProcessRuntime
private final RuntimeService runtimeService;
public interface TaskRuntime
TaskRuntimeConfiguration configuration();
Task task(String taskId);
Page tasks(Pageable pageable);
Page tasks(Pageable pageable, GetTasksPayload payload);
Task create(CreateTaskPayload payload);
Task claim(ClaimTaskPayload payload);
Task release(ReleaseTaskPayload payload);
Task complete(CompleteTaskPayload payload);
Task update(UpdateTaskPayload payload);
Task delete(DeleteTaskPayload payload);
...
@PreAuthorize("hasRole('ACTIVITI_USER')")
public class TaskRuntimeImpl implements TaskRuntime
private final TaskService taskService;
public interface ProcessRuntime
ProcessRuntimeConfiguration configuration();
ProcessDefinition processDefinition(String processDefinitionId);
Page processDefinitions(Pageable pageable);
Page processDefinitions(Pageable pageable, GetProcessDefinitionsPayload payload);
ProcessInstance start(StartProcessPayload payload);
Page processInstances(Pageable pageable);
Page processInstances(Pageable pageable, GetProcessInstancesPayload payload);
ProcessInstance processInstance(String processInstanceId);
ProcessInstance suspend(SuspendProcessPayload payload);
ProcessInstance resume(ResumeProcessPayload payload);
ProcessInstance delete(DeleteProcessPayload payload);
void signal(SignalPayload payload);
...
XxxRuntime要求用户必须有ACTIVITI_USER
角色。
二:示例
taskRuntime.create(TaskPayloadBuilder.create()
.withName("First Team Task")
.withDescription("This is something really important")
.withGroup("activitiTeam")
.withPriority(10)
.build());
Page processDefinitionPage = processRuntime.processDefinitions(Pageable.of(0, 10));
logger.info("> Available Process definitions: " + processDefinitionPage.getTotalItems());
for (ProcessDefinition pd : processDefinitionPage.getContent())
logger.info("\\t > Process definition: " + pd);
@SpringBootTest
class SpringbootActiviti7ApplicationTests
@Autowired
private ProcessRuntime processRuntime;
@Autowired
private TaskRuntime taskRuntime;
@Autowired
private SecurityUtil securityUtil;
@Test
void testQueryProcessDefinition()
securityUtil.logInAs("system");
Page<ProcessDefinition> processDefinitionPage = processRuntime.processDefinitions(Pageable.of(0, 10));
for (ProcessDefinition processDefinition : processDefinitionPage.getContent())
System.out.println(processDefinition.getKey());
@Test
void testStartProcess()
securityUtil.logInAs("system");
processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey("HelloWorldProcess").build());
@Test
public void testCompleteTask()
securityUtil.logInAs("jack");
Page<Task> taskPage = taskRuntime.tasks(Pageable.of(0, 10));
if (taskPage.getTotalItems() > 0)
for (Task task : taskPage.getContent())
// 拾取任务
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
// 完成任务
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
三:其它
Activiti7 提供了两个新的API ProcessRuntime和TaskRuntime,但是这两个API必须使用Spring Security,这对于项目没有引入Spring Security是非常不友好的。
so 我们可以使用Activiti7中继续使用原来的方式,使用XxxService来完成工作流。
以上是关于Activiti7工作流引擎:进阶篇 ProcessRuntime和TaskRuntime的主要内容,如果未能解决你的问题,请参考以下文章
Activiti7工作流引擎:进阶篇 SpringBoot整合工作流Activiti7