2017-02-15 34 views
0

根据Potts先生亲切提供的example,我开发了合同批准系统。如何正确声明,更改和使用工作流程变量?

下面介绍BPMN表示法中的业务流程。

通过Activiti Eclipse BPMN 2.0 Designer

enter image description here

正在运行的业务流程的露天的方案:

enter image description here

要创建我用的Activiti Eclipse的BPMN 2.0设计者5.18 Activiti的图。这里是一个由该插件生成过程的描述:

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"> 
    <process id="contractsApproval" name="Contracts Approval" isExecutable="true"> 
    <startEvent id="startevent1" name="Start" activiti:formKey="scwf:submitReviewTask"></startEvent> 
    <endEvent id="endevent1" name="End"></endEvent> 
    <userTask id="usertask1" name="Approval of the first group" activiti:candidateGroups="GROUP_First" activiti:formKey="scwf:activitiFirstReview"> 
     <extensionElements> 
     <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"> 
      <activiti:field name="script"> 
      <activiti:string><![CDATA[if(task.getVariableLocal('scwf_approveRejectOutcome') == 'Approve') { 
          var newApprovedCount = scwf_approveCount + 1; 
          execution.setVariable('scwf_approveCount', newApprovedCount); 
         }]]></activiti:string> 
      </activiti:field> 
     </activiti:taskListener> 
     </extensionElements> 
    </userTask> 
    <userTask id="usertask3" name="Revise" activiti:assignee="${initiator.properties.userName}" activiti:formKey="scwf:activitiRevise"> 
     <extensionElements> 
     <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"> 
      <activiti:field name="script"> 
      <activiti:string><![CDATA[if(task.getVariableLocal('scwf_reviseOutcome') == 'Re-submit') { 
        execution.setVariable('scwf_resubmit', true); 
        } else { 
        execution.setVariable('scwf_resubmit', false); 
        }]]></activiti:string> 
      </activiti:field> 
     </activiti:taskListener> 
     </extensionElements> 
    </userTask> 
    <userTask id="usertask4" name="Approval of the second group" activiti:candidateGroups="GROUP_Second" activiti:formKey="scwf:activitiSecondReview"> 
     <extensionElements> 
     <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"> 
      <activiti:field name="script"> 
      <activiti:string><![CDATA[if(task.getVariableLocal('scwf_approveRejectOutcome') == 'Approve') { 
          var newApprovedCount = scwf_approveCount + 1; 
          execution.setVariable('scwf_approveCount', newApprovedCount); 
         } 
     ]]></activiti:string> 
      </activiti:field> 
     </activiti:taskListener> 
     </extensionElements> 
    </userTask> 
    <serviceTask id="scripttask1" name="Send a document for approval" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate"> 
     <extensionElements> 
     <activiti:field name="runAs"> 
      <activiti:string><![CDATA[admin]]></activiti:string> 
     </activiti:field> 
     <activiti:field name="script"> 
      <activiti:string><![CDATA[execution.setVariable('scwf_approveCount', 0); 
      execution.setVariable('scwf_tpApproved', false);]]></activiti:string> 
     </activiti:field> 
     </extensionElements> 
    </serviceTask> 
    <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway> 
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway> 
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway> 
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="scripttask1"></sequenceFlow> 
    <sequenceFlow id="flow2" sourceRef="scripttask1" targetRef="parallelgateway1"></sequenceFlow> 
    <sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="usertask1"></sequenceFlow> 
    <sequenceFlow id="flow4" sourceRef="parallelgateway1" targetRef="usertask4"></sequenceFlow> 
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="parallelgateway2"></sequenceFlow> 
    <sequenceFlow id="flow6" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow> 
    <sequenceFlow id="flow7" sourceRef="parallelgateway2" targetRef="exclusivegateway1"></sequenceFlow> 
    <sequenceFlow id="flow9" sourceRef="exclusivegateway1" targetRef="usertask3"> 
     <conditionExpression xsi:type="tFormalExpression"><![CDATA[${scwf_approveCount < 2}]]></conditionExpression> 
    </sequenceFlow> 
    <sequenceFlow id="flow13" sourceRef="usertask3" targetRef="scripttask1"> 
     <conditionExpression xsi:type="tFormalExpression"><![CDATA[${scwf_resubmit == true}]]></conditionExpression> 
    </sequenceFlow> 
    <userTask id="usertask5" name="Approved Notification" activiti:assignee="${initiator.properties.userName}" activiti:formKey="scwf:activitiApprovedNotification"> 
     <extensionElements> 
     <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"> 
      <activiti:field name="script"> 
      <activiti:string><![CDATA[var setWebFlagAction = actions.create("set-web-flag"); 
         setWebFlagAction.parameters["active"] = true; 
         for (var i = 0; i < bpm_package.children.length; i++) { 
          logger.log("Approving node:" + bpm_package.children[i].nodeRef); 
          setWebFlagAction.execute(bpm_package.children[i]); 
         }]]></activiti:string> 
      </activiti:field> 
     </activiti:taskListener> 
     </extensionElements> 
    </userTask> 
    <sequenceFlow id="flow15" sourceRef="usertask5" targetRef="endevent1"></sequenceFlow> 
    <sequenceFlow id="flow16" sourceRef="usertask3" targetRef="endevent1"> 
     <conditionExpression xsi:type="tFormalExpression"><![CDATA[${scwf_resubmit == false}]]></conditionExpression> 
    </sequenceFlow> 
    <sequenceFlow id="flow17" sourceRef="exclusivegateway1" targetRef="usertask5"></sequenceFlow> 
    </process> 
    <bpmndi:BPMNDiagram id="BPMNDiagram_contractsApproval"> 
    <bpmndi:BPMNPlane bpmnElement="contractsApproval" id="BPMNPlane_contractsApproval"> 
     <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> 
     <omgdc:Bounds height="35.0" width="35.0" x="0.0" y="163.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> 
     <omgdc:Bounds height="35.0" width="35.0" x="790.0" y="164.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"> 
     <omgdc:Bounds height="75.0" width="105.0" x="330.0" y="96.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3"> 
     <omgdc:Bounds height="55.0" width="105.0" x="310.0" y="360.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4"> 
     <omgdc:Bounds height="78.0" width="105.0" x="330.0" y="193.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1"> 
     <omgdc:Bounds height="89.0" width="121.0" x="60.0" y="136.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1"> 
     <omgdc:Bounds height="40.0" width="40.0" x="230.0" y="162.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2"> 
     <omgdc:Bounds height="40.0" width="40.0" x="480.0" y="160.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1"> 
     <omgdc:Bounds height="40.0" width="40.0" x="568.0" y="160.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNShape bpmnElement="usertask5" id="BPMNShape_usertask5"> 
     <omgdc:Bounds height="68.0" width="105.0" x="640.0" y="147.0"></omgdc:Bounds> 
     </bpmndi:BPMNShape> 
     <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> 
     <omgdi:waypoint x="35.0" y="180.0"></omgdi:waypoint> 
     <omgdi:waypoint x="60.0" y="180.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> 
     <omgdi:waypoint x="181.0" y="180.0"></omgdi:waypoint> 
     <omgdi:waypoint x="230.0" y="182.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"> 
     <omgdi:waypoint x="250.0" y="162.0"></omgdi:waypoint> 
     <omgdi:waypoint x="250.0" y="137.0"></omgdi:waypoint> 
     <omgdi:waypoint x="330.0" y="133.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"> 
     <omgdi:waypoint x="250.0" y="202.0"></omgdi:waypoint> 
     <omgdi:waypoint x="250.0" y="233.0"></omgdi:waypoint> 
     <omgdi:waypoint x="330.0" y="232.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"> 
     <omgdi:waypoint x="435.0" y="133.0"></omgdi:waypoint> 
     <omgdi:waypoint x="500.0" y="137.0"></omgdi:waypoint> 
     <omgdi:waypoint x="500.0" y="160.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"> 
     <omgdi:waypoint x="435.0" y="232.0"></omgdi:waypoint> 
     <omgdi:waypoint x="500.0" y="233.0"></omgdi:waypoint> 
     <omgdi:waypoint x="500.0" y="200.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7"> 
     <omgdi:waypoint x="520.0" y="180.0"></omgdi:waypoint> 
     <omgdi:waypoint x="568.0" y="180.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9"> 
     <omgdi:waypoint x="588.0" y="200.0"></omgdi:waypoint> 
     <omgdi:waypoint x="362.0" y="360.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13"> 
     <omgdi:waypoint x="362.0" y="360.0"></omgdi:waypoint> 
     <omgdi:waypoint x="120.0" y="225.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15"> 
     <omgdi:waypoint x="745.0" y="181.0"></omgdi:waypoint> 
     <omgdi:waypoint x="790.0" y="181.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16"> 
     <omgdi:waypoint x="415.0" y="387.0"></omgdi:waypoint> 
     <omgdi:waypoint x="598.0" y="387.0"></omgdi:waypoint> 
     <omgdi:waypoint x="807.0" y="199.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
     <bpmndi:BPMNEdge bpmnElement="flow17" id="BPMNEdge_flow17"> 
     <omgdi:waypoint x="608.0" y="180.0"></omgdi:waypoint> 
     <omgdi:waypoint x="640.0" y="181.0"></omgdi:waypoint> 
     </bpmndi:BPMNEdge> 
    </bpmndi:BPMNPlane> 
    </bpmndi:BPMNDiagram> 
</definitions> 

这里是工作流程的内容模型:

<?xml version="1.0" encoding="UTF-8"?> 
<!-- Definition of new Model --> 
<model name="scwf:workflowModel" 
     xmlns="http://www.alfresco.org/model/dictionary/1.0"> 

    <!-- Optional meta-data about the model --> 
    <description>...</description> 
    <author>...</author> 
    <version>...</version> 

    <!-- Imports are required to allow references to definitions in other models --> 
    <imports> 
     <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" /> 
     <import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm" /> 
    </imports> 

    <!-- Introduction of new namespaces defined by this model --> 
    <namespaces> 
     <namespace uri="http://.../model/workflow/1.0" prefix="scwf" /> 
    </namespaces> 

    <types> 

     <type name="scwf:submitReviewTask"> 
      <parent>bpm:startTask</parent> 
     </type> 

     <type name="scwf:activitiFirstReview"> 
      <parent>scwf:activitiReviewTask</parent> 
     </type> 

     <type name="scwf:activitiSecondReview"> 
      <parent>scwf:activitiReviewTask</parent> 
     </type> 

     <type name="scwf:activitiRevise"> 
      <parent>bpm:activitiOutcomeTask</parent> 
      <properties> 
       <property name="scwf:reviseOutcome"> 
        <type>d:text</type> 
        <default>Abort</default> 
        <constraints> 
         <constraint type="LIST"> 
          <parameter name="allowedValues"> 
           <list> 
            <value>Re-submit</value> 
            <value>Abort</value> 
           </list> 
          </parameter> 
         </constraint> 
        </constraints> 
       </property> 
      </properties>    
      <overrides> 
       <property name="bpm:packageItemActionGroup"> 
        <default>edit_package_item_actions</default> 
       </property> 
       <property name="bpm:outcomePropertyName"> 
        <default>{http://.../model/workflow/1.0}reviseOutcome</default> 
       </property> 
      </overrides> 
     </type> 

     <type name="scwf:activitiReviewTask"> 
      <parent>bpm:activitiOutcomeTask</parent> 
      <properties> 
       <property name="scwf:approveRejectOutcome"> 
        <type>d:text</type> 
        <default>Reject</default> 
        <constraints> 
         <constraint type="LIST"> 
          <parameter name="allowedValues"> 
           <list> 
            <value>Approve</value> 
            <value>Reject</value> 
           </list> 
          </parameter> 
         </constraint> 
        </constraints> 
       </property> 
      </properties>    
      <overrides> 
       <property name="bpm:packageItemActionGroup"> 
        <default>read_package_item_actions</default> 
       </property> 
       <property name="bpm:outcomePropertyName"> 
        <default>{http://.../model/workflow/1.0}approveRejectOutcome</default> 
       </property> 
      </overrides> 
     </type> 

     <type name="scwf:activitiApprovedNotification"> 
      <parent>bpm:workflowTask</parent> 
      <overrides> 
       <property name="bpm:packageItemActionGroup"> 
        <default>read_package_item_actions</default> 
       </property> 
      </overrides>    
     </type> 
    </types> 
</model> 

在我的本地计算机上安装:

露天Share v5.2.d(r134641-b15,Aikau 1.0.101.3,Spring Surf 5.2.d,Spring WebScripts 6.13,Freemarker 2.3.20-露天补丁,Rhino 1.7R4露天补丁,Yui 2.9.0-alfresco -20141223)

露天社区V5.2.0(r134428-B13)架构10005

,一切工作正常...

然而,当我安装系统的服务器,上发生的问题,即:

露天分享v5.2.c(r133673-B12,Aikau 1.0.99,春冲浪5.2.c, 春WebScripts 6.11,Freemarker的2.3.20-露天打补丁,犀牛 1.7R4,露天打补丁,Yui 2.9.0-alfresco-20141223)

露天社区V5.2.0(r133656-B12)架构10005

在审批的过程中,我得到这个错误信息:

org.activiti.engine.ActivitiException:未知属性在 表达式中使用:$ {scwf_approveCount < 2}

NB:将出现错误只有在下一组处理之后(无论是第一个还是第二个) - 例如,如果合同批准/被第一组拒绝,那么第二组既不能批准也不能拒绝。

门户ecmarchitect说:

“你可能会奇怪,为什么这是一个服务任务,而不是一个脚本任务在5.0.d,在Activiti的底层JavaScript引擎从犀牛切换到犀牛。这导致了与设置执行变量相关的问题。解决方法是使用一个服务任务“

,并显示了如何初始化变量的例子:

<serviceTask id="scripttask1" name="Submit" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate"> 
    <extensionElements> 
    <activiti:field name="script"> 
     <activiti:string><![CDATA[execution.setVariable('scwf_approveCount', 0); 
      execution.setVariable('scwf_tpApproved', false);]]></activiti:string> 
    </activiti:field> 
    </extensionElements> 
</serviceTask> 

我发现这个多次讨论,但没有在其中描述的方法没帮助我的情况:

例如,我试图通过这些方式来初始化变量:

... 

<scriptTask id="scripttask1" name="Submit" scriptFormat="javascript" activiti:autoStoreVariables="true"> 
    <script>var scwf_approveCount = 0; var scwf_tpApproved = false;</script> 
</scriptTask> 

... 

<scriptTask id="scripttask1" name="Submit" scriptFormat="javascript"> 
<script><![CDATA[var scwf_approveCount = 0; var scwf_tpApproved = 
false;]]></script> 
</scriptTask> 

... 

<scriptTask id="scripttask1" name="Submit" scriptFormat="javascript" activiti:autoStoreVariables="true"> 
    <script>execution.setVariable('scwf_approveCount', 0); execution.setVariable('scwf_tpApproved', false);</script> 
</scriptTask> 

... 

我认为I N eed在服务器上重新安装Alfresco以匹配本地安装。

有没有解决这个问题的另一种方法?我将非常感激这些信息。谢谢大家。


其他信息:我安装了完全相同的系统。在服务器和我的本地计算机上:

露天分享v5.2.d(r134641-B15,Aikau 1.0.101.3,春冲浪 5.2.d,春天WebScripts 6.13,Freemarker的2.3.20-alfresco-打补丁,犀牛1.7R4,露天打补丁,衣2.9.0-露天-20141223)

露天社区V5.2.0(r134428-B13)架构10005

但它是非常奇怪的 - 当地一切正常但在服务器上我再次得到相同的错误:

org.activiti.engine.ActivitiException:在 表达式中使用未知的属性:$ {scwf_approveCount < 2}

我比较了图中和在底层XML数据和它们是相同的。

+0

来自[Axel Faust]的非常有用的信息(https://community.alfresco.com/people/afaust) - [我可以使用工作流模型的前缀作为未映射到内容模型中的流程变量吗?] (HTTPS://community.alfresco。COM /线程/ 228311灿我使用前缀的最工作流模型换的过程变量,也就是说,是 - 未映射功能于该内容模型#带注释808244) –

回答

1

scwf_approveCount您正在使用该属性确保你已经在你的工作流模型文件scwf定义这个属性:approveCount 您正在使用该属性scwf_approveCount,它可能在你的模型文件中没有定义。

+0

非常感谢您的回答!..好主意。明天早上将在办公室进行检查。 –

+0

呃..我查过了。但据我了解,这是过程*的*变量,它并不需要在模型声明...这个变量是通过'execution.setVariable()'调用设置。 –

+0

我的权利。例如,'scwf_approveRejectOutcome'变量映射到了'scwf定义的属性:activitiReviewTask'类型... –