From 5f8c72efbb95985745d40aacd8256e7eca262184 Mon Sep 17 00:00:00 2001 From: Joram Barrez Date: Tue, 3 Oct 2017 15:53:06 +0200 Subject: [PATCH] Fix #587 : event subscriptions should only be deleted when sibling executions are not active --- .../impl/agenda/EndExecutionOperation.java | 48 +++++++++++++++---- .../persistence/entity/ExecutionEntity.java | 21 -------- ...onInterruptingMultipleInstances.bpmn20.xml | 2 +- ...t.testNonInterruptingSubProcess.bpmn20.xml | 2 +- ...erruptingUnderProcessDefinition.bpmn20.xml | 2 +- ...onInterruptingMultipleInstances.bpmn20.xml | 2 +- ...t.testNonInterruptingSubProcess.bpmn20.xml | 2 +- ...erruptingUnderProcessDefinition.bpmn20.xml | 2 +- ...t.testNonInterruptingSubProcess.bpmn20.xml | 2 +- ...erruptingUnderProcessDefinition.bpmn20.xml | 2 +- 10 files changed, 47 insertions(+), 38 deletions(-) diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/agenda/EndExecutionOperation.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/agenda/EndExecutionOperation.java index 1952cca20d..48ec8003c1 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/agenda/EndExecutionOperation.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/agenda/EndExecutionOperation.java @@ -196,8 +196,28 @@ public class EndExecutionOperation extends AbstractOperation { // If there are no more active child executions, the process can be continued // If not (eg an embedded subprocess still has active elements, we cannot continue) - if (getNumberOfActiveChildExecutionsForExecution(executionEntityManager, parentExecution.getId()) == 0 - || isAllEventScopeExecutions(executionEntityManager, parentExecution)) { + List eventScopeExecutions = getEventScopeExecutions(executionEntityManager, parentExecution); + + // Event scoped executions need to be deleted when there are no active siblings anymore, + // unless instances of the event subprocess itself. If there are no active siblings anymore, + // the current scope had ended and the event subprocess start event should stop listening to any trigger. + if (!eventScopeExecutions.isEmpty()) { + List childExecutions = parentExecution.getExecutions(); + boolean activeSiblings = false; + for (ExecutionEntity childExecutionEntity : childExecutions) { + if (!isInEventSubProcess(childExecutionEntity) && childExecutionEntity.isActive() && !childExecutionEntity.isEnded()) { + activeSiblings = true; + } + } + + if (!activeSiblings) { + for (ExecutionEntity eventScopeExecution : eventScopeExecutions) { + executionEntityManager.deleteExecutionAndRelatedData(eventScopeExecution, null); + } + } + } + + if (getNumberOfActiveChildExecutionsForExecution(executionEntityManager, parentExecution.getId()) == 0) { ExecutionEntity executionToContinue = null; @@ -386,18 +406,16 @@ public class EndExecutionOperation extends AbstractOperation { return activeChildExecutions; } - protected boolean isAllEventScopeExecutions(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution) { - boolean allEventScopeExecutions = true; + protected List getEventScopeExecutions(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution) { + List eventScopeExecutions = new ArrayList<>(1); List executions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecution.getId()); for (ExecutionEntity childExecution : executions) { if (childExecution.isEventScope()) { - executionEntityManager.deleteExecutionAndRelatedData(childExecution, null); + eventScopeExecutions.add(childExecution); - } else { - allEventScopeExecutions = false; - } + } } - return allEventScopeExecutions; + return eventScopeExecutions; } protected boolean allChildExecutionsEnded(ExecutionEntity parentExecutionEntity, ExecutionEntity executionEntityToIgnore) { @@ -415,4 +433,16 @@ public class EndExecutionOperation extends AbstractOperation { } return true; } + + protected boolean isInEventSubProcess(ExecutionEntity executionEntity) { + ExecutionEntity currentExecutionEntity = executionEntity; + while (currentExecutionEntity != null) { + if (currentExecutionEntity.getCurrentFlowElement() instanceof EventSubProcess) { + return true; + } + currentExecutionEntity = currentExecutionEntity.getParent(); + } + return false; + } + } diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/ExecutionEntity.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/ExecutionEntity.java index b38bbc267d..0605e640b2 100755 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/ExecutionEntity.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/ExecutionEntity.java @@ -93,9 +93,6 @@ public interface ExecutionEntity extends DelegateExecution, Execution, ProcessIn void setEnded(boolean isEnded); - @Override - void setEventName(String eventName); - String getDeleteReason(); void setDeleteReason(String deleteReason); @@ -108,12 +105,6 @@ public interface ExecutionEntity extends DelegateExecution, Execution, ProcessIn void setEventScope(boolean isEventScope); - @Override - boolean isMultiInstanceRoot(); - - @Override - void setMultiInstanceRoot(boolean isMultiInstanceRoot); - void setName(String name); void setDescription(String description); @@ -128,26 +119,14 @@ public interface ExecutionEntity extends DelegateExecution, Execution, ProcessIn void setLockTime(Date lockTime); - @Override - boolean isDeleted(); - - @Override - void setDeleted(boolean isDeleted); - void forceUpdate(); String getStartActivityId(); void setStartActivityId(String startActivityId); - @Override - String getStartUserId(); - void setStartUserId(String startUserId); - @Override - Date getStartTime(); - void setStartTime(Date startTime); void setCallbackId(String callbackId); diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml index 7d6782b552..87ac8b0874 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml @@ -13,7 +13,7 @@ - + diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml index 5980fb506e..955622b87e 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml @@ -13,7 +13,7 @@ - + diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml index 7d6782b552..87ac8b0874 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/message/MessageEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml @@ -13,7 +13,7 @@ - + diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml index 52e7dca0e2..fe9afd5784 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingMultipleInstances.bpmn20.xml @@ -13,7 +13,7 @@ - + diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml index 2582574aa7..ac7dbad32e 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml @@ -13,7 +13,7 @@ - + diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml index 52e7dca0e2..fe9afd5784 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/signal/SignalEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml @@ -13,7 +13,7 @@ - + diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml index 0766238684..8a4d18bff9 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingSubProcess.bpmn20.xml @@ -11,7 +11,7 @@ - + R3/P1D diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml index 74110bacf6..380f5c6b5f 100644 --- a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testNonInterruptingUnderProcessDefinition.bpmn20.xml @@ -11,7 +11,7 @@ - + P1D -- GitLab