The RCUD of the process definition, that is, the addition, deletion, and inspection of the process. This blog post briefly introduces the use of Activiti's api to add, delete, modify, and check the process definition.
1. View the process definition
- // query process definition
- @Test
- publicvoid findProcessDifinitionList() {
- List <ProcessDefinition> list = processEngine.getRepositoryService ()
- .createProcessDefinitionQuery()
- // Query conditions
- .processDefinitionKey( "myMyHelloWorld" ) // key defined by the process
- // .processDefinitionId("helloworld")//ID defined by the process
- .orderByProcessDefinitionVersion().desc() // sort
- // return result
- // .singleResult()//returns a unique result set
- // .count()//returns the number of result sets
- // .listPage(firstResult, maxResults)
- .list(); // multiple result sets
- if(list!=null && list.size()>0){
- for(ProcessDefinition pd:list){
- System.out.println( "Process definition ID: " +pd.getId());
- System.out.println( "Name of process definition: " +pd.getName());
- System.out.println( "Key defined by the process: " +pd.getKey());
- System.out.println( "Deployment ID of process definition: " +pd.getDeploymentId());
- System.out.println( "Process defined resource name: " +pd.getResourceName());
- System.out.println( "Version of process definition: " +pd.getVersion());
- System.out.println("########################################################");
- }
- }
- }
// query process definition @Test public void findProcessDifinitionList() { List <ProcessDefinition> list = processEngine.getRepositoryService () .createProcessDefinitionQuery() // Query conditions .processDefinitionKey("myMyHelloWorld")// The key defined by the process // .processDefinitionId("helloworld")//ID defined by the process .orderByProcessDefinitionVersion().desc()// sort // return result // .singleResult()//returns a unique result set // .count()//returns the number of result sets // .listPage(firstResult, maxResults) .list();// Multiple result sets if(list!=null && list.size()>0){ for(ProcessDefinition pd:list){ System.out.println("Process definition ID: "+pd.getId()); System.out.println("Name of process definition: "+pd.getName()); System.out.println("Key defined by the process: "+pd.getKey()); System.out.println("Deployment ID of process definition: "+pd.getDeploymentId()); System.out.println("Process-defined resource name: "+pd.getResourceName()); System.out.println("Process definition version: "+pd.getVersion()); System.out.println("########################################################"); } } }
The Service related to the process definition and the deployment object is RepositoryService. To create a process definition query object, you can
Set the relevant parameters of the query on ProcessDefinitionQuery, call the list method of the ProcessDefinitionQuery object, execute the query, and get the
A list of eligible process definitions.
The execution result is as follows:
Second, delete the process definition
- // delete the process definition
- @Test
- publicvoid deleteProcessDifinition(){
- //deployment object ID
- String deploymentId = "601";
- processEngine.getRepositoryService() //Get the Service related to the process definition and deployment object
- .deleteDeployment(deploymentId,true);
- System.out.println( "Delete successful~~~" ); //Use the deployment ID to delete the process definition, true means cascade deletion
- }
// delete the process definition @Test public void deleteProcessDifinition(){ //deployment object ID String deploymentId = "601"; processEngine.getRepositoryService()//Get the Service related to the process definition and deployment object .deleteDeployment(deploymentId,true); System.out.println("Deleted successfully~~~");//Use the deployment ID to delete the process definition, true means cascade deletion }
Because the process definition is deleted, and the deployment of the process definition belongs to the warehouse service, the RepositoryService should be obtained first.
If there is no running process under the process definition, you can use normal delete. If it is related information, use cascade delete. project development ambassador
There are many cases of cascading deletion, and deletion operations are generally only open to super administrators.
The execution result is as follows:
3. Obtaining resources for process definition documents
- //View the resource file defined by the process
- @Test
- publicvoid viewPng() throws IOException{
- //deployment ID
- String deploymentId = "1";
- // get the resource name
- List <String> list = processEngine.getRepositoryService ()
- .getDeploymentResourceNames(deploymentId);
- //Get the resource name suffix.png
- String resourceName = "";
- if(list != null && list.size()>0){
- for(String name:list){
- if (name.indexOf( ".png" )>= 0 ){ //returns the index position of the first letter containing the string
- resourceName = name;
- }
- }
- }
- //Get the input stream, and store the .PNG file in the input stream
- InputStream in = processEngine.getRepositoryService ()
- .getResourceAsStream(deploymentId, resourceName);
- //Save the obtained file to the local
- FileUtils.copyInputStreamToFile(in, new File("D:/" + resourceName));
- System.out.println( "The file was saved successfully!" );
- }
//View the resource file defined by the process @Test public void viewPng() throws IOException{ //deployment ID String deploymentId = "1"; // get the resource name List <String> list = processEngine.getRepositoryService () .getDeploymentResourceNames(deploymentId); //Get the resource name suffix.png String resourceName = ""; if(list != null && list.size()>0){ for(String name:list){ if(name.indexOf(".png")>=0){//Returns the index position of the first letter containing the string resourceName = name; } } } //Get the input stream, and store the .PNG file in the input stream InputStream in = processEngine.getRepositoryService () .getResourceAsStream(deploymentId, resourceName); //Save the obtained file to the local FileUtils.copyInputStreamToFile(in, new File("D:/" + resourceName)); System.out.println("The file was saved successfully!"); }
Use the getDeploymentResourceNames method of repositoryService to get the names of all files under the specified deployment; use
The getResourceAsStream method of repositoryService passes in the deployment ID and resource image name to obtain the input stream of the file with the specified name under the deployment;
The last operation of IO stream, use the copyInputStreamToFile method of the FileUtils tool to complete the copy of the process flow to the file, and copy the resource file to the file.
Output to the specified folder in the form of a stream.