Activiti querying the latest version of the process definition

Source: Internet
Author: User

 Packagecom.mycom.processDefinition;ImportJava.io.File;Importjava.io.IOException;ImportJava.io.InputStream;Importjava.util.ArrayList;ImportJava.util.LinkedHashMap;Importjava.util.List;ImportJava.util.Map;ImportJava.util.zip.ZipInputStream;ImportOrg.activiti.engine.ProcessEngine;ImportOrg.activiti.engine.ProcessEngines;Importorg.activiti.engine.repository.Deployment;Importorg.activiti.engine.repository.ProcessDefinition;Importorg.apache.commons.io.FileUtils;Importorg.junit.Test; Public classprocessdefinitiontest {processengine processengine=Processengines.getdefaultprocessengine (); /** Deployment process definition (from Classpath)*/@Test Public voidDeploymentprocessdefinition_classpath () {Deployment Deployment= Processengine.getrepositoryservice ()//Service related to process definition and deployment objects. Createdeployment ()//Create a Deployment object. Name ("Process definition")//Add a deployment name. Addclasspathresource ("DIAGRAMS/HELLOWORLD.BPMN")//Load from Classpath resources, only one file can be loaded at a time. Addclasspathresource ("Diagrams/helloworld.png"). deploy ();//Complete DeploymentSYSTEM.OUT.PRINTLN ("Deployment ID:" +Deployment.getid ()); System.out.println ("Deployment Name:" +deployment.getname ()); }        /** Deployment process definition (from Zip)*/@Test Public voidDeploymentprocessdefinition_zip () {InputStream in= This. GetClass (). getClassLoader (). getResourceAsStream ("Diagrams/helloworld.zip"); Zipinputstream Zipinputstream=NewZipinputstream (in); Deployment Deployment= Processengine.getrepositoryservice ()//Service related to process definition and deployment objects. Createdeployment ()//Create a Deployment object. Name ("Process definition")//Add a deployment name. Addzipinputstream (Zipinputstream)//complete the deployment of the zip file. deploy ();//Complete DeploymentSYSTEM.OUT.PRINTLN ("Deployment ID:" +Deployment.getid ()); System.out.println ("Deployment Name:" +deployment.getname ()); }        /** Query Process definition*/@Test Public voidfindprocessdefinition () {List<ProcessDefinition> list = Processengine.getrepositoryservice ()//Service related to process definition and deployment objects. Createprocessdefinitionquery ()//Create a Process definition query                        /*specify query criteria, where condition*/                        //. Deploymentid (Deploymentid)//querying using the Deployment Object ID//. Processdefinitionid (Processdefinitionid)//query using process definition ID//. Processdefinitionkey (Processdefinitionkey)//use process-defined key queries//. Processdefinitionnamelike (processdefinitionnamelike)//fuzzy Query using the name of the process definition                                                /*Sort*/. Orderbyprocessdefinitionversion (). ASC ()//Sorted by version in ascending order//. Orderbyprocessdefinitionname (). DESC ()//Sort by process-defined name in descending order. List ();//returns a collection list that encapsulates the process definition//. Singleresult ();//returns a unique result set//. Count ();//returns the number of result sets//. Listpage (Firstresult, MaxResults)//Paging Query                if(List! =NULL&& list.size () >0){             for(ProcessDefinition processdefinition:list) {System.out.println ("Process definition ID:" +processdefinition.getid ());//key+ version of the process definition + random build numberSYSTEM.OUT.PRINTLN ("Process definition name:" +processdefinition.getname ());//the value of the name attribute in the corresponding HELLOWORLD.BPMN fileSystem.out.println ("Key for process definition:" +processdefinition.getkey ());//the value of the id attribute in the corresponding HELLOWORLD.BPMN fileSystem.out.println ("version of the process definition:" +processdefinition.getversion ());//when the key value of the process definition is the same, the version is upgraded by default starting from 1System.out.println ("Resource Name BPMN file:" +processdefinition.getresourcename ()); System.out.println ("Resource name PNG file:" +processdefinition.getdiagramresourcename ()); System.out.println ("Deployment Object ID:" +Processdefinition.getdeploymentid ()); System.out.println ("################################"); }        }            }        /** Delete process definition*/@Test Public voiddeleteprocessdefinition () {//use the deployment ID to complete the removalString Deploymentid = "1"; /** Delete without cascade * Can only delete processes that do not start, and throws an exception if the process starts*///Processengine.getrepositoryservice ()//Service related to process definition and deployment objects//. Deletedeployment (Deploymentid);        /** The deletion of the energy level Union * can delete the initiating process, will delete all the information related to the current rule, the information being executed, also includes the historical information*/Processengine.getrepositoryservice ()//Service related to process definition and deployment objects. Deletedeployment (Deploymentid,true); System.out.println ("Delete Succeeded"); }        /** Query Flowchart*/@Test Public voidViewpic ()throwsioexception{/**Place the resulting picture under a folder*/String Deploymentid= "401"; //Get Picture Resource namelist<string> list = Processengine.getrepositoryservice ()//. Getdeploymentresourcenames (Deploymentid); //define the name of the picture resourceString resourcename = ""; if(list!=NULL&& list.size () >0){             for(String name:list) {if(Name.indexof (". png") >=0) {resourcename=name; }            }        }                        //get the input stream of a pictureInputStream in = Processengine.getrepositoryservice ()//. getResourceAsStream (Deploymentid, resourcename); //create a picture into the directory of D-diskFile File =NewFile ("d:/" +resourcename); //write the picture of the input stream to the D drivefileutils.copyinputstreamtofile (in, file); }        /** Query The latest version of the process definition*/@Test Public voidfindlastversionprocessdefinition () {List<ProcessDefinition> list =Processengine.getrepositoryservice (). Createprocessdefinitionquery (). O Rderbyprocessdefinitionversion (). ASC ()//use process-defined versions in ascending order. List (); /** map<string,processdefinition> * Map Collection key: process-defined key * Map set of value: process-Defined Object * Features : When the Map collection key value is the same, the next value will replace the previous value*/Map<String,ProcessDefinition> map =NewLinkedhashmap<string,processdefinition>(); if(List! =NULL&& list.size () >0){             for(ProcessDefinition pd:list) {map.put (Pd.getkey (), PD); }} List<ProcessDefinition> pdlist =NewArraylist<processdefinition>(Map.values ()); if(pdlist!=NULL&& pdlist.size () >0){             for(ProcessDefinition pd:pdlist) {System.out.println ("Process definition ID:" +pd.getid ());//key+ version of the process definition + random build numberSystem.out.println ("Name of the process definition:" +pd.getname ());//the value of the name attribute in the corresponding HELLOWORLD.BPMN fileSystem.out.println ("Key for process definition:" +pd.getkey ());//the value of the id attribute in the corresponding HELLOWORLD.BPMN fileSystem.out.println ("version of the process definition:" +pd.getversion ());//when the key value of the process definition is the same, the version is upgraded, the default 1System.out.println ("Resource Name BPMN file:" +pd.getresourcename ()); System.out.println ("Resource name PNG file:" +pd.getdiagramresourcename ()); System.out.println ("Deployment Object ID:" +Pd.getdeploymentid ()); System.out.println ("#########################################################"); }        }                }}

Activiti querying the latest version of the process definition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.