Jbpm Workflow Engine Learning Log

1. Introduction to jbpm

     jBPM is an open source java workflow project under JBOSS, which provides eclipse plug-in and implements data persistent storage based on Hibernate. Download address: http://pan.baidu.com/s/1ntr8t6L

 

2.jbpm environment construction

    Install gpd, configure the runtime environment, import the jar packages required by jbpm, and create configuration files jbpm.cfg.xml and jbpm.hibernate.cfg.xml

 

    jbpm.cfg.xml is configured as follows:

<?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.spring.cfg.xml" />
  <import resource="jbpm.jpdl.cfg.xml" />
  <import resource="jbpm.bpmn.cfg.xml" />
  <import resource="jbpm.identity.cfg.xml" />
  

</jbpm-configuration>

    jbpm.hibernate.cfg.xml is configured as follows:

 

     

<?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="connection.url">jdbc:sqlserver://localhost:1433;databaseName=Jbpm</property>
		<property name="connection.username">sa</property>
		<property name="connection.password">woaixua52110</property>
		<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
		<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
		<property name="hibernate.hbm2ddl.auto">create-drop</property>
		<property name="hibernate.format_sql">true</property>
		<property name="show_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>


   Here is the configuration of Sql server, what needs to be paid attention to here is the property <property name="hibernate.hbm2ddl.auto">create-drop</property>. There are two types: update and create-drop. It is not recommended to use create-drop, because if a table already exists in the database, it will drop first and then create it.

 

  Create a new jpdl process file

 

    

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

<process name="test" key="test" xmlns="http://jbpm.org/4.4/jpdl">
   <start name="start1" g="272,85,48,48">
      <transition name="Submit to Section Chief" to="Section Chief Approval" g="-52,-22"/>
   </start>
   <task assignee="Zhang San" name="Section Chief Approval" g="258,212,92,52">
      <transition name="Submit to Director" to="Director Approval" g="-52,-22"/>
   </task>
   <task assignee="Li Si" name="Director's approval" g="261,341,92,52">
      <transition name="通过" to="end1" g="-50,-22"/>
   </task>
   <end name="end1" g="284,448,48,48"/>
</process>

    The design diagram is as follows:

 



 

After the configuration file is ready, start the test 

 

package com.jbpm.demo;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;

import junit.framework.TestCase;

public class JbpmDemo extends TestCase {
	
	/**
	 * 部署、初始化 创建jbpm所需的表
	 */
	public void deploy(){
		ProcessEngine processEngine = Configuration.getProcessEngine();
		RepositoryService repositoryService = processEngine.getRepositoryService();
		repositoryService.createDeployment().addResourceFromClasspath("test.jpdl.xml").deploy();
	}
	
	
}

   单元测试成功后,数据库里会新那18张jbpm相应表,如下图

 

 3.jbpm简单的例子

 

package com.jbpm.demo;

import java.util.List;

import junit.framework.TestCase;

import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.task.Task;

public class JbpmDemo extends TestCase {

	public ProcessEngine processEngine = Configuration.getProcessEngine();

	/**
	 * 部署、初始化 创建jbpm所需的表
	 */
	public void deploy() {
		RepositoryService repositoryService = processEngine
				.getRepositoryService();
		repositoryService.createDeployment()
				.addResourceFromClasspath("test.jpdl.xml").deploy();
	}

	/**
	 * 创建流程实例
	 */
	public void createInstance() {
		ExecutionService executionService = processEngine.getExecutionService();
		ProcessInstance processInstance = executionService
				.startProcessInstanceByKey("leave");
		System.out.println("流程实例Id:" + processInstance.getId());
	}

	/**
	 * 获取对应人员任务
	 */
	public void getTask() {
		TaskService taskService = processEngine.getTaskService();
		List<Task> tasks = taskService.findPersonalTasks("李四");
		for (Task task : tasks) {
			System.out.println("当前任务ID:" + task.getId());
			System.out.println("当前任务名:" + task.getActivityName());
			System.out.println("当前任务分配人员:" + task.getAssignee());
		}
	}

	/**
	 * 查询流程实例当前所在节点
	 */
	public void getCurrectActivity() {
		ExecutionService executionService = processEngine.getExecutionService();
		String activityName = executionService.createProcessInstanceQuery()
				.processInstanceId("leave.10001").uniqueResult()
				.findActiveActivityNames().toString();
		System.out.println("当前流程节点:" + activityName);
	}

	/**
	 * 完成任务
	 */
	public void completeTask() {
		TaskService taskService = processEngine.getTaskService();
		taskService.completeTask("10002");
	}
}

 4.jbpm服务介绍

     jpbm主要对象包括:Configuration 和ProcessEngine

     Configuration是jbpm的配置文件管理对象即资源加载对象.负责加载jbpm的各种配置如数据库连接配置,事务配置,身份认证,jpdl等相关配置.

     ProcessEngine是一个服务工厂,有点类似hibernate的sessionFactory负责创建jbpm的每个服务.

     

ProcessEngine又包括以下6个服务

    1>RepositoryService

流程资源服务接口。提供对流程定义的部署、查询、删除和流程图查看等操作。

    2>ExecutionService

流程执行服务接口。提供启动流程实例、推进、删除等操作。

    3>TaskService

人工任务服务接口。提供对任务的创建、提交、查询、保存、删除等操作。

    4>HistoryService

流程历史服务接口。提供对任务的管理操作。提供对流程历史库中历史流程实例、历史活动实例等记录的查询。

    5>ManagementService

流程管理接口,通常用来管理Jop(异步服务)

    6>IdentityService

身份认证服务接口。提供对流程用户、用户组管理

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327049181&siteId=291194637