JBPM4.4 基本使用

JBPM工做流環境搭建:java

                    一、先下載JBPM框架mysql

                    二、安裝JBPM圖形編輯插件sql

                         注:插件在jbpm-4.4\install\src\gpd 目錄下數據庫

 

建立工程導入JBPM依賴jar包api

                     注:jar包目錄jbpm-4.4\lib 單獨使用JBPM開發 建議導入此目錄下全部jar包session

                      在src目錄下建立JBPM持久化配置文件和注配置文件app

                      一、jbpm.cfg.xml  默認配置文件框架

                         

<?xml version="1.0" encoding="UTF-8"?>

<jbpm-configuration>

  <import resource="jbpm.default.cfg.xml" />
  <import resource="jbpm.businesscalendar.cfg.xml" />
  <import resource="jbpm.tx.hibernate.cfg.xml" />
  <import resource="jbpm.jpdl.cfg.xml" />
  <import resource="jbpm.bpmn.cfg.xml" />
  <import resource="jbpm.identity.cfg.xml" />

  <!-- Job executor is excluded for running the example test cases. -->
  <!-- To enable timers and messages in production use, this should be included. -->
  <!-- <import resource="jbpm.jobexecutor.cfg.xml" /> -->

</jbpm-configuration>

                    二、jbpm.hibernate.cfg.xml 數據庫持久化配置文件  示例爲Mysql 數據庫ide

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>

        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm?useUnicode=true&amp;characterEncoding=UTF-8</property>
        <property name="hibernate.connection.username">jbpm</property>
        <property name="hibernate.connection.password">jbpm</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.format_sql">true</property>

        <mapping resource="jbpm.repository.hbm.xml" />
        <mapping resource="jbpm.execution.hbm.xml" />
        <mapping resource="jbpm.history.hbm.xml" />
        <mapping resource="jbpm.task.hbm.xml" />
        <mapping resource="jbpm.identity.hbm.xml" />

    </session-factory>
</hibernate-configuration>

 

繪製流程圖 test01.jpdl.xml 流程圖爲.jpdl.xml 結尾 如何繪製流程省略this

 

調用API操做流程

              注意:JBPM會在數據庫建立18張表

/** * */
package com.ly.test; import java.util.Iterator; import java.util.List; import java.util.Set; import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.ProcessEngine; import org.jbpm.api.RepositoryService; import org.jbpm.api.TaskService; import org.jbpm.api.task.Task; import junit.framework.TestCase; /** * @author Yong * @時間 2013年9月24日 * @版本 V1.0 */
public class Test extends TestCase { public void testdeploy() { ProcessEngine pEngine = Configuration.getProcessEngine(); RepositoryService repositoryService = pEngine.getRepositoryService(); // 部署流程
        String deploymentId = repositoryService.createDeployment().addResourceFromClasspath("test02.jpdl.xml").deploy(); // 刪除流程 不會刪除未完成任務得流程 // repositoryService.deleteDeployment(deploymentId); // 刪除流程 會級聯未完成任務得流程 // repositoryService.deleteDeploymentCascade(deploymentId);
 } // 獲取對應人員任務
    public void testgetTask() { ProcessEngine pEngine = Configuration.getProcessEngine(); // 獲取人工任務服務
        TaskService tService = pEngine.getTaskService(); // 經過assignee 提取全部任務 
        List<Task> tasks = tService.findPersonalTasks("李四"); Task task = tasks.get(0); System.out.println("任務數量------------->" + tasks.size()); System.out.println("任務名稱------------->" + task.getActivityName()); System.out.println("任務人員-------------->" + task.getAssignee()); System.out.println("任務ID---------------->" + task.getId()); } // 查詢當前流程所處階段
    public void testgetCurrectactivity() { ProcessEngine pEngine = Configuration.getProcessEngine(); //獲取執行服務
        ExecutionService eService = pEngine.getExecutionService(); //獲取全部路程節點
        Set<String> activityName = eService.createProcessInstanceQuery().processInstanceId("test01.10001").uniqueResult().findActiveActivityNames(); Iterator<String> iterator = activityName.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } // 完成任務
    public void testcoepleteTask() { ProcessEngine pEngine = Configuration.getProcessEngine(); //獲取任務服務
        TaskService tService = pEngine.getTaskService(); tService.completeTask("20001"); } }

 

工做流基本操做:部署流程--》建立流程實例--》獲取當前任務--》完成任務跳轉下一個節點任務--》全部任務完成流程結束

相關文章
相關標籤/搜索