https://community.alfresco.com/thread/221280-business-key-in-a-call-activity

这个帖子有一些讨论和回复。

https://community.alfresco.com/thread/218788-call-activity-and-businesskey#

这个帖子一直没人回答。

https://stackoverflow.com/questions/26497569/activity-how-to-know-if-an-execution-is-linked-to-an-instance-of-subprocess

https://community.alfresco.com/thread/221348-get-all-active-tasks-including-sub-process-tasks

这篇文章比较中肯,社区分享了两种(潜在的)WorkAround的方案,详见下边解决方案部分。

http://blog.csdn.net/lovemenghaibin/article/details/50608300

这个帖子是讲business key的用户的入门文章,和本问题无关。

act_ru_execution表的BUSINESS_KEY_ 字段,在使用call activiti时,子流程的BUSINESS_KEY_会丢失,而不能从父流程继承过来。

解决方案:

1.《Activiti权威指南》作者冀正,给的建议的解决办法:修改源代码,一行代码就能把丢失的BUSINESS_KEY_拷贝过来。

2.用ExecutionListener或者ActivitiEventListener监听CallActiviti的创建过程,然后把父流程实例的Business存入流程变量中。

社区网友由ExecutionListener到ActivitiEventListener逐步讨论。

a) ExecutionListener

/**
* BusinessKeyInjectionListener.java
* com.yuanchuangyun.workflow.listener
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2017年12月1日 renguoqiang
*
* Copyright (c) 2017, yuanchuangyun All Rights Reserved.
*/ package com.yuanchuangyun.workflow.listener; import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity; /**
* ClassName:BusinessKeyInjectionExecutionListener
* @author renguoqiang
* @version
* @since Ver 1.1
* @Date 2017年12月1日 下午4:10:37
*
* @see
*/
public class BusinessKeyInjectionExecutionListener implements ExecutionListener{ /**
* serialVersionUID:TODO(用一句话描述这个变量表示什么)
*
* @since Ver 1.1
*/ private static final long serialVersionUID = 1L; @Override
public void notify(DelegateExecution exec) throws Exception {
System.out.println("In BusinessKey Injection Listener"); ExecutionEntity thisEntity = (ExecutionEntity)exec;
ExecutionEntity superExecEntity = thisEntity.getSuperExecution(); String key = ""; // Check if this is the main process.
if( superExecEntity == null ){
// If it is, get the business key the main process was launched with.
key = thisEntity.getBusinessKey();
}else{
// We are a subprocess so get the BusinessKey variable set by the caller.
// This should work for N level deep sub processes.
key = (String)superExecEntity.getVariable("BusinessKey");
} // Set a process variable with the business key. Can't actually set business key because business keys
// have to be unique per process instance.
thisEntity.setVariable("BusinessKey", key);
} }

b) ActivitiEventListener

/**
* BusinessKeyInjectionActivitiEventListener.java
* com.yuanchuangyun.workflow.listener
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2017年12月1日 renguoqiang
*
* Copyright (c) 2017, yuanchuangyun All Rights Reserved.
*/ package com.yuanchuangyun.workflow.listener; import org.activiti.engine.delegate.event.ActivitiEntityEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity; /**
* ClassName:BusinessKeyInjectionActivitiEventListener
* @author renguoqiang
* @version
* @since Ver 1.1
* @Date 2017年12月1日 下午5:03:29
*
* @see
*/
public class BusinessKeyInjectionActivitiEventListener implements ActivitiEventListener {
private String getSuperProcessInstanceId(ExecutionEntity exEntity) {
if (exEntity != null && exEntity.getSuperExecution() != null) {
return getSuperProcessInstanceId(exEntity.getSuperExecution());
} else if (exEntity != null) {
return exEntity.getProcessInstanceId();
} return null;
} @Override
public void onEvent(ActivitiEvent event) {
switch (event.getType()) {
case TASK_CREATED:
if (event instanceof ActivitiEntityEvent) {
ActivitiEntityEvent activityEntityEvent = (ActivitiEntityEvent) event; TaskEntity taskEntity = (TaskEntity) activityEntityEvent
.getEntity();
ExecutionEntity exEntity = taskEntity.getExecution();
String superExId = getSuperProcessInstanceId(exEntity != null ? exEntity
.getSuperExecution() : null); if (superExId != null) {
taskEntity.setAssignee(superExId);
} try {
@SuppressWarnings("null")
ExecutionEntity executionEntity = (ExecutionEntity) activityEntityEvent
.getEntity(); ExecutionEntity superExecEntity = executionEntity
.getSuperExecution();
String key = ""; // Check if this is the main process.
if (superExecEntity == null) {
// key = executionEntity.getBusinessKey();
key = (String) executionEntity
.getVariable("BusinessKey");
} else {
key = (String) superExecEntity
.getVariable("BusinessKey");
} executionEntity.setVariable("BusinessKey", key); } catch (Exception e) {
// System.out.println("ENTITY CAST ERROR !!!!!!!!");
} break;
// ...
}
default:
break;
}
} @Override
public boolean isFailOnException() {
// TODO Auto-generated method stub
return false;
}
}

TIP:从Activiti的官方文档,可知BusinessKey这个列,预留只是为了兼容一些历史问题。系统设计时,应该避免使用此值,这样Activiti就更独立一下(耦合小),也就是把业务的主键与ProcessInstanceId的关联记录,放入自定义的业务表中存储。

源码附件:https://files.cnblogs.com/files/rgqancy/BusinessKey.zip

Issue: business key in a call activiti的更多相关文章

  1. Activiti第一篇【介绍、配置开发环境、快速入门】

    Activiti介绍 什么是Activiti? Activiti5是由Alfresco软件在2010年5月17日发布的业务流程管理(BPM)框架,它是覆盖了业务流程管理.工作流.服务协作等领域的一个开 ...

  2. Activiti就是这么简单

    Activiti介绍 什么是Activiti? Activiti5是由Alfresco软件在2010年5月17日发布的业务流程管理(BPM)框架,它是覆盖了业务流程管理.工作流.服务协作等领域的一个开 ...

  3. activiti工作流框架简介

    常见的工作流框架:activiti, JBPM, OSWorkflow activiti框架基于23张基础的表数据, 基于Mybatis操作数据库. JBPM框架基于18张基础的表数据, 基于hibe ...

  4. Activiti工作流学习-----基于5.19.0版本(5)

    五.与Spring集成 实际项目中一般都有Spring的身影,与Spring集成使得Activiti的实用性得到提高.activiti和Spring整合需要activiti-spring的jar在类路 ...

  5. 六、activiti工作流-流程定义查询

    本节主要讲流程定义查询.查询某个流程设计图片并保存到本地中.查询最新版本的流程定义集合.删除所有key相同的定义 先创建一个java类 package com.java.procdef; import ...

  6. activiti整合开发实例总结

    参考手册:http://www.mossle.com/docs/activiti/ 一.applicationContext.xml中引入activiti相关配置的xml文件 <!-- begi ...

  7. Project Management Process

    Project Management ProcessDescription .............................................................. ...

  8. jbpm 6 vs activities 5评估(持续更新、亲测实际项目评估)

    最近我们有个使用了jbpm 6.2(6.2是一个较大的里程碑)的批处理模块,因为大BOSS一直觉得太重了,希望有更加轻量级的解决方案,因为我们基本上没有真正意义上流程的概念,只有静态的流程图,因为一直 ...

  9. 2017.11.2 Talk to customers for an hour

    yesterday::: Hi Huang, For the better performance of the test the Con 6 should be connected all the ...

随机推荐

  1. 【知识碎片】getResource和getResourceAsStream

    1. 前言 在Java中获取资源的时候,经常用到getResource和getResourceAsStream,本文总结一下这两种获取资源文件的路径差异. 2.Class.getResource(St ...

  2. Excel中concatenate函数的使用方法

    你还在为Excel中concatenate函数的使用方法而苦恼吗,今天小编教你Excel中concatenate函数的使用方法,让你告别Excel中concatenate函数的使用方法的烦恼. 经验主 ...

  3. PHP开发小技巧①①—php实现手机号码显示部分

    从个人信息保护性的角度来讲,我们在开发过程中总会想办法去保护用户的一些个人信息.就如本篇博文所讲,我们有时会将用户的手机号码只显示出部分,这是很多网站都有做的功能.这个功能实现起来也是特别的简单,只需 ...

  4. (2)free详解 (每周一个linux命令系列)

    (2)free详解 (每周一个linux命令系列) linux命令 free详解 引言:今天的命令是用来看内存的free free 换一个套路,我们先看man free中对free的描述: Displ ...

  5. 转载 js函数声明和函数表达式

    在js中函数有两种表达方式.1 函数声明 2 函数表达式 函数声明 function sayname(){ alert("li lei"); } 函数表达式 var sayname ...

  6. 分布式爬虫之elasticsearch基础6(bluk)

    上篇文章介绍了在es里面批量读取数据的方法mget,本篇我们来看下关于批量写入的方法bulk. bulk api可以在单个请求中一次执行多个索引或者删除操作,使用这种方式可以极大的提升索引性能. bu ...

  7. web测试工具列表

    ab.webbench,siege,loadrunner(专业的测试软件可形成图表.) 推荐使用ab测试. tcp并发测试: c1000k

  8. 深入浅出的webpack构建工具---tree shaking打包性能优化(十二)

    阅读目录 1. 什么是tree-shaking? 2. 在webpack中如何使用 tree-shaking 呢? 3. 使用webpack-deep-scope-plugin 优化 回到顶部 1. ...

  9. vue-resource get/post请求如何携带cookie的问题

    vue-resource get/post请求如何携带cookie的问题 当我们使用vue请求的时候,我们会发现请求头中没有携带cookie传给后台,我们可以在请求时添加如下代码:vue.http.o ...

  10. ARM汇编语言基础

    ARM 与 Thumb 寄存器对应关系 PC寄存器: ARM状态为R15,Thumb状态为PC LR寄存器: ARM状态为R14,Thumb状态为LR SP寄存器: ARM状态为R13,Thumb状态 ...