Activiti Advanced (3) - CRUD of Process Definition

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

 

 

  1. // query process definition  
  2. @Test  
  3. publicvoid findProcessDifinitionList() {   
  4.     List <ProcessDefinition> list = processEngine.getRepositoryService ()  
  5.             .createProcessDefinitionQuery()  
  6.             // Query conditions  
  7.             .processDefinitionKey( "myMyHelloWorld" ) // key defined by the process  
  8.             // .processDefinitionId("helloworld")//ID defined by the process  
  9.             .orderByProcessDefinitionVersion().desc() // sort  
  10.             // return result  
  11.             // .singleResult()//returns a unique result set  
  12.             // .count()//returns the number of result sets  
  13.             // .listPage(firstResult, maxResults)  
  14.             .list(); // multiple result sets  
  15.       
  16.     if(list!=null && list.size()>0){  
  17.         for(ProcessDefinition pd:list){  
  18.             System.out.println( "Process definition ID: " +pd.getId());  
  19.             System.out.println( "Name of process definition: " +pd.getName());  
  20.             System.out.println( "Key defined by the process: " +pd.getKey());  
  21.             System.out.println( "Deployment ID of process definition: " +pd.getDeploymentId());  
  22.             System.out.println( "Process defined resource name: " +pd.getResourceName());  
  23.             System.out.println( "Version of process definition: " +pd.getVersion());  
  24.             System.out.println("########################################################");  
  25.         }  
  26.     }  
  27.   
  28. }  
	// 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

 

 

  1. // delete the process definition  
  2. @Test  
  3. publicvoid deleteProcessDifinition(){   
  4.     //deployment object ID  
  5.     String deploymentId = "601";  
  6.     processEngine.getRepositoryService() //Get the Service related to the process definition and deployment object  
  7.         .deleteDeployment(deploymentId,true);  
  8.       
  9.     System.out.println( "Delete successful~~~" ); //Use the deployment ID to delete the process definition, true means cascade deletion  
  10. }  
	// 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

 

 

  1. //View the resource file defined by the process  
  2. @Test  
  3. publicvoid viewPng() throws IOException{   
  4.     //deployment ID  
  5.     String deploymentId = "1";  
  6.     // get the resource name  
  7.     List <String> list = processEngine.getRepositoryService ()  
  8.         .getDeploymentResourceNames(deploymentId);  
  9.     //Get the resource name suffix.png  
  10.     String resourceName = "";  
  11.     if(list != null && list.size()>0){  
  12.         for(String name:list){  
  13.             if (name.indexOf( ".png" )>= 0 ){ //returns the index position of the first letter containing the string  
  14.                 resourceName = name;  
  15.             }  
  16.         }  
  17.     }  
  18.       
  19.     //Get the input stream, and store the .PNG file in the input stream  
  20.     InputStream in = processEngine.getRepositoryService ()  
  21.             .getResourceAsStream(deploymentId, resourceName);  
  22.       
  23.     //Save the obtained file to the local  
  24.     FileUtils.copyInputStreamToFile(in, new File("D:/" + resourceName));  
  25.       
  26.     System.out.println( "The file was saved successfully!" );  
  27. }  
	//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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326622853&siteId=291194637