JPBM(四)管理流程定义
来源:互联网 发布:汽车超载的危害知乎 编辑:程序博客网 时间:2024/04/30 08:12
概念:
ProcessDefinition,流程定义:一个流程的步骤说明,如一个请假流程、报销流程、是一个规则。
ProcessDefinition,流程定义对象,是解析.jpdl.xml文件得到流程步骤的信息。没有更新操作,启动流程实例时是使用指定key的最新的版本。
1.部署流程定义
a)一次添加一个资源,相关文件在Classpath中
-
-
-
-
- @Test
- public void deploy_1() {
- String deploymentId = processEngine.getRepositoryService()
- .createDeployment()
- .addResourceFromClasspath("helloworld/test.jpdl.xml")
- .addResourceFromClasspath("helloworld/test.png")
- .deploy();
- System.out.println("deploymentId = " + deploymentId);
- }
b)一次添加多个资源,多个资源先打成zip包
- @Test
- public void deploy_2() {
-
- InputStream in = this.getClass().getClassLoader().getResourceAsStream("helloworld/helloworld.zip");
- ZipInputStream zipInputStream = new ZipInputStream(in);
-
-
- String deploymentId = processEngine.getRepositoryService()
- .createDeployment()
- .addResourcesFromZipInputStream(zipInputStream)
- .deploy();
- System.out.println("deploymentId = " + deploymentId);
- }
c)说明
1, addResourceFromClasspath(resource); 可以调用多次以添加多个文件。文件重复添加也不会报错。
2, addResourceFromInputStream(resourceName, inputStream)添加一个文件(使用InputStream)
3, addResourcesFromZipInputStream(zipInputStream)添加多个文件,里面也可以有文件夹。
4, 以上方法可以在一起调用。
2.查询所有流程定义
a) 查询所有流程定义
- @Test
- public void findAll() {
-
- List<ProcessDefinition> list = processEngine.getRepositoryService()
- .createProcessDefinitionQuery()
- .orderAsc(ProcessDefinitionQuery.PROPERTY_KEY)
-
-
- .list();
-
-
- for (ProcessDefinition pd : list) {
- System.out.println("id=" + pd.getId()
- + ", name=" + pd.getName()
- + ", key=" + pd.getKey()
- + ", version=" + pd.getVersion()
- + ", deploymentId=" + pd.getDeploymentId());
- }
- }
b) 查询所有最新版本的流程定义
- @Test
- public void findAllLatestVersions() {
-
- List<ProcessDefinition> allList = processEngine.getRepositoryService()
- .createProcessDefinitionQuery()
- .orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION)
-
-
-
-
-
-
- .list();
-
-
- Map<String, ProcessDefinition> map = new HashMap<String, ProcessDefinition>();
- for (ProcessDefinition pd : allList) {
- map.put(pd.getKey(), pd);
- }
-
-
- for (ProcessDefinition pd : map.values()) {
- System.out.println("id=" + pd.getId()
- + ", name=" + pd.getName()
- + ", key=" + pd.getKey()
- + ", version=" + pd.getVersion()
- + ", deploymentId=" + pd.getDeploymentId());
- }
- }
3.删除流程定义(其实是删除Deployment)
a) 删除某个Deployment
- @Test
- public void deleteById() {
- String deploymentId = "1";
-
-
-
- processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId);
- }
b) 删除指定key的所有版本的流程定义
- @Test
- public void deleteByKey() {
-
- List<ProcessDefinition> list = processEngine.getRepositoryService()
- .createProcessDefinitionQuery()
- .processDefinitionKey("helloworld")
- .list();
-
-
- for (ProcessDefinition pd : list) {
- processEngine.getRepositoryService().deleteDeploymentCascade(pd.getDeploymentId());
- }
- }
4.获取部署时的某文件的资源(查看流程图)
a) 查看流程图
- @Test
- public void getResourceFromDeployment() throws Exception {
- String deploymentId = "50001";
- String resourceName = "helloworld/test.png";
-
-
- Set<String> names = processEngine.getRepositoryService().getResourceNames(deploymentId);
- for (String name : names) {
- System.out.println(name);
- }
-
-
- InputStream in = processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName);
-
-
- OutputStream out = new FileOutputStream("c:/process.png");
- for (int b = -1; (b = in.read()) != -1;) {
- out.write(b);
- }
- in.close();
- out.close();
- }
5.获取流程图中某活动的坐标(不重要)
- String processDefinitionId = "test-1";
- String activityName = "start1";
- ActivityCoordinates c = processEngine.getRepositoryService().getActivityCoordinates(processDefinitionId, activityName);
- System.out.println("x=" + c.getX()
- + ",y=" + c.getY()
- + ",width=" + c.getWidth()
- + ",height=" + c.getHeight());
0 0