关于jbpm的文档

   一个引擎多个service:

RepositoryService repositoryService = processEngine
    .getRepositoryService();        //部署服务器
ExecutionService executionService = processEngine
    .getExecutionService();        //执行服务器
TaskService taskService = processEngine
    .getTaskService();            //任务服务器
HistoryService historyService = processEngine
    .getHistoryService();        //历史服务器
ManagementService managementService = processEngine
    .getManagementService();        //管理服务器

各个Service的作用:
RepositoryService   管理部署对象和流程定义
ExecutionService    管理执行的,包括启动、推进、删除Execution等操作
TaskService         管理任务的
HistoryService      历史管理(执行完的数据管理,主要是查询)
IdentityService    jBPM的用户、组管理
ManagementService   

/**
 * 
 */
package net.nyist.jbpmdemo.test;

import java.util.List;

import org.hibernate.cfg.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
import org.junit.Test;

/**
 * @author yu chao
 * 
 * @school 南阳理工软件学院 11级移动设备开发与应用 移动四班
 * 
 * @dateTime 2014年5月14日 上午11:33:07
 */
public class TestJbpm {

      /**方法一:使用默认的配置文件(jbpm.cfg.xml)生成Configuration并构建ProcessEngine*/
      //ProcessEngine processEngine =new org.jbpm.api.Configuration().buildProcessEngine();
      /**方法二:使用如下代码获取使用默认配置文件的、单例的ProcessEngine对象*/
     // ProcessEngine processEngine =org.jbpm.api.Configuration.getProcessEngine();
      /**方法三:使用指定的配置文件(要放到classPath下)*/
     // ProcessEngine processEngine =new org.jbpm.api.Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();
      
  /**创建流程引擎*/
  ProcessEngine processEngine =new org.jbpm.api.Configuration().buildProcessEngine();
  @Test
  /**创建十八张表*/
  public void create18Tables(){
       new Configuration().configure("jbpm.hibernate.cfg.xml").buildSessionFactory();
  }
  
  @Test
  /**部署流程定义*/
  public void deployProcessDefinition(){
      
      String deployID = processEngine.getRepositoryService()//部署服务器
              .createDeployment()//创建一个部署对象
              .addResourceFromClasspath("helloworld/HelloWorld.jpdl.xml")
              .addResourceFromClasspath("helloworld/HelloWorld.png")
              .deploy();
     System.out.println(deployID);
   }
  /**启动流程实例*/
  @Test
  public void startProcessInstance(){
      String processDefinitionId="HelloWorld";
     ProcessInstance processInstance = processEngine.getExecutionService()//管理执行的,包括启动、推进、删除Execution等操作
                             .startProcessInstanceByKey(processDefinitionId);
     System.out.println("流程实例的ID:"+processInstance.getId());
     System.out.println("流程实例定义的ID:"+processInstance.getProcessDefinitionId());
  }
  /**查看我个人任务列表*/
  @Test
  public void findMyPersonalTaskList(){
      
      String userId ="部门经理";
     List<Task> list = processEngine.getTaskService()
             .findPersonalTasks(userId);
     for (Task task : list) {
         System.out.println("任务的ID:"+task.getId());
         System.out.println("任务执行的ID:"+task.getExecutionId());
         System.out.println("任务的办理人:"+task.getAssignee());
         System.out.println("任务的名称:"+task.getName());
         System.out.println("任务的创建日期:"+task.getCreateTime());
    }
  }
  /**完成我个人任务*/
  @Test
  public void completeMyPersonalTask(){
      
      String taskID ="30002";
      processEngine.getTaskService()
       .completeTask(taskID);
  }
}

 

/**完成我的个人任务*/
    @Test
    public void completeMyPersonalTask(){
        
        String taskId="180002";
        processEngine.getTaskService()
        .completeTask(taskId);
        /*String taskId="140002";
        String outcome="to 审批【部门经理】";//这个参数的 作用就是指定连线的下一个走向
        processEngine.getTaskService()
        .completeTask(taskId, outcome);*/
    }
 /**向后推进一步*/                             
    @Test
    public void singleExecution(){
        
    String executionId="state.220001";    
    ProcessInstance processInstance =processEngine.getExecutionService()
         /**对于后面的连线的条数如果只有1条连线,那么就不用指明连线的名称*/        
            .signalExecutionById(executionId);
        
        //String executionId="HelloWorld.180001";
        //String signalName="to end1";
        //ProcessInstance processInstance = processEngine.getExecutionService()
        /**如果后面的流程的经过的连线的条数超过2条及其以上,就要指定下一连线的名称*/        
                                          //.signalExecutionById(executionId, signalName);
        System.out.println("流程的ID:"+processInstance.getId());        
    }

 对于流程变量所能接收的类型有以下几种形式:

 

/**设置流程变量*/    
     @Test
     public void setProcessVarible(){
        
         //这种方法采用配置文件的方式来实现对于流程变量的设置
         String executionId="state.240001";
            Person values =new Person(1L,"余超");
            Session session = new org.hibernate.cfg.Configuration().configure("jbpm.hibernate.cfg.xml").buildSessionFactory().openSession();
            session.beginTransaction().begin();
            session.save(values);
            session.beginTransaction().commit();
            ExecutionService executionService =  processEngine.getExecutionService();
            executionService.setVariable(executionId, "职工的信息", values);
         
       /*这种方法采用类实现序列化接口来完成对于变量的设置
        *String executionId="state.240001";
        Person values =new Person(1l,"余超");
        ExecutionService executionService =  processEngine.getExecutionService();
        executionService.setVariable(executionId, "职工的信息", values);*/
     }
     /**获得流程变量*/    
     @Test
     public void getProcessVarible(){
        
         /**org.hibernate.LazyInitializationException: could not initialize proxy - no Session
            at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
            at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
            at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
            at net.nyist.jbpmdemo.entity.Person_$$_javassist_8.getName(Person_$$_javassist_8.java)
            at net.nyist.jbpmdemo.test.Jbpms.getProcessVarible(Jbpms.java:132)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
            at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
            at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
            at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
            at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
            at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
            at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
            at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
            at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
            at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
            at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
            at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
            at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
            at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
            at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
            at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
            at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
          */
         String executionId="state.240001";
         ExecutionService executionService =  processEngine.getExecutionService();
         Person person = (Person) executionService.getVariable(executionId, "职工的信息");
         System.out.println(person.getId()+"      "+person.getName());
     }


/**
 * 
 */
package net.nyist.jbpmdemo.entity;

import java.io.Serializable;

/**
 * @author yu chao
 * 
 * @school 南阳理工软件学院 11级移动设备开发与应用 移动四班
 * 
 * @dateTime 2014年5月14日 下午1:43:49
 */
@SuppressWarnings("serial")
public class Person //implements Serializable 
  {

    private Long id;
    private String name;

    public Person(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Person() {

    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2014-5-14 14:06:19 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="net.nyist.jbpmdemo.entity.Person" table="PERSON" lazy="false">
        <id name="id" type="java.lang.Long">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" />
        </property>
    </class>
</hibernate-mapping>

 

 

posted @ 2014-05-14 14:42  yu0312chao  阅读(289)  评论(0编辑  收藏  举报