JBPM to change the definition of the process

Source: Internet
Author: User
Package com.itcast.processdefinition;
Import Java.io.File;
Import Java.io.FileOutputStream;
Import Java.io.InputStream;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Java.util.Set;

Import Java.util.zip.ZipInputStream;
Import org.jbpm.api.Configuration;
Import org.jbpm.api.ProcessDefinition;
Import Org.jbpm.api.ProcessDefinitionQuery;
Import Org.jbpm.api.ProcessEngine;

Import Org.junit.Test;
    public class Processdefinitiontest {private static processengine processengine;
        static{//processengine = new Configuration (). Setresource ("Jbpm.cfg.xml"). Buildprocessengine ();
        Processengine = new Configuration (). Buildprocessengine ();
    Processengine = Configuration.getprocessengine (); }//Deployment (ADD) @Test public void Deploy () throws Exception {String Deployid = Processengine.getreposito Ryservice (). Createdeployment (). Addresourcefromclasspath ("Helloworld/helloworld.jpdl.xml"). AddResourceFro MClAsspath ("Helloworld/helloworld.png"). deploy ();
    SYSTEM.OUT.PRINTLN ("Successful deployment: deployid==" +deployid); }//Deployment (ADD) @Test public void Deployzip () throws Exception {InputStream is = This.getclass (). GetClass
        Loader (). getResourceAsStream ("Helloworld/helloworld.zip"); String Deployid = Processengine.getrepositoryservice (). Createdeployment ()//.addresourcefromfile (New File ("D:/hell

        Oworld.zip ")). Addresourcesfromzipinputstream (New Zipinputstream (IS)). deploy ();
    SYSTEM.OUT.PRINTLN ("Successful deployment: deployid==" +deployid); }//Query @Test public void FindAll () throws Exception {list<processdefinition> List = Processengi Ne.getrepositoryservice (). Createprocessdefinitionquery (). Processdefinitionkey ("HelloWorld"). Processdefin Itionnamelike ("%helloworld%"). ORDERASC (processdefinitionquery.property_id). Orderdesc (ProcessDefinitionQu ery. Property_key)//.page (Firstresult, Maxresults). List (); if (list!= null) {for (ProcessDefinition pd:list) {System.out.println ("deploymentid=" +pd.getd
                        Eploymentid () + ", name=" +pd.getname () + ", version=" +pd.getversion ()
            + ", id=" +pd.getid () + ", key=" +pd.getkey ()); }}//Query the latest version of the process @Test public void findalllatestversions () throws Exception {LIST&LT;PR ocessdefinition> list = Processengine.getrepositoryservice (). Createprocessdefinitionquery (). ORDERASC (ProcessDe

        finitionquery.property_version). List (); So the map has the latest processdefinition map<string, processdefinition> map = new hashmap<string, Processdefiniti
        On> ();
        for (ProcessDefinition pd:list) {map.put (Pd.getkey (), PD); } if (list!= null) {for (ProcessDefinition pd:map.values()) {System.out.println ("deploymentid=" +pd.getdeploymentid () + ", name=" +pd.getname (
                        ) + ", version=" +pd.getversion () + ", id=" +pd.getid ()
            + ", key=" +pd.getkey ()); }}//query @Test public void count () throws Exception {Long Count = Processengine.getrep Ositoryservice (). Createprocessdefinitionquery (). Processdefinitionkey ("HelloWorld"). Proce Ssdefinitionnamelike ("%helloworld%"). ORDERASC (processdefinitionquery.property_id). orderd
        ESC (Processdefinitionquery.property_key). Count ();
    System.out.println ("count==" + count);
        }//Query @Test public void Find () throws Exception {String Deploymentid = "80001";
           ProcessDefinition PD = Processengine.getrepositoryservice (). Createprocessdefinitionquery ()     . Processdefinitionkey ("HelloWorld"). Processdefinitionnamelike ("%helloworld%"). Order ASC (processdefinitionquery.property_id). Orderdesc (Processdefinitionquery.property_key). D

        Eploymentid (Deploymentid). Uniqueresult ();
    System.out.println ("id=" +pd.getdeploymentid () + ", name=" +pd.getname () + ", assigne=" +pd.getversion ());
        }//delete @Test public void Deletebyid () throws Exception {String Deploymentid = "80001";
        The information associated with the deletion will be an error//processengine.getrepositoryservice (). Deletedeployment (Deploymentid);
    cascading deletes Processengine.getrepositoryservice (). Deletedeploymentcascade (Deploymentid); }//Remove all @Test public void Deleteallbykey () throws Exception {list<processdefinition> List = P Rocessengine.getrepositoryservice (). Createprocessdefinitionquery (). ORDERASC (Processdefinitionquery.proper
                Ty_version). List ();

        The information associated with the deletion will be an error//processengine.getrepositoryservice (). Deletedeployment (Deploymentid); for (ProcessDefinition pd:list) {//Cascade deletes Processengine.getrepositoryservice (). Deletedeploymentcasc
        Ade (Pd.getdeploymentid ()); }//View flowchart (***.png) @Test public void Getimageresource () throws Exception {String deployment
        Id = "80001";
        String resourcename = "Helloworld/helloworld.png";
        set<string> resourcenames = Processengine.getrepositoryservice (). Getresourcenames (DeploymentId);
        Processengine.getrepositoryservice (). getResourceAsStream (Deploymentid, resourcename);
        for (String name:resourcenames) {System.out.println ("imagename==" +name + "\t\n");
        } InputStream is = Processengine.getrepositoryservice (). getResourceAsStream (Deploymentid, resourceName);
        FileOutputStream fos = new FileOutputStream (New File ("D:/process.png")); int Len =-1;
        while (len = Is.read ())!=-1) {fos.write (len);
        } is.close ();
    Fos.close ();
 }
}

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.