Activiti> bpmn:无法使用变量动态分配候选组

时间:2016-05-26 06:28:52

标签: java liferay activiti bpmn

我正在从liferay运行activiti。 我正在尝试为用户任务动态设置候选组,我尝试过以下解决方案,这些解决方案无效。 这适用于liferay 6.2 CE GA6和activiti版本5.18.0 如果我错过了什么或者你有更好的解决方案,请告诉我。

解决方案1: 它涉及使用proccess变量为用户任务设置候选组。 下面是bpmn代码:

<userTask id="Review" name="Review"  activiti:candidateGroups=${assignee}>
  <extensionElements>
    <activiti:formProperty id="outputTransition" name="output Transition" type="enum">
      <activiti:value id="Approve" name="Approve"></activiti:value>
      <activiti:value id="Reject" name="Reject"></activiti:value>
    </activiti:formProperty>
  </extensionElements>
</userTask>

这里,受让人是已经设定的过程变量。

执行工作流程时,我遇到以下异常:

13:42:01,326 INFO  [http-bio-8080-exec-10][LiferayGroupsUtil:54] Convert    groups : [ ${assignee} ]
13:42:01,329 WARN  [http-bio-8080-exec-10][LiferayGroupsUtil:94] Cannot assign task to role ${assignee} com.liferay.portal.NoSuchRoleException: No Role exists with the key {companyId=20155, name=${assignee}}

解决方案2:

我也试过下面的xml代码,但我仍然得到同样的异常: 在这里,我有multiInstanceLoopCharacteristics。

<userTask id="Review" name="Review"  activiti:candidateGroups=${assignee}>
    <multiInstanceLoopCharacteristics isSequential="false" 
     activiti:collection="candidateGrp" activiti:elementVariable="assignee" >
    <completionCondition>${nrOfCompletedInstances/nrOfInstances >= 0.6 }</completionCondition>
  </multiInstanceLoopCharacteristics>
  <extensionElements>
    <activiti:formProperty id="outputTransition" name="output Transition" type="enum">
      <activiti:value id="Approve" name="Approve"></activiti:value>
      <activiti:value id="Reject" name="Reject"></activiti:value>
    </activiti:formProperty>
  </extensionElements>
</userTask>

解决方案3:

我还尝试使用DynamicBpmnService动态设置候选组,请检查以下代码: 对于这种方法,我使用了activiti版本5.19.0 我从liferay&gt;替换了activiti引擎jar。的Tomcat&GT; webapp&gt; activiti-web&gt; web-inf&gt; lib

@Override
public void notify(DelegateExecution execution) {
    try {
    EngineServices engineServices = execution.getEngineServices();
    DynamicBpmnService dynamicBpmnService = engineServices.getDynamicBpmnService();
    ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateGroup(
              "Review", "Power User", false);
    dynamicBpmnService.saveProcessDefinitionInfo("procDefId", infoNode);
    System.out.println("------saveProcessDefinitionInfo------=saved");

    } catch (Exception e) {
        System.out.println("------error");
        e.printStackTrace();
    }
    List<String> list = new ArrayList<String>();
    list.add("Power User");
    execution.setVariable("candidateGrp",list);
}

我在执行此代码时遇到异常:

WARN  [http-bio-8080-exec-10][ProxyMessageListener:81] org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause:  com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:  Cannot add or update a child row: a foreign key constraint fails (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))
### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity.insertProcessDefinitionInfo-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_PROCDEF_INFO(ID_, PROC_DEF_ID_, REV_, INFO_JSON_ID_)     values(?,             ?,            1,            ?)
### Cause:  com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:  Cannot add or update a child row: a foreign key constraint fails  (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY  (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))
org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))
### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity.insertProcessDefinitionInfo-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_PROCDEF_INFO(ID_, PROC_DEF_ID_, REV_, INFO_JSON_ID_)     values(?,             ?,            1,            ?)
### Cause:  com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))

我真的无法继续。 你的快速帮助将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:0)

Try this:

Process:

<userTask id="review" name="Review" >
  <extensionElements>
    <activiti:taskListener event="create" class="org.activiti.MyDynamicGroupHandler" />
  </extensionElements>
</userTask>

Listener:

public class MyDynamicGroupHandler implements TaskListener {

  public void notify(DelegateTask delegateTask) {

    String assigneeGroup = 'Reviewer'
    ...
    // business logic to set correct assigneeGroup
    ...
    // set candidate group dynamically 
    delegateTask.addCandidateGroup(assigneeGroup); // 
    ...
  }

}

Spring framework example:

myListener is defined in spring bean context.

<bean id="myListener" class="org.activiti.MyDynamicGroupHandler"/>

Process:

<userTask id="review" name="Review">
  <extensionElements>
    <activiti:taskListener event="create" expression="${myListener.setCandidateGroup(task, assigneeGroup)}" />
  </extensionElements>
</userTask>

Listener:

public class MyDynamicGroupHandler {

  public void setCandidateGroup(DelegateTask delegateTask, String assigneeGroup) {
    // set candidate group dynamically 
    delegateTask.addCandidateGroup(assigneeGroup); // 
    ...
  }

}