jbpm 流程增删改查

package com.jiaocaigen002.processinstance;

import java.util.List;

import org.jbpm.api.*;

import junit.framework.TestCase;

/**
 * 流程实例
 * @author leiwei 2012-3-20
 *
 */
public class ProcessInstanceTest extends TestCase {

    //流程引擎
    ProcessEngine processEngine;

    public ProcessInstanceTest() {
        processEngine = Configuration.getProcessEngine();
    }

    /**
     *  发布流程定义
     */
    protected void setUp() {
        //流程资源服务的接口,如流程定义发布、查询、删除等
        processEngine.getRepositoryService().createDeployment()
                        .addResourceFromClasspath("helloworld.jpdl.xml").deploy();
    }
    
    /**
     * 发布新流程
     */
    public void newProcessInstance() {
        //用于操作人工任务的服务,可以进行任务创建、查询、获取、提交完成、保存、删除等操作
        ExecutionService executionService = processEngine.getExecutionService();
        ProcessInstance processInstance = executionService.startProcessInstanceByKey("helloworld");
        
        //查看流程是否已经结束
        System.out.println("流程是否已经结束:"+processInstance.isEnded());
        
        //直接跳过等待,直接结束
        processInstance = executionService.signalExecutionById(processInstance.getId());
        System.out.println("流程是否已经结束:"+processInstance.isEnded());
    }
    
    /**
     * 终止流程
     */
    public void endProcessInstance() {
        ExecutionService executionService = processEngine.getExecutionService();
        ProcessInstance processInstance = executionService.startProcessInstanceByKey("helloworld");
        executionService.endProcessInstance(processInstance.getId(), "cancle");
    }
    
    /**
     * 删除流程
     */
    public void deleteProcessInstance() {
        ExecutionService executionService = processEngine.getExecutionService();
        ProcessInstance processInstance = executionService.startProcessInstanceByKey("helloworld");
        executionService.deleteProcessInstanceCascade(processInstance.getId());
    }
    
    /**
     * 查看流程
     */
    public void selectProcessInstance() {
        ExecutionService executionService = processEngine.getExecutionService();
        ProcessInstance processInstance1 = executionService.startProcessInstanceByKey("helloworld");
        ProcessInstance processInstance2 = executionService.startProcessInstanceByKey("helloworld");
        List<ProcessInstance> processInstanceList= executionService
                                    .createProcessInstanceQuery().list();
        
        for (ProcessInstance processInstance : processInstanceList) {
            System.out.println("流程的个数:"+processInstance.getId());
        }
    }
    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值