Activiti process definition deployment, deletion, and viewing process images,
1. deployment process definition
The deployment process definition can also be considered as adding a process definition.
First, create a process engine object (public method)
Private ProcessEngine processEngine = ProcessEngines. getdefadefaprocessengine (); Method 1:
/*** 1. the publishing process * generates data in three tables: * act_ge_bytearray generates two pieces of data * act_re_deployment generates one piece of data * act_re_procdef generates one piece of data */public void deploy () throws Exception {// obtain the repository service RepositoryService repositoryService = processEngine. getRepositoryService (); // create the release configuration object DeploymentBuilder = repositoryService. createDeployment (); // set the publishing information builder. name ("Leave Process") // Add an alias for the deployment rule. addClasspathResource ("diagrams/Leave2.bpmn") // Add a rule file. addClasspathResource ("diagrams/Leave2.png"); // adding a rule image without adding a rule image will automatically generate an image not recommended // complete publishing builder. deploy ();}
Method 2:
Public void deployZIP () throws Exception {// get repository service RepositoryService repositoryService = processEngine. getRepositoryService (); // create the release configuration object DeploymentBuilder = repositoryService. createDeployment (); // obtain the input process of the uploaded file. InputStream in = this. getClass (). getClassLoader (). getResourceAsStream ("diagrams/diagrams.zip"); ZipInputStream zipInputStream = new ZipInputStream (in); // set the publishing information builder. name ("Leave Process") // Add an alias for the deployment rule. addZipInputStream (zipInputStream); // complete the release builder. deploy ();}
Note:
1) first obtain the default process engine. activiti. cfg. xml under classpath is automatically loaded during creation.
2) Obtain a RepositoryService object through the process engine-> warehouse service object
3) A deployment object configuration object is generated by the service objects in the repository to encapsulate the configurations of the deployment environment.
4) This is a chained programming. Set the display name in the deployment configuration object and upload the address of the Rule file relative to classpath.
5) deployment is also the process of defining the stored procedures in the database.
6) in this step, three tables will be operated in the database:
A) act_re_deployment
Stores the display name and deployment time of the process definition, and adds a record for each deployment.
B) act_re_procdef
Stores the attribute information of the process definition. Each new process definition is deployed with a record added to this table.
C) act_ge_bytearray
The deployment information related to the storage process definition. That is, the place where the process definition document is stored. Each deployment adds two records, one for the bpmn rule file and the other for the image (if only one bpmn file is specified during deployment, activiti will parse the bpmn file content during deployment to automatically generate a flowchart ). The two files are not very large and are both stored in the database in binary format.
2. Deletion Process
Delete the process definition deployed in activiti.
Public void delDeployment () throws Exception {// obtain the repository service object RepositoryService repositoryService = processEngine. getRepositoryService (); // Delete publish message String deploymentId = "1"; // normal deletion. If the current rule has a running process, an exception is thrown. deleteDeployment (deploymentId); // cascading deletion deletes all information related to the current rule, including historical repositoryService. deleteDeployment (deploymentId, true );}
Note:
1) because the process definition is deleted and the deployment of the Process Definition belongs to the repository service, you should first obtain the RepositoryService
2) if there is no running process under the process definition, you can use normal deletion. For associated information, delete it in cascade mode. In general, you can use normal deletion. Because cascade deletion involves a large amount of data, it is generally only available to super administrators.
3. view the process definition
/*** View process definition * process definition ProcessDefinition * id: {key }:{ version }:{ random value} * name: name attribute of the process node in the process file * key: id attribute * version of the process file process node: generated automatically upon release. For the first release process, veresion starts from 1 by default. If the current process engine already has a process with the same key, find the highest version number corresponding to the current key, add 1 */public void queryProcessDefinition () throws Exception {// obtain the repository service object RepositoryService repositoryService = processEngine. getRepositoryService (); // gets the process definition query object ProcessDefinitionQuery processDefinitionQuery = repositoryService. createProcessDefinitionQuery (); // configure the query object processDefinitionQuery // Add filter conditions //. processDefinitionName (processDefinitionName )//. processDefinitionId (processDefinitionId )//. processDefinitionKey (processDefinitionKey) // paging condition //. listPage (firstResult, maxResults) // sorting condition. orderByProcessDefinitionVersion (). desc ();/*** execution query ** list: after execution, a set * singelResult is returned. After execution, the system checks whether the result length is 1. If the result is one, the system returns the first data entry; if it is not unique, an exception is thrown * count: count the number of results meeting the condition */List <ProcessDefinition> pd= processDefinitionQuery. list (); // traverse the set and view the content for (ProcessDefinition pd: PPS) {System. out. print ("id:" + pd. getId () + ","); System. out. print ("name:" + pd. getName () + ","); System. out. print ("key:" + pd. getKey () + ","); System. out. println ("version:" + pd. getVersion ());}}
Note:
1) because the process definition information is stored in the repository, you should obtain the RepositoryService.
2) create a process definition query object. You can set query filter parameters on ProcessDefinitionQuery.
3) Call the list method of the ProcessDefinitionQuery object to execute the query and obtain the list of qualified process definitions.
4) The running results show that:
A) The value of Key and Name is the attribute value of the id and name of the process node of the bpmn file.
B) The key attribute is used to differentiate different process definitions.
C) when a process with a specific key is defined for the first deployment, the version is 1. After that, each deployment will add 1 to the current maximum version number.
D) The generation rule of Id values is: {processDefinitionKey }:{ processDefinitionVersion }:{ generated-id}, where generated-id is a unique automatically generated number.
E) If the deployment is repeated once, the value of deploymentId changes in a certain form.
F) ProcessDefinition does not have a corresponding table in the database, but retrieves the corresponding bpmn and png images from the act_ge_bytearray table and parses them.
4. View process images
Public void viewImage () throws Exception {// create a repository service to object RepositoryService repositoryService = processEngine. getRepositoryService (); // find the file to be displayed from the repository String deploymentId = "701"; List <String> names = repositoryService. getDeploymentResourceNames (deploymentId); String imageName = null; for (String name: names) {if (name. indexOf (". png ")> = 0) {imageName = name;} if (imageName! = Null) {// System. out. println (imageName); File f = new File ("e:/" + imageName); // The input stream InputStream in = repositoryService of the File is obtained by the deployment ID and File name. getResourceAsStream (deploymentId, imageName); FileUtils. copyInputStreamToFile (in, f );}
Note:
1) deploymentId is the process deployment ID
2) resourceName is the value of the NAME _ column in The act_ge_bytearray table.
3) use the getDeploymentResourceNames method of repositoryService to obtain the names of all files under the specified deployment.
4) use the getResourceAsStream method of the repositoryService to pass in the deployment ID and file name to get the input stream of the specified name file under the deployment.
5) for the last IO stream operation, use the copyInputStreamToFile method of the FileUtils tool to copy the process flow to the file.