activiti learning 4: Process file deployment
After a good process to get the process definition files, you need to deploy the file specification defines bpmn activiti to the database, this process can be used.
activiti and process definitions related operations require the use of RepositoryService
this service components to carry out.
activiti all service components are required to get through the process engine objects
A, RepositoryService service components
This component provides a series of management process definition and process deployment api, we can use this component in the process of deploying api
Gets 1.1 RepositoryService instance of an object
Process Engine instance method of an object processEngine.getRepositoryService();
to obtain RepositoryService
@Test
public void test1() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
System.out.println(repositoryService);
}
Second, the process deployment descriptor information, Deployment Object
Before explaining how the deployment process, we first look at how to deploy activiti description of the information flow. activiti use Deployment
this interface to describe the process of deployment information, and provides its own implementation class. Corresponds to a table in the database ACT_RE_DEPLOYMENT activiti
Third, the process of deployment
DeploymentBuilder activiti using objects of this class to the deployment process, from the name of this class can be seen on its function, and returns the process to deploy a description of the object of this deployment information.
RepositoryService service components using an object to obtain the object DeploymentBuilder
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
Then add to this deploymentBuilder position to deploy the process files
deploymentBuilder.addClasspathResource("process/process.bpmn");
I am here is to create a process / process.bpmn process definition file in the resources directory, so add this path
You can also add a name-based deployments and classification
deploymentBuilder.name("vacation-test").category("test");
Finally, the implementation of the deployment
Deployment deploy = deploymentBuilder.deploy();
ACT_RE_DEPLOYMENT observation database table, you will find more than a deployment record.
Complete code
@Test
public void test1() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
deploymentBuilder.addClasspathResource("process/process.bpmn");
deploymentBuilder.name("vacation-test").category("test");
Deployment deploy = deploymentBuilder.deploy();
System.out.println(deploy);
}
Note, by default the same flowchart will be deployed multiple times to generate a plurality of records in the table, with a deployment time field used for distinguishing
3.1 filtration problems repeated deployments
In order to prevent not changed repetitive deployment resources deployment method to produce again, you can call the enableDuplicateFiltering DeploymentBuilder () method, where the filtering is to deploy a query table, the table has been the deployment of a collection of objects, if we find there is a deployment record will be deployed with the object of the same will not be repeated deployments. So name, category, resource name and content settings when deploying, as long as one is not the same it will not be filtered out
deploymentBuilder.enableDuplicateFiltering();//设置过滤重复部署
Fourth, deployment management information
activiti in DeploymentQuery
the package this interface in the management api deployment information, and provides its own implementation class to get its class object achieved by repositoryService service components.
DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
4.1 Deployment Information inquiry
@Test
public void test2() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
//根据deploymentId查询
String deploymentId="4201";
Deployment singleResult = deploymentQuery.deploymentId(deploymentId)
.deploymentName("vacation-test").singleResult();
System.out.println(singleResult);
}
Query, the query stitching give deploymentQuery objects, here to support programming chain, the first splice query one by one, this last
singleResult()
If the return multiple results according to the conditions set call; methods to perform queries return a result singleResult()
query method throws an exception, then you need to call to return multiple resultslist()
4.2 Delete Deployment Information
Because the deployment information table and other tables have foreign key, so delete data deployment in the table are deleted can not afford, you need to call the delete method to delete the RepositoryService
@Test
public void test3() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
String deploymentId="4201";
boolean cascade=true;
repositoryService.deleteDeployment(deploymentId, cascade);
}
The second parameter which indicates whether the cascade cascade delete data from other tables, you can direct to true
Fifth, process definition and management
5.1 Description of the flow definition information
After a successful deployment process file, the deployment will not only record information in the deployment table, but also add a process definition in the process definition table act_re_procdef information, a description of the process flow file is deployed defined.
Note that this KEY_ wherein id field corresponding to a node is a flow process definition files, the flow to be turned on when activiti use this field.
<process id="process" isExecutable="true">
<startEvent id="sid-26F630F1-0761-4247-8383-F63F913A310E"></startEvent>
<userTask id="usertask1" name="apply vecation" activiti:assignee="kermit"></userTask>
<sequenceFlow id="sid-85398367-B674-473A-B7AC-268635F0DF5D" sourceRef="sid-26F630F1-0761-4247-8383-F63F913A310E" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="manager agree" activiti:assignee="kermit"></userTask>
<sequenceFlow id="sid-5372C6B1-7359-40AB-B0A4-3FF06F20790E" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<endEvent id="sid-F621C8EF-13A5-4A49-BD5B-708BFB066576"></endEvent>
<sequenceFlow id="sid-BCF9087D-36F4-4EDE-BD88-013AC74AB93A" sourceRef="usertask2" targetRef="sid-F621C8EF-13A5-4A49-BD5B-708BFB066576"></sequenceFlow>
</process>
And deployment information, like, activiti also has an interface to the description of this table, ProcessDefinition
and provides its own implementation class
5.2 process definition information management
activiti provides ProcessDefinitionQuery
this interface, the package in which the flow definition information relevant to the query api. Query object access and use DeploymentQuery similar.
@Test
public void test1() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
String processDefinitionKey="process";
List<ProcessDefinition> list = processDefinitionQuery.processDefinitionKey(processDefinitionKey).list();
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition);
}
}
VI Summary
This article describes how to manage the deployment process definition files, as well as the deployment of information and process definition for post-deployment generated information.