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 1952cca20d8fc01f57b571ae2effdc8694d006f3..48ec8003c1ea3dc6bd72218cf8e861acddfec82c 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 b38bbc267d9d75406123035cc861d130288c14af..0605e640b22d5e2d685ab6d92fc0ffb3c991a946 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 7d6782b55214a6791f53c7310e495eedfdc3f099..87ac8b08748dd868efc9a5170a9ea189a1875bd8 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 5980fb506ec4542160f0bed79c72b3d96bb64544..955622b87e73cef3d7f43bbb23975e9e88670c45 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 7d6782b55214a6791f53c7310e495eedfdc3f099..87ac8b08748dd868efc9a5170a9ea189a1875bd8 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 52e7dca0e2103d82772b3167966ba38e6b34bd1f..fe9afd578413668d930b1f05ad064d37fdd259ba 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 2582574aa7990c30345525a2bce2f5c758957c91..ac7dbad32e4713d30923c3aa35a4f1c1cb5013d4 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 52e7dca0e2103d82772b3167966ba38e6b34bd1f..fe9afd578413668d930b1f05ad064d37fdd259ba 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 07662386846f95ec665f524bcdaccf81c361890c..8a4d18bff95862ff423c6f5400921f78275985fe 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 74110bacf69ffef74f2eb1c2c6dd8dc9bd6246ea..380f5c6b5ff91240460c3f3538aa3f4d44bcb670 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