JBPM4.4 基本使用

JBPM工作流环境搭建:

                    1、先下载JBPM框架

                    2、安装JBPM图形编辑插件

                         注:插件在jbpm-4.4\install\src\gpd 目录下

 

创建工程导入JBPM依赖jar包

                     注:jar包目录jbpm-4.4\lib 单独使用JBPM开发 建议导入此目录下所有jar包

                      在src目录下创建JBPM持久化配置文件和注配置文件

                      1、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>

                    2、jbpm.hibernate.cfg.xml 数据库持久化配置文件  示例为Mysql 数据库

<?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 结尾 如何绘制流程省略

 

调用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");
    }
}

 

工作流基本操作:部署流程--》创建流程实例--》获取当前任务--》完成任务跳转下一个节点任务--》所有任务完成流程结束

 

你可能感兴趣的:(JBPM4.4 基本使用)