【问题标题】:How can I use dataObject inside serviceTask in a BPMN如何在 BPMN 中的服务任务中使用数据对象
【发布时间】:2022-11-08 20:27:59
【问题描述】:

我正在处理一个具有 dataObject 和一些 serviceTasks 的 BPMN 文件。我想检查 serviceTask 变量是否存在于 dataObject 中。如果存在,则应跳过服务任务。所以,我正在使用 skipExpressions 来实现这一点。

这是示例 BPMN:

<process id="TASK_FLOW_TESTING" name="TASK_FLOW_TESTING" isExecutable="true">
<dataObject id="optionalInputList" name="optionalInputList">
       <extensionElements>
           <flowable:value>
                   ["input1","input2"]
           </flowable:value>
       </extensionElements>
   </dataObject>
<dataObject id="_ACTIVITI_SKIP_EXPRESSION_ENABLED" name="_ACTIVITI_SKIP_EXPRESSION_ENABLED" itemSubjectRef="xsd:boolean">
  <extensionElements>
    <flowable:value>true</flowable:value>
  </extensionElements>
</dataObject>
  <serviceTask id="REFRESH_TASK" name="REFRESH_TASK" flowable:async="true" skipExpression="/*something should be here*/" flowable:triggerable="true" flowable:class="com.delegates.customDelegate">
     <extensionElements>
        <flowable:field name="inputData">
           <flowable:string>["input1"]</flowable:string>
        </flowable:field>
        <flowable:field name="outputDataConfig">
           <flowable:string>["output1"]</flowable:string>
        </flowable:field>
     </extensionElements>
  </serviceTask>

如果我的 input1 存在于 dataObject 的 optionalInputList 中,我想跳过刷新任务。 我可以在 BPMN 中实现这一点吗?

【问题讨论】:

    标签: bpmn flowable


    【解决方案1】:

    为了启用跳过表达式,您需要将_ACTIVITI_SKIP_EXPRESSION_ENABLED 字段设置为true 作为变量。您已通过使用 bpmn20.xml 中演示的变量定义一个 dataObject 来正确完成此操作。 (奇怪的是,在撰写此答案时,流动文档 v6.7.2 中的任何地方都没有提到这一点)

    接下来,您的 skip_expression 与 flowable 中的任何其他表达式一样,都需要一个真或假的结果,并在您的服务任务之前进行评估执行表达式,代表表达式,班级ETC..我已经定义了 skip_expression 以在 Spring Bean 中执行一个方法,该方法返回 true(已跳过任务)或 false(已执行任务)

    <serviceTask id="sid-80A94367-049B-4851-BD97-DC1A368DAB9F" name="Some service" flowable:expression="${serviceTaskBean.execute(execution)}" flowable:skipExpression="${serviceTaskBean.skipExpressionLogic(optionalInputList)}"></serviceTask>
    

    其中方法的输入是您的 optionalInputList dataObject 的值

    服务任务 Bean:

    public class ServiceTaskBean {
    
        public void execute(DelegateExecution execution) {
            //some service execution logic executed only if the 
            //skipExpressionLogic method below returns false
    
        }
        public boolean skipExpressionLogic(String optionalInputList) {
            try {
                //The values set in your dataObject appears in 
                 //optionalInputList
                if(optionalInputList.contains("input1")) {
                    return true; //task skipped
                }
                else {
                    return false; //task executed
                }
    
            }catch(Exception e) {
                e.printStackTrace();
            }
        return false;
        }
    }
    

    有关在此处使用表达式的更多信息:https://www.flowable.com/open-source/docs/bpmn/ch04-API#expressions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-14
      • 2016-10-23
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多