手动发布流程定义(jbpm3)

     上一个文章介绍了在启动tomat服务的时候自动发布流程。这里介绍如何手动的把定义好的processdefinition.xml持久化到数据库中。这里使用的是junit测试代码

1. 建两个包cn.edu.ujn.wsjx.test.process以及cn.edu.ujn.wsjx.test.service
2. 在service包中新建测试基类BaseServiceTest.java
 1 package  cn.edu.ujn.wsjx.test.service;
 2
 3 import  org.springframework.context.ApplicationContext;
 4 import  org.springframework.context.support.ClassPathXmlApplicationContext;
 5
 6 import  junit.framework.TestCase;
 7
 8 public   class  BaseServiceTest  extends  TestCase
 9 {
10    protected ApplicationContext context;
11    
12    public ApplicationContext getApplicationContext()
13    {
14        return context;
15    }

16
17    @Override
18    protected void setUp() throws Exception
19    {
20        // TODO Auto-generated method stub
21        super.setUp();
22
23        context = new ClassPathXmlApplicationContext(new String[]
24        "spring/applicationContext.xml""spring/applicationContext-jbpm.xml",
25                "spring/applicationContext-shi.xml""spring/applicationContext-wu.xml",
26                "spring/applicationContext-zhou.xml""spring/daoContext.xml" }
);
27    }

28}

29
3. 在包process中新建类ProcessDeployTest继承上面的类
package  cn.edu.ujn.wsjx.test.process;

import  java.io.File;
import  java.io.FileInputStream;
import  java.io.FileNotFoundException;
import  java.util.zip.ZipInputStream;

import  org.jbpm.JbpmConfiguration;
import  org.jbpm.JbpmContext;
import  org.jbpm.graph.def.ProcessDefinition;

import  cn.edu.ujn.wsjx.test.service.BaseServiceTest;

public   class  ProcessDeployTest  extends  BaseServiceTest
{
    
public void testAddProcessDefinition()
    
{
        JbpmConfiguration jbpmConfiguration 
= (JbpmConfiguration)context.getBean("jbpmConfiguration");
        JbpmContext jbpmContext 
= jbpmConfiguration.createJbpmContext();
        
        
try
        
{
            File file 
= new File("E:/work/work.zip");
            FileInputStream fis 
= new FileInputStream(file);
            ZipInputStream zip 
= new ZipInputStream(fis);
            
            ProcessDefinition processDefinition 
= ProcessDefinition.parseParZipInputStream(zip);
            
            jbpmContext.deployProcessDefinition(processDefinition);
        }
catch(FileNotFoundException e)
        
{
            e.printStackTrace();
        }
finally
        
{
            jbpmContext.close();
        }

        
    }

    
    
public void testDestroyProcess()
    
{
        JbpmConfiguration jbpmConfiguration 
= (JbpmConfiguration)context.getBean("jbpmConfiguration");
        JbpmContext jbpmContext 
= jbpmConfiguration.createJbpmContext();
        
        jbpmContext.getGraphSession().deleteProcessDefinition(
1);
        
        jbpmContext.close();
    }

}

说明:testAddProcessDefinition()是发布流程定义的zip包到数据库中,testDestroyProcess()是通过数据库中存储的流程id删除相应的流程

你可能感兴趣的:(手动发布流程定义(jbpm3))