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. Semaphore实现的生产者消费者程序

    Semaphore:Semaphores are often used to restrict the number of threads than can access some (physical ...

  2. Arduino IDE for ESP8266 项目云盒子(4)组网

  3. log4j2的环境变量使用

    官方文档  http://logging.apache.org/log4j/2.x/manual/lookups.html#EnvironmentLookup

  4. PAT A1145 Hashing - Average Search Time (25 分)——hash 散列的平方探查法

    The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...

  5. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  6. char.IsLetter的使用

    先看一下下面的代码,大家会觉得控制台输出什么? 输出:Chiantxt  .对吗? 因为你看到char.IsLetter这个方法的文字的注释是这样写的: 但实际上输出的结果是这样的: ??? 怎么还输 ...

  7. python descriptor 详解

    descriptor简介 在python中,如果一个新式类定义了__get__, __set__, __delete__方法中的一个或者多个,那么称之为descriptor.descriptor有分为 ...

  8. IDC Digital Transition Annual Festival(2018.10.19)

    时间:2018.10.19地点:北京万达文化酒店

  9. SpringMVC之单/多文件上传

    1.准备jar包(图标所指必备包,其他按情况导入) 2.项目结构 3.SingleController.java(控制器代码单文件和多文件) package com.wt.uplaod; import ...

  10. 51Nod 1443 路径和树

    还是一道很简单的基础题,就是一个最短路径树的类型题目 我们首先可以发现这棵树必定满足从1出发到其它点的距离都是原图中的最短路 换句话说,这棵树上的每一条边都是原图从1出发到其它点的最短路上的边 那么直 ...