Activiti5.22 创建全局的连线监听器
有时候我们想在连线处处理一些逻辑,比如在连线处设置任务的办理入参数
如果我们的流程图非常复杂,那么我们可以按照如下的方法进行处理
1,重写SequenceFlowParseHandler类的executeParse方法;
2,拿到transitionImpl为其设置监听
3,重新注入这个类即可
完整的参考代码如下
public class ConfigPersionFlowListener extends SequenceFlowParseHandler {
@Override
protected void executeParse(BpmnParse bpmnParse, SequenceFlow sequenceFlow) {
ScopeImpl scope = bpmnParse.getCurrentScope();
ActivityImpl sourceActivity = scope.findActivity(sequenceFlow.getSourceRef());
ActivityImpl destinationActivity = scope.findActivity(sequenceFlow.getTargetRef());
if(destinationActivity.getId().indexOf("usertask3")>=0||destinationActivity.getId().indexOf("usertask1")>=0) {
TransitionImpl transitionImpl = sourceActivity.createOutgoingTransition(sequenceFlow.getId());
bpmnParse.getSequenceFlows().put(sequenceFlow.getId(), transitionImpl);
transitionImpl.setProperty("name",sequenceFlow.getName());
transitionImpl.setProperty("documentation",sequenceFlow.getName());
transitionImpl.setDestination(destinationActivity);
ExecutionListener executionListeners = new ExecutionListener() {
/**
* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
*/
private static final long serialVersionUID = 1L;
@Override
public void notify(DelegateExecution execution) throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("uname", "likilone");
map.put("uname2", "heyou");execution.setVariables(map);
System.out.println(execution.getVariables().get("ppp"));
System.out.println(execution.getVariables().get("ppp1"));
}
};
List<ExecutionListener> list = new ArrayList<ExecutionListener>();
list.add(executionListeners);
transitionImpl.setExecutionListeners(list);
createExecutionListenersOnTransition(bpmnParse, sequenceFlow.getExecutionListeners(), transitionImpl);
}else {
super.executeParse(bpmnParse, sequenceFlow);
}
}以上代码为我测试代码,大家可自行测试
最后我们在配置文件里面注入这个类即可
爆款云服务器s6 2核4G 低至0.46/天,具体规则查看活动详情