ActivityWorkflow工作流引擎修改分配使用者觸發監聽事件的Bug處理思路
阿新 • • 發佈:2018-11-08
Activity Workflow修改流程處理人的bug,流程裡配置了assignment監聽。
修改稽核人,業務程式碼裡面需要呼叫工作流的taskService.setAssignee(String taskId, String userId)方法。
這個方法內部是命令模式,最終執行到TaskEntity.setAssignee(String assignee, boolean dispatchAssignmentEvent, boolean dispatchUpdateEvent)
public void setAssignee(String assignee, boolean dispatchAssignmentEvent, boolean dispatchUpdateEvent) { CommandContext commandContext = Context.getCommandContext(); if (assignee==null && this.assignee==null) { // ACT-1923: even if assignee is unmodified and null, this should be stored in history. if (commandContext!=null) { commandContext .getHistoryManager() .recordTaskAssigneeChange(id, assignee); } return; } this.assignee = assignee; // if there is no command context, then it means that the user is calling the // setAssignee outside a service method. E.g. while creating a new task. if (commandContext!=null) { commandContext .getHistoryManager() .recordTaskAssigneeChange(id, assignee); if (assignee != null && processInstanceId != null) { getProcessInstance().involveUser(assignee, IdentityLinkType.PARTICIPANT); } if(!StringUtils.equals(initialAssignee, assignee)) { fireEvent(TaskListener.EVENTNAME_ASSIGNMENT); initialAssignee = assignee; } if(commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { if(dispatchAssignmentEvent) { commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_ASSIGNED, this)); } if(dispatchUpdateEvent) { commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, this)); } } } }
跟蹤原始碼發現28~31行,會判斷分配的人是不是原來的人,如果有變更,不是原來的人,就重新觸發assginment事件。
這就是為什麼修改稽核人會觸發流程節點的assingment事件的原因。
既然工作流程式碼裡面這樣寫了,在assingment事件的實現裡面就不能建立問題跟蹤之類的資訊,否則每改一次,都會生成一個新的。
節點建立最適合用的監聽事件是create。這樣修改的時候,重新assign就不會觸發監聽。