Packagecom.mycom.processDefinition;ImportJava.io.InputStream;Importjava.util.List;ImportJava.util.zip.ZipInputStream;ImportOrg.activiti.engine.ProcessEngine;ImportOrg.activiti.engine.ProcessEngines;Importorg.activiti.engine.repository.Deployment;Importorg.activiti.engine.repository.ProcessDefinition;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 ("################################"); } } } }
Activiti query Process Definition