Process engines and services
- RepositoryService RepositoryService, which is used to manage the process repository, such as deploying, deleting, and reading process resources
- The RuntimeService RuntimeService can handle process control (start, pause, suspend, etc.) for all running process instances
- TaskService Manages and queries tasks, such as receiving, handling, and assigning tasks
- The IdentitiServicec identity Service manages and queries the relationship between users and groups
- FormService the FormService is used to read form data related to processes and tasks
- HistoryService HistoryService is used to query all historical data
- ManagementService Engine Manages services. It is irrelevant to specific services and mainly queries engine configurations and database operations
- DynamicBpmService DynamicBpmService
Process Storage Service
RepositoryService
- Manage process definition file XML and static resource services
- Suspend activation of the process definition file
- Process defines startup permission management
- Deploy file builder DeploymentBuilder
- Deploy file query DeploymentQuery
- The process definition file query object ProcessDefinitionQuery
The API documentation
The serial number | methods | meaning | describe | Library table field |
---|---|---|---|---|
1 | RepositoryService. CreateDeployment (.) addClasspathResource (” parameters “). The deploy () | Deployment process | The XML process file under the Resources file | omit |
2 | repositoryService.createDeploymentQuery().list() | Querying All Deployments | omit | omit |
3 | repositoryService.createProcessDefinitionQuery().list() | Query all deployment processes | omit | omit |
4 | Or ByKey repositoryService. SuspendProcessDefinitionById (id) | Suspend the process | Suspend the process based on the process ID | Change the ACT_RE_PROCDEF field in table SUSPENSION_STATE_:1 activate the SUSPENSION_STATE_. 2 suspend the SUSPENSION_STATE_ |
5 | Or ByKey repositoryService. ActivateProcessDefinitionById (id) | Start the process | Activate the process based on the process ID | Change the ACT_RE_PROCDEF field in table SUSPENSION_STATE_:1 activate the SUSPENSION_STATE_. 2 suspend the SUSPENSION_STATE_ |
6 | RepositoryService. AddCandidateStarterUser (process id, user id) | Mapping between processes and users | Add a relationship between a process and a user | Operating ACT_RU_IDENTITYLINK table |
7 | RepositoryService. DeleteCandidateStarterGroup (process id, user id) | Mapping between flows and user groups | Adding a relationship between a flow and a user group | Operating ACT_RU_IDENTITYLINK table |
8 | RepositoryService. DeleteCandidateStarterUser (process id, user id) | Mapping between processes and users | Delete the relationship between a process and a user | Operating ACT_RU_IDENTITYLINK table |
9 | RepositoryService. DeleteCandidateStarterGroup (process id, user id) | Mapping between processes and users | Deleting the relationship between a flow and a user group | Operating ACT_RU_IDENTITYLINK table |
10 | RepositoryService. GetIdentityLinksForProcessDefinition (process id) | Query flow mapping | The query flow corresponds to the relationship between users and groups | Query ACT_RU_IDENTITYLINK table |
The test code
package com.guosh.activiti.coreapi;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.DeploymentQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.test.ActivitiRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
/** * Process storage service *@Author: Guosh
* @Date: the 2019-07-19 o * /
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:activiti-context.xml"})
public class RepostoryServiceTest {
private static final Logger logger = LoggerFactory.getLogger(RepostoryServiceTest.class);
@Rule
@Autowired
public ActivitiRule activitiRule;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Test
public void testRepository(a){
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
/ / the classpath
Deployment deploy = deploymentBuilder.name("Test Deployment Resource 1")
.addClasspathResource("my-process.bpmn20.xml")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
// Multiple deployments
/ / the classpath
DeploymentBuilder deploymentBuilder2 = repositoryService.createDeployment();
Deployment deploy2 = deploymentBuilder2.name("Test Deployment Resource 2")
.addClasspathResource("my-process.bpmn20.xml")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
// Query the deployment
List<Deployment> deployments = repositoryService.createDeploymentQuery()
.orderByDeploymenTime().asc()
.list();
for (Deployment deployment:deployments){
logger.info("deployment = {}",deployment);
}
logger.info("deployments.size = {}",deployments.size());
// Query the deployed process
List<ProcessDefinition> processDefinitions = repositoryService
.createProcessDefinitionQuery()
.list();
for (ProcessDefinition processDefinition:processDefinitions) {
logger.info("processDefinition = {}, version = {}, key = {}, id = {}", processDefinition, processDefinition.getVersion(), processDefinition.getKey(), processDefinition.getId()); }}// The test process suspends and starts
@Test
public void testSuspend(a){
// The process hangs
repositoryService.suspendProcessDefinitionById("my-process:1:7506");
// An error is reported if the process is suspended
try{
logger.info("Startup process");
runtimeService.startProcessInstanceById("my-process:1:7506");
logger.info("Startup successful");
}catch (Exception e){
logger.info("Startup failed");
logger.info(e.getMessage(),e);
}
// Process activation
repositoryService.activateProcessDefinitionById("my-process:1:7506");
logger.info("Startup process");
runtimeService.startProcessInstanceById("my-process:1:7506");
logger.info("Startup successful");
}
// Tests the relationship between the specified user or user group and the process
@Test
public void testCandidateStarter(a){
// Specify user parameters for the process process ID and user ID
repositoryService.addCandidateStarterUser("my-process:1:7506"."user");
// Specify user groups for the process
repositoryService.addCandidateStarterGroup("my-process:1:7506"."groupM");
// Query all users corresponding to the flow
List<IdentityLink> identityLinks = repositoryService.getIdentityLinksForProcessDefinition("my-process:1:7506");
for (IdentityLink identityLink:identityLinks) {
logger.info("identityLink = {}",identityLink);
}
// Delete the relationship
repositoryService.deleteCandidateStarterUser("my-process:1:7506"."user");
repositoryService.deleteCandidateStarterGroup("my-process:1:7506"."groupM"); }}Copy the code
Process run control service
RuntimeService
- Start process and control process data
- ProcessInstance and Execution flow query
- Trigger process operations and receive messages and signals
RuntimeService starts process variable management
- Common ways to start a process (ID,key,message)
- Start a process optional parameters (businesskey, variables, tenantId)
- Set and get variables
Process instances and execution flows
- A ProcessInstance represents a data entity for a workflow business
- Execution flow represents a specific Execution path within a process instance
- The process instance interface inherits and executes flows
The process trigger
- Use trigger to trigger the ReceiveTask node
- The signal capture event signalEvenReceived is triggered
- The message capture event messageEventReceived is triggered
The serial number | methods | meaning | describe |
---|---|---|---|
1 | runtimeService.startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) | Start a process based on the deployment process key | omit |
2 | runtimeService.startProcessInstanceById(String processDefinitionId, Map<String, Object> variables) | Start a process based on the deployment process ID | omit |
3 | runtimeService.createProcessInstanceBuilder().businessKey(“businessKey001”) .processDefinitionKey(String processDefinitionKey).variables( Map<String, Object> variables) .start() | Start the process according to processInstanceBuilder | omit |
4 | runtimeService.getVariables(processInstance.getId()) | Get the pass parameter based on the process instance ID | omit |
5 | runtimeService.setVariable(processInstance.getId(),”key3″,”value3″) | Add or modify parameters | omit |
6 | runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()) | Query flow instance | Get the process instance by process ID |
7 | runtimeService.createExecutionQuery() | Gets the process execution object | omit |
The test code
/** * Process operation control service *@Author: Guosh
* @Date: the 2019-07-19 o * /
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:activiti-context.xml"})
public class RuntimeServiceTest {
private static final Logger logger = LoggerFactory.getLogger(RuntimeServiceTest.class);
@Rule
@Autowired
public ActivitiRule activitiRule;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
// Deploy the flow process
@Test
public void testRepository(a){
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
/ / the classpath
Deployment deploy = deploymentBuilder.name("Test Deployment Resource 1")
.addClasspathResource("my-process-signal-received.bpmn20.xml")
.deploy();
}
// Start the process according to key
@Test
public void testStartProcess(a){
Map<String,Object> variables=new HashMap<String,Object>();
// Pass in parameters
variables.put("key1"."value1");
// Start the latest version of the process that is used by default based on key
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
}
// Start the process by id
@Test
public void testStartProcessById(a){
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
Map<String,Object> variables=new HashMap<String,Object>();
// Pass in parameters
variables.put("key1"."value1");
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), variables);
logger.info("processInstance = {}",processInstance);
}
// Start the process according to processInstanceBuilder
@Test
public void testProcessInstanceBuilder(a){
Map<String,Object> variables=new HashMap<String,Object>();
// Pass in parameters
variables.put("key1"."value1");
// Start the process
ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
ProcessInstance processInstance = processInstanceBuilder.businessKey("businessKey001")
.processDefinitionKey("my-process")
.variables(variables)
.start();
logger.info("processInstance = {}",processInstance);
}
// Get parameters based on their process instance ID
@Test
public void testVariables(a){
Map<String,Object> variables=new HashMap<String,Object>();
// Pass in parameters
variables.put("key1"."value1");
variables.put("key2"."value2");
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
// Add a new parameter
runtimeService.setVariable(processInstance.getId(),"key3"."value3");
// Modify a parameter
runtimeService.setVariable(processInstance.getId(),"key2"."value2_1");
// Get the parameters passed by the process instance
Map<String, Object> variables1 = runtimeService.getVariables(processInstance.getId());
logger.info("variables1 = {}",variables1);
}
// Based on its process instance ID
@Test
public void testProcessInstanceQuery(a){
Map<String,Object> variables=new HashMap<String,Object>();
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
ProcessInstance processInstance1 = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstance.getId()).singleResult();
}
// The process performs the object query operation
@Test
public void testExecutionQuery(a){
Map<String,Object> variables=new HashMap<String,Object>();
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
// Process execution object
List<Execution> executions = runtimeService.createExecutionQuery().list();
for (Execution execution:executions){
logger.info("execution = {}",execution); }}}Copy the code
The process trigger
// Process triggers
@Test
public void testTrigger(a){
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
// Process execution object
Execution executions = runtimeService.createExecutionQuery().activityId("someTask").singleResult();
logger.info("executions = {}",executions);
// Trigger execution
runtimeService.trigger(executions.getId());
executions = runtimeService.createExecutionQuery().activityId("someTask").singleResult();
logger.info("executions = {}",executions);
}
Copy the code
Process file XML
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<receiveTask id="someTask"/>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Copy the code
Signal capture node triggers
// Signal process node fires
@Test
public void testSignalEventReceived(a){
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
// Query the trigger signal
Execution executions = runtimeService.createExecutionQuery().signalEventSubscriptionName("my-signal").singleResult();
logger.info("executions = {}",executions);
// Trigger execution
runtimeService.signalEventReceived("my-signal");
}
Copy the code
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<! -- -- -- > signal
<signal id="signalStart" name="my-signal"/>
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="signal-received" />
<! -- Catch events -->
<intermediateCatchEvent id="signal-received">
<signalEventDefinition signalRef="signalStart"/>
</intermediateCatchEvent>
<sequenceFlow id="flow2" sourceRef="signal-received" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Copy the code
Message triggers
// Message flow node fires
@Test
public void testMessageEventReceived(a){
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
// Query the trigger signal
Execution executions = runtimeService.createExecutionQuery().messageEventSubscriptionName("my-message").singleResult();
logger.info("executions = {}",executions);
// Trigger execution
runtimeService.messageEventReceived("my-message",executions.getId());
}
Copy the code
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<! -- -- -- > signal
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="message-received" />
<! -- Catch events -->
<intermediateCatchEvent id="message-received">
<messageEventDefinition messageRef="messageStart"/>
</intermediateCatchEvent>
<sequenceFlow id="flow2" sourceRef="message-received" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Copy the code
The process starts based on Message
@Test
public void testMessageStart(a){
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByMessage("my-message");
logger.info("processInstance = {}",processInstance);
}
Copy the code
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<! -- -- -- > signal
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start" >
<messageEventDefinition messageRef="messageStart"/>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!" />
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Copy the code
Task Management service
- TaskService
- Manage user tasks and process control
- Set UserTask to permission information (owner, candidate, handler)
- Add task attachments and tasks for user tasks; Evaluation and event record
- TaskService manages tasks and controls processes
- Task object pairs are created and deleted
- Query tasks and drive the Task node to complete execution
- Set Task parameters (variable)
The serial number | methods | meaning | describe |
---|---|---|---|
1 | taskService.createTaskQuery().list() | Querying all Tasks | omit |
2 | Taskservice. setVariable(” task ID “,” key “,” value “) | Setting common variables | omit |
3 | TaskService. SetVariableLocal (” task id “, “key”, “value”) | Setting local variables | omit |
4 | TaskService. GetVariables (” task id “) | Getting common variables | omit |
5 | TaskService. GetVariablesLocal ((” task id “) | Get local variables | omit |
6 | runtimeService.getVariables(task.getExecutionId()) | Get variables by stream | omit |
7 | TaskService.com plete(” task ID “,” Map”) | Go to the next node | omit |
@Test
public void testTaskService(a){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message"."my test message !!");
// Start the process
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
/ / for the task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
// Description
logger.info("task.description = {}",task.getDescription());
// Set a normal variable
taskService.setVariable(task.getId(),"key1"."value1");
// Set local variables
taskService.setVariableLocal(task.getId(),"localkey1"."localval1");
// Get ordinary variables
Map<String, Object> taskServiceVariables = taskService.getVariables(task.getId());
// Get local variables
Map<String, Object> taskServiceVariablesLocal = taskService.getVariablesLocal(task.getId());
// Through the execution flow
Map<String, Object> variables1 = runtimeService.getVariables(task.getExecutionId());
//{key1=value1, localkey1=localval1, message=my test message !! }
logger.info("taskServiceVariables = {}",taskServiceVariables);
//{localkey1=localval1}
logger.info("taskServiceVariablesLocal = {}",taskServiceVariablesLocal);
//{key1=value1, message=my test message !! }
logger.info("variables1 = {}",variables1);
Map<String,Object> completeVar=new HashMap<String, Object>();
completeVar.put("ckey1"."cvalue1");
// Execute the next node
taskService.complete(task.getId(),completeVar);
Copy the code
- TaskService Sets Task permission information
- Candidate users (candidateUser) and candidate Groups (candidateGroup)
- Designated Owner and Assignee
- Set the handler through claim
The serial number | methods | meaning | describe |
---|---|---|---|
1 | taskService.setOwner(“taskId”,”user”) | Setting the process Initiator | omit |
2 | taskService.claim(“”taskId””,”user”) | Appointed agent | omit |
3 | taskService.addCandidateUser(“user”) | Add candidates | omit |
4 | taskService.addCandidateGroup(“group”) | Adding candidate Groups | omit |
5 | taskService.createTaskQuery().taskCandidateUser(“user”).taskUnassigned().list() | Query candidate list has user but does not specify agent task | omit |
6 | taskService.createTaskQuery().taskCandidateUser(“user”).taskUnassigned().list() | Query the list of candidates with me but no assigned agent task | omit |
7 | taskService.createTaskQuery().taskAssignee(“user”).list() | Query the task for the agent user | omit |
8 | taskService.getIdentityLinksForTask(“taskId”) | Query the relationship between tasks and personnel | omit |
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<! - activiti: candidateStarterUsers designated candidates -- >
<userTask id="someTask" name="Activiti is awesome!" activiti:candidateUsers="jimmy,user1,user2">
<! -- Add description -->
<documentation>some task ${message}</documentation>
</userTask>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Copy the code
// User permission test
@Test
public void testTaskServiceUser(a){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message"."my test message !!");
// Start the process
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
/ / for the task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
// Description
logger.info("task.description = {}",task.getDescription());
// Set the process to the originator
taskService.setOwner(task.getId(),"user1");
// specify a transactor
//taskService.setAssignee(task.getId(),"jimmy");
// query the list of candidates with me but no agent assigned task
List<Task> taskList = taskService.createTaskQuery()
.taskCandidateUser("jimmy")
.taskUnassigned().list();
/ / specify the transactor claim checks whether the task has already been claimed, if the claim is sell ActivitiTaskAlreadyClaimedException
for (Task task1:taskList){
taskService.claim(task1.getId(),"jimmy");
}
// Query how much user-related data the task has
List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(task.getId());
for(IdentityLink identityLink:identityLinksForTask){
logger.info("identityLink = {}",identityLink);
}
// Query the task for Jimmy
List<Task> taskList1 = taskService.createTaskQuery().taskAssignee("jimmy").list();
for (Task task1:taskList1){
Map<String,Object> completeVar=new HashMap<String, Object>();
completeVar.put("ckey1"."cvalue1"); taskService.complete(task.getId(),completeVar); }}Copy the code
- TaskService Sets additional Task information
- Task Attachment creation and query
- Task evaluation (Comment) Creation and query
The serial number | methods | meaning | describe |
---|---|---|---|
1 | TaskService. CreateAttachment (” type “, “task id”, “process id”, “the attachment name”, “annex describes”, “flow or url) | To upload attachments | omit |
2 | TaskService. GetTaskAttachments (” task id “) | To upload attachments | omit |
3 | Taskservice. addComment(” task id”,” process id”,” comment 1″) | Add approval comments | omit |
4 | TaskService. GetTaskComments (” task id “) | Inquire approval notes | omit |
5 | TaskService. GetTaskEvents (” task id “) | Example Query task logs | omit |
// File attachment test
@Test
public void testTaskServiceAttachment(a){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message"."my test message !!");
// Start the process
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
/ / for the task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
// Description
logger.info("task.description = {}",task.getDescription());
// Upload the attachment
taskService.createAttachment("url",task.getId(),
task.getProcessInstanceId(),"Attachment Name"."Appendix Description"."/url/test.png");
// Query the attachment
List<Attachment> taskAttachments = taskService.getTaskAttachments(task.getId());
for (Attachment attachment:taskAttachments){
logger.info("attachment = {}",attachment); }}// Comment test
@Test
public void testTaskServiceComment(a){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message"."my test message !!");
// Start the process
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
/ / for the task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
// Description
logger.info("task.description = {}",task.getDescription());
// Add the approval annotation
taskService.addComment(task.getId(),task.getProcessInstanceId(),"recourd note 1");
taskService.addComment(task.getId(),task.getProcessInstanceId(),"recourd note 2");
// Query approval comments
List<Comment> taskComments = taskService.getTaskComments(task.getId());
for (Comment comment:taskComments){
logger.info("comment = {}",comment);
}
// Query all task logs
List<Event> taskEvents = taskService.getTaskEvents(task.getId());
for (Event event:taskEvents){
logger.info("event = {}",event); }}Copy the code
Identity Management services
- IdentityService
- Managing users (User)
- Managing User Groups
- User and user Group Membership
The serial number | methods | meaning | describe |
---|---|---|---|
1 | identityService.newUser(“userid”) | Create a user | omit |
2 | identityService.newGroup(“groupid”) | Create a Group | omit |
3 | identityService.saveUser(user) | Save or update the user | omit |
4 | identityService.saveGroup(group) | Save or update the group | omit |
5 | identityService.createUserQuery() | Query the user | omit |
6 | identityService.createGroupQuery() | Query group | omit |
@Test
public void testIdentity(a){
/ / create the user
User user1 = identityService.newUser("user1");
// Add attributes
user1.setEmail("[email protected]");
User user2 = identityService.newUser("user2");
user2.setEmail("[email protected]");
identityService.saveUser(user1);
identityService.saveUser(user2);
/ / create a group
Group group1 = identityService.newGroup("group1");
identityService.saveGroup(group1);
Group group2 = identityService.newGroup("group2");
identityService.saveGroup(group2);
// Create a relationship between userid and grupID
identityService.createMembership("user1"."group1");
identityService.createMembership("user2"."group1");
identityService.createMembership("user1"."group2");
// Query the users under group1
List<User> userList = identityService.createUserQuery().memberOfGroup("group1").list();
for (User user:userList) {
logger.info("user = {}",user);
}
// Query the group to which user1 belongs
List<Group> groupList = identityService.createGroupQuery().groupMember("user1").list();
for (Group group:groupList) {
logger.info("group = {}",group); }}Copy the code
Form Service Management
- FormService
- Resolve the configuration of table items in the process definition
- The way the form is submitted drives the user node flow
- Gets the custom external form key
The serial number | methods | meaning | describe |
---|---|---|---|
1 | formService.getStartFormKey(processDefinition.getId()) | The ID of the deployment process gets the form key | omit |
2 | formService.getStartFormData(processDefinition.getId()).getFormProperties() | Gets the start node form content | omit |
3 | formService.getStartFormData(processDefinition.getId()).getFormProperties() | Gets the start node form content | omit |
4 | FormService. SubmitStartFormData (processDefinition. GetId (), “the value parameter”) | Start the process through FormService | omit |
5 | FormService. SubmitTaskFormData (” taskId “, “parameter”) | Submit the task form through FormService | omit |
6 | formService.getTaskFormData(“taskId”) | Get the task node form content through taskid | omit |
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="my-process">
<startEvent id="start" activiti:formKey="/rest/process/form/start">
<extensionElements>
<activiti:formProperty id="message" name="Information" type="string" required="true"></activiti:formProperty>
</extensionElements>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!" activiti:formKey="/rest/process/form/userTask">
<extensionElements>
<activiti:formProperty id="yewORno" name="Approval" type="string" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Copy the code
@Test
public void testFormService(a){
// Get the deployment process
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
/ / get startformkey
String startFormKey = formService.getStartFormKey(processDefinition.getId());
logger.info("startFormKey= {}",startFormKey);
// Get the form content
StartFormData startFormData = formService.getStartFormData(processDefinition.getId());
List<FormProperty> formProperties = startFormData.getFormProperties();
for (FormProperty formProperty:formProperties) {
logger.info("formProperty= {}",formProperty);
}
// Start the process with formService
Map<String,String> properties=new HashMap<String,String>();
properties.put("message"."my test message");
ProcessInstance processInstance = formService.submitStartFormData(processDefinition.getId(), properties);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
// Query the task form
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
List<FormProperty> formProperties1 = taskFormData.getFormProperties();
for (FormProperty formProperty:formProperties1) {
logger.info("formProperties1= {}",formProperty);
}
Map<String, String> properties2 = new HashMap<String, String>();
properties2.put("yewORno"."yes");
// Submit the task with formService
formService.submitTaskFormData(task.getId(),properties2);
}
Copy the code
History Management Service
- HistoryService
- Manage historical data after the process instance ends
- Build historical data query objects
- Delete process history data based on the process instance ID
- HistoryService builds historical query objects
- Create [Historical data Entity]Query
- CreateNative [entity] historical Query | by native SQL queries
- CreateProcessInstanceHistoryLogQuery | all the other data query a process instance
- HistoryService Deletes the history operation
- DeleteHistoricProcessInstance | delete history and other information cascade deletion process instance
- DeleteHistoricTaskInstance | delete history task instance
The serial number | methods | meaning | describe |
---|---|---|---|
1 | historyService.createHistoricProcessInstanceQuery() | Query process instance variables | omit |
2 | historyService.createHistoricActivityInstanceQuery() | Querying active Nodes | omit |
3 | historyService.createHistoricTaskInstanceQuery() | Query Task Instance | omit |
4 | historyService.createHistoricVariableInstanceQuery() | Example Query process task variables | omit |
5 | historyService.createHistoricDetailQuery() | History task flow activity details | omit |
6 | HistoryService. CreateProcessInstanceHistoryLogQuery (” process instance id “) | Query all other data for a process instance | omit |
7 | HistoryService. DeleteHistoricProcessInstance (” process instance id “) | Delete the historical process instance | omit |
8 | historyService.deleteHistoricTaskInstance(“taskid”) | Deleting a Historical Task | omit |
@Test
public void testHistory(a){
Map<String,Object> variables=new HashMap<String,Object>();
// Pass in parameters
variables.put("key0"."value0");
variables.put("key1"."value1");
variables.put("key2"."value2");
Map<String,Object> transientVariables=new HashMap<String,Object>();
// Pass in parameters
transientVariables.put("tkey1"."tvalue1");
// Start the process
ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
ProcessInstance processInstance = processInstanceBuilder
.processDefinitionKey("my-process")
.variables(variables)
// Transient variables are not persisted to the database
.transientVariables(transientVariables)
.start();
logger.info("processInstance = {}",processInstance);
// Change the key1 value
runtimeService.setVariable(processInstance.getId(),"key1"."value1_1");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
Map<String,String> properties =new HashMap<String, String>();
properties.put("fkey1"."fvalue1");
properties.put("key2"."value2_2");
formService.submitTaskFormData(task.getId(),properties);
// Query process instance variables
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance historicProcessInstance:historicProcessInstances) {
logger.info("historicProcessInstance = {}",historicProcessInstance);
}
// Query the active node object
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().list();
for (HistoricActivityInstance historicActivityInstance:historicActivityInstances) {
logger.info("historicActivityInstance = {}",historicActivityInstance);
}
// Query task instances
List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery().list();
for (HistoricTaskInstance historicTaskInstance:historicTaskInstances) {
logger.info("historicTaskInstance = {}",historicTaskInstance);
}
// Query the value of the process task variable
List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().list();
for (HistoricVariableInstance historicVariableInstance:historicVariableInstances) {
logger.info("historicVariableInstance = {}",historicVariableInstance);
}
// History task flow activity details
List<HistoricDetail> historicDetails = historyService.createHistoricDetailQuery().list();
for (HistoricDetail historicDetail:historicDetails) {
logger.info("historicDetail = {}",historicDetail);
}
// Query all other data for a process instance
ProcessInstanceHistoryLog processInstanceHistoryLog = historyService.createProcessInstanceHistoryLogQuery(processInstance.getId())
// Contains data
.includeVariables()
.includeFormProperties()
.includeComments()
.includeTasks()
.includeActivities()
.includeVariableUpdates()
.singleResult();
List<HistoricData> historicDatas = processInstanceHistoryLog.getHistoricData();
for (HistoricData historicData:historicDatas) {
logger.info("historicData = {}",historicData);
}
// Delete the process instance ID
historyService.deleteHistoricProcessInstance(processInstance.getId());
// Confirm whether to delete
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
logger.info("historicProcessInstance = {}",historicProcessInstance);
}
Copy the code
Other Management Services
- Other Management Services
- The ManagementService
- Dynamic process definition service DynamicBpmnService
- ManagementService
- Job Task Management
- General database-related operations
- Executing process engine commands
- Job Task Query
- JobQuery Indicates the common work
- TimerJobQuery Query works periodically
- SuspendedJobQuery The query is interrupted
- DeadLetterJobQuery Query for jobs that cannot be executed
The serial number | methods | meaning | describe |
---|---|---|---|
1 | managementService.createTimerJobQuery() | Query timing work | omit |
2 | managementService.createJobQuery() | Query general job omission | omit |
3 | managementService.createSuspendedJobQuery() | Query interrupt work | omit |
4 | managementService.createDeadLetterJobQuery() | Query for work that cannot be performed | omit |
@Test
public void testJobQuery(a){
// Work task query
List<Job> timerJobList = managementService.createTimerJobQuery().list();
for (Job timerJob:timerJobList) {
logger.info("timerJob={}",timerJob);
}
JobQuery jobQuery = managementService.createJobQuery();
/ / the interrupt
SuspendedJobQuery suspendedJobQuery = managementService.createSuspendedJobQuery();
// No more execution
DeadLetterJobQuery deadLetterJobQuery = managementService.createDeadLetterJobQuery();
}
Copy the code
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="my-process">
<startEvent id="start">
<timerEventDefinition>
<! -- Timed task loops five times every ten seconds -->
<timeCycle>R5/PT10S</timeCycle>
</timerEventDefinition>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!" />
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Copy the code
- Database-related operations
- Querying table structure metadata
- Generic query (TablePageQuery)
- ExecuteCustomSql queries (executeCustomSql)
The serial number | methods | meaning | describe |
---|---|---|---|
1 | managementService.createTablePageQuery().tableName(managementService.getTableName(class)) | Query entity to all data | omit |
2 | managementService.executeCustomSql() | Customize SQL queries | omit |
public interface MyCustomMapper {
@Select("SELECT * FROM ACT_RU_TASK")
public List<Map<String,Object>> findAll();
}
Copy the code
@Test
public void testCustSql(a){
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
// Customize SQL statements
List<Map<String, Object>> mapList = managementService.executeCustomSql(new AbstractCustomSqlExecution<MyCustomMapper, List<Map<String, Object>>>(MyCustomMapper.class) {
@Override
public List<Map<String, Object>> execute(MyCustomMapper o) {
returno.findAll(); }});for (Map<String,Object> stringObjectMap:mapList) {
logger.info("stringObjectMap={}",stringObjectMap); }}Copy the code
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="jdbcUrl" value="JDBC: mysql: / / 127.0.0.1:3306 / activiti6unit? useUnicode=true& characterEncoding=utf8& useSSL=false& autoReconnect=true& failOverReadOnly=false" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
<! -- Database update Policy -->
<property name="databaseSchemaUpdate" value="true"/>
<! -- Asynchronous activator -->
<property name="asyncExecutorActivate" value="true"/>
<! -- Register mapper object -->
<property name="customMybatisMappers">
<set>
<value>com.guosh.activiti.mapper.MyCustomMapper</value>
</set>
</property>
</bean>
Copy the code
- Executing process engine commands
@Test
public void testCommand(a){
// Start the process
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
// Create command
ProcessDefinitionEntity processDefinitionEntity= managementService.executeCommand(new Command<ProcessDefinitionEntity>() {
@Override
public ProcessDefinitionEntity execute(CommandContext commandContext) {
ProcessDefinitionEntity processDefinitionEntity= commandContext.getProcessDefinitionEntityManager()
// The object defined by the last process
.findLatestProcessDefinitionByKey("my-process");
returnprocessDefinitionEntity; }}); logger.info("processDefinitionEntity={}",processDefinitionEntity);
}
Copy the code
Abnormal strategy
- ActivitiEXception
- The ActivitiWrongDbException engine does not match the database version
- ActivitiOptimisticLockingException concurrent lead to abnormal optimistic locking
- Abnormal ActivitiClassLoadingException class is loaded
- ActivitiObjectNotFoundException action object does not exist
- The parameters of ActivitilllegalArgumentException illegally
- ActivitiTaskAlreadyClaimedException task agent is statement
- BpmnError defines the service exception control flow