今天对iMatrix平台中子流程中的事件处理研究所得几点,分享给大家:
获得子流程实体的spring bean
当子流程的表单为标准表单时,子表单对应的实体实例是流程引擎通过回调该bean获得的。这里的bean必须实现接口com.norteksoft.wf.engine.client.OnStartingSubProcess
进入子流程前spring bean
开始子流程前回调该bean。如果该bean不存在,则直接启动子流程;如果该bean存在,则调用该bean的isIntoSubProcess ()方法。如果该方法返回true,启动子流程;如果该方法返回false,不进入启动子流程,主流程将跳过子流程继续向下执行。这里的bean必须实现接口com.norteksoft.wf.engine.client.BeforeStartSubProcess
子流程结束后返回时的spring bean
当子流程结束返回主流程时,流程引擎将回调该bean。这里的bean必须实现接口com.norteksoft.wf.engine.client.AfterSubProcessEnd。
1 子流程实现是使用了jbpm的custom节点,如下:
<custom name="子流程" g="191,243,80,40" class="com.norteksoft.wf.engine.core.SubProcessService">
… … … …
</custom>
2 当走到该节点时根据jbpm对custom的处理,会自动调用com.norteksoft.wf.engine.core.SubProcessService中的execute方法,同时给jbpm信号,等待子流程结束,当子流程结束时在给主流程继续流转的信号,如下:
红色字体代码段为:获得执行的bean名称、获得spring容器中的bean、执行该bean中的方法。
”进入子流程前”的处理实现:
public void execute(ActivityExecution execution) throws Exception {
… … … …
String beforeStartSubProcessName = DefinitionXmlParse.getBeforeStartSubProcess(subprocessParse.getParentDefinitionId(),subprocessParse.getActivityName());
log.info("实现类的beforeStartSubProcessName:"+beforeStartSubProcessName);
BeforeStartSubProcess beforeStartSubProcess = null;
if(StringUtils.isNotEmpty(beforeStartSubProcessName)){
beforeStartSubProcess = (BeforeStartSubProcess)ContextUtils.getBean(beforeStartSubProcessName);
log.debug("beforeStartSubProcess:"+beforeStartSubProcess);
}
if(beforeStartSubProcess==null || beforeStartSubProcess.isIntoSubProcess(parentWorkflow.getDataId())){
… … … …
//给jbpm信号,等待子流程结束
execution.waitForSignal();
}
… … … …
}
“获得子流程实体的spring bean”的处理实现:
com.norteksoft.wf.engine.core.SubProcessService中的execute方法为入口,
public void execute(ActivityExecution execution) throws Exception {
… … … …
taskService.startSubProcessWorkflow(transactor,subprocessParse,null);
… … … …
}
public void startSubProcessWorkflow(Map<TaskTransactorCondition, String> transactor,SubProcessParse subprocessParse,Collection<String> transcators){
… … … …
String beanName = DefinitionXmlParse.getSubProcessBeginning(subprocessParse.getParentDefinitionId(),subprocessParse.getActivityName());
log.info("实现类的beanname:"+beanName);
OnStartingSubProcess beginning = (OnStartingSubProcess)ContextUtils.getBean(beanName);
… … … …
//获得子流程对应的实体
FormFlowable subFormEntity = eginning.getRequiredSubEntity(param);
… … … …
}
“子流程结束后”的处理实现:
当子流程结束时,给主流程继续流转的信号:
com.norteksoft.wf.engine.core. ProcessEndListener中,
public void notify(EventListenerExecution execution) {
… … … …
//设置继续流转的信号
executionService.signalExecutionById(workflow.getParentExcutionId(),transitionName);
… … … …
}
当给了该信号后,会走com.norteksoft.wf.engine.core.SubProcessService中的signal方法,在该方法中处理“子流程结束后”的事件:
public void signal(ActivityExecution execution, String signalName, Map<String, ?> parameters) throws Exception {
… … … …
String subProcessEndName = DefinitionXmlParse.getSubProcessEnd(subprocessParse.getParentDefinitionId (),subprocessParse.getActivityName());
log.info("实现类的subProcessEndName:"+subProcessEndName);
if(StringUtils.isNotEmpty(subProcessEndName)){
AfterSubProcessEnd afterSubProcessEnd = (AfterSubProcessEnd)ContextUtils.getBean(subProcessEndName);
log.info("subProcessEnd:"+afterSubProcessEnd);
if(afterSubProcessEnd!=null) afterSubProcessEnd.execute(parentWorkflow.getDataId());
}
… … … …
}