ProcessEventListener中的访问节点变量 [英] Access node variables in ProcessEventListener

查看:96
本文介绍了ProcessEventListener中的访问节点变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新版本的6.2,它是JBPM的新手.我正在尝试建立一个过程,通过该过程,无论何时打开某些(自定义)任务类型,都可以调用旧平台的REST API,并在将来某个时候完成这些任务时,通过异步过程再次调用.

Fairly new to JBPM, using latest version of 6.2. I am trying to establish a process by which I can make a calls to a REST API for a legacy platform whenever certain (custom) task types are opened and again via an asynch process when they are completed at some point in the future.

总的来说,该过程应类似于:

At a high level the process should be something like:

旧版应用程序->(REST)JBPM"StartProcess"->(REST)旧版应用程序创建任务A"

Legacy App -> (REST) JBPM "StartProcess" -> (REST) Legacy App "Task A Created"

旧版应用程序->(REST)JBPM完成任务A"->(REST)旧版应用程序任务A已完成"&旧版应用(REST)任务B已创建"

Legacy App -> (REST) JBPM "Complete Task A" -> (REST) Legacy App "Task A Completed" & Legacy App (REST) "Task B Created"

我已经创建并注册了一个ProcessEventListener,并在AfterNodeTriggered事件中创建了一个钩子,以调用某种类型的节点.我还创建了一个自定义WorkItem定义,并添加了可以在注册的WorkItemHandler中访问的参数.我遇到的问题是,我需要我的ProcessEventListener来检索我的WorkItem的每个实例的唯一ID(从旧版应用程序中),并将其附加到该WorkItem上,然后再调用WorkItemHander.我可以通过访问getParameter('key')在完成WorkItem的同时在WorkItemHandler中执行此操作,但是我无法确定ProcessEventListener中的方式(或是否可行).

I have created and registered a ProcessEventListener and have created a hook in the AfterNodeTriggered event to make a call for nodes of a certain type. I have also created a custom WorkItem definition and added parameters which I can access in my registered WorkItemHandler. The issue I have is that I need my ProcessEventListener to retrieve a unique ID per instance (from the Legacy App) of my WorkItem and attach it to that WorkItem prior to the WorkItemHander being invoked. I can do this in the WorkItemHandler while completing the WorkItem by accessing the getParameter('key'), but I cannot determine how (or if this is possible) in a ProcessEventListener.

我可以(怎么做):

  1. 在ProcessEventListener中访问工作项(或用户任务)的参数
  2. 确定ProcessEventListener中的节点类型(例如MyCustomTask与用户任务"),以便仅对MyCustomTask调用此服务调用.我可以获取节点'event.getNodeInstance().getNode()',但是我无法确定节点类型是什么.
  3. 如果远程服务上有任何错误,请防止创建我的CustomTask(回滚到触发节点?).

我非常确定答案是,我应该在需要时使用abortWorkItem()在WorkItemHandler中执行这两个请求,但是我无法确定如何作为WorkItemHandler解决方案的一部分处理相应的异步过程.

I am fairly certain the answer is that I should be doing both of these requests in the WorkItemHandler using abortWorkItem() as necessary, but I cannot determine how I handle the corresponding asynch process as part of a WorkItemHandler solution.

请提前感谢您的反馈!

推荐答案

有很多问题,但是我会解决的.

That is a lot of questions but I'll give it a go.

是的,但仅在执行后不能满足您的要求.但是这里还是:

Yes, but only after its execution which does not address your requirement. But here it is nevertheless:

public void afterNodeTriggered(ProcessNodeTriggeredEvent event){
......
  WorkItemNodeInstance wini=(WorkItemNodeInstance)event.getNodeInstance();
  wini.getWorkItem().getParameters()
.....

WorkItemNode node = (WorkItemNode)event.getNodeInstance().getNode();
if(node.getWork().getName().equals("MyCustomTask"){
  .....
}else if(node.getWork().getName().equals("Human Task"){
  ......
}

是的,但是如前所述,ProcessEventListener可能不是理想的地方.这不是为胆小者准备的,但是您始终可以在启动任何过程之前,在安装代码中的某个位置提供自己的WorkItemNodeInstance实现,例如:

Yes, but as mentioned before, the ProcessEventListener is perhaps not the ideal place. This is not for the faint-hearted but you can always provide your own implementation of the WorkItemNodeInstance somewhere in your setup code, BEFORE any process is started, like so:

NodeInstanceFactoryRegistry.INSTANCE.register( WorkItemNode.class,new CreateNewNodeFactory( MyCustomWorkItemNodeInstance.class ) );

然后,您可能想覆盖internalTrigger方法,根据您的要求,该方法可能看起来像这样:

Then you may want to override the internalTrigger method, which, depending on your requirements may look something like this:

public void internalTrigger(final NodeInstance from, String type) {
    try{
     /*my special custom code*/
        ....
        super.internalTrigger(from, type);
    }catch(MySpecialRemoteException e){
     /*my special custom exception handling*/
    }

根据您的要求,您可能还必须添加一个自定义ProcessInstanceMarshaller以确保持久性进程实例化您的NodeInstance而不是默认实例,因此它确实很棘手,但这是可行的:

Depending on your requirements you may also have to add a custom ProcessInstanceMarshaller to ensure persistent processes instantiate your NodeInstance and not the default one, so it does get tricky, but it is doable:

ProcessMarshallerRegistry.INSTANCE.register(RuleFlowProcess.RULEFLOW_TYPE, new MyRuleflowProcessInstanceMarshaller());

这篇关于ProcessEventListener中的访问节点变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆