Java Code Examples for org.activiti.engine.impl.interceptor.CommandContext#getExecutionEntityManager()

The following examples show how to use org.activiti.engine.impl.interceptor.CommandContext#getExecutionEntityManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompleteAdhocSubProcessCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Void execute(CommandContext commandContext) {
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  ExecutionEntity execution = executionEntityManager.findById(executionId);
  if (execution == null) {
    throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
  }

  if (execution.getCurrentFlowElement() instanceof AdhocSubProcess == false) {
    throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process");
  }

  List<? extends ExecutionEntity> childExecutions = execution.getExecutions();
  if (childExecutions.size() > 0) {
    throw new ActivitiException("Ad-hoc sub process has running child executions that need to be completed first");
  }

  ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());
  outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());

  executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);

  Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);

  return null;
}
 
Example 2
Source File: ProcessInstanceDiagramCmd.java    From activiti-basic with Apache License 2.0 6 votes vote down vote up
public InputStream execute(CommandContext commandContext) {
    ExecutionEntityManager executionEntityManager = commandContext
        .getExecutionEntityManager();
    ExecutionEntity executionEntity = executionEntityManager
        .findExecutionById(processInstanceId);
    List<String> activiityIds = executionEntity.findActiveActivityIds();
    String processDefinitionId = executionEntity.getProcessDefinitionId();

    GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd(
            processDefinitionId);
    BpmnModel bpmnModel = getBpmnModelCmd.execute(commandContext);

    InputStream is = ProcessDiagramGenerator.generateDiagram(bpmnModel,
            "png", activiityIds);

    return is;
}
 
Example 3
Source File: SetProcessInstanceBusinessKeyCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
    ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
    if (processInstance == null) {
        throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
    } else if (!processInstance.isProcessInstanceType()) {
        throw new ActivitiIllegalArgumentException(
                "A process instance id is required, but the provided id " +
                        "'" + processInstanceId + "' " +
                        "points to a child execution of process instance " +
                        "'" + processInstance.getProcessInstanceId() + "'. " +
                        "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
    }

    processInstance.updateProcessBusinessKey(businessKey);

    return null;
}
 
Example 4
Source File: SetProcessInstanceBusinessKeyCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Void execute(CommandContext commandContext) {
  ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
  ExecutionEntity processInstance = executionManager.findById(processInstanceId);
  if (processInstance == null) {
    throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
  } else if (!processInstance.isProcessInstanceType()) {
    throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'"
        + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
  }
  
  if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {
    commandContext.getProcessEngineConfiguration().getActiviti5CompatibilityHandler().updateBusinessKey(processInstanceId, businessKey);
    return null;
  }

  executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey);

  return null;
}
 
Example 5
Source File: AddIdentityLinkForProcessInstanceCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Void execute(CommandContext commandContext) {

    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity processInstance = executionEntityManager.findById(processInstanceId);

    if (processInstance == null) {
      throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
    }
    
    if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); 
      activiti5CompatibilityHandler.addIdentityLinkForProcessInstance(processInstanceId, userId, groupId, type);
      return null;
    }

    IdentityLinkEntityManager identityLinkEntityManager = commandContext.getIdentityLinkEntityManager();
    identityLinkEntityManager.addIdentityLink(processInstance, userId, groupId, type);
    commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true);

    return null;

  }
 
Example 6
Source File: SetProcessDefinitionVersionCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {
  // check that the new process definition is just another version of the same
  // process definition that the process instance is using
  ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
  ExecutionEntity processInstance = executionManager.findById(processInstanceId);
  if (processInstance == null) {
    throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
  } else if (!processInstance.isProcessInstanceType()) {
    throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'"
        + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
  }
  
  DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();
  ProcessDefinition currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(processInstance.getProcessDefinitionId());

  ProcessDefinition newProcessDefinition = deploymentCache
      .findDeployedProcessDefinitionByKeyAndVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());

  validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);

  // switch the historic process instance to the new process definition version
  commandContext.getHistoryManager().recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());

  // switch all sub-executions of the process instance to the new process definition version
  Collection<ExecutionEntity> childExecutions = executionManager.findChildExecutionsByProcessInstanceId(processInstanceId);
  for (ExecutionEntity executionEntity : childExecutions) {
    validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
  }

  return null;
}
 
Example 7
Source File: IntermediateCatchEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void deleteOtherEventsRelatedToEventBasedGateway(DelegateExecution execution, EventGateway eventGateway) {
  
  // To clean up the other events behind the event based gateway, we must gather the 
  // activity ids of said events and check the _sibling_ executions of the incoming execution.
  // Note that it can happen that there are multiple such execution in those activity ids,
  // (for example a parallel gw going twice to the event based gateway, kinda silly, but valid)
  // so we only take _one_ result of such a query for deletion.
  
  // Gather all activity ids for the events after the event based gateway that need to be destroyed
  List<SequenceFlow> outgoingSequenceFlows = eventGateway.getOutgoingFlows();
  Set<String> eventActivityIds = new HashSet<String>(outgoingSequenceFlows.size() - 1); // -1, the event being triggered does not need to be deleted
  for (SequenceFlow outgoingSequenceFlow : outgoingSequenceFlows) {
    if (outgoingSequenceFlow.getTargetFlowElement() != null
        && !outgoingSequenceFlow.getTargetFlowElement().getId().equals(execution.getCurrentActivityId())) {
      eventActivityIds.add(outgoingSequenceFlow.getTargetFlowElement().getId());
    }
  }
  
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  
  // Find the executions
  List<ExecutionEntity> executionEntities = executionEntityManager
      .findExecutionsByParentExecutionAndActivityIds(execution.getParentId(), eventActivityIds);
  
  // Execute the cancel behaviour of the IntermediateCatchEvent
  for (ExecutionEntity executionEntity : executionEntities) {
    if (eventActivityIds.contains(executionEntity.getActivityId()) && execution.getCurrentFlowElement() instanceof IntermediateCatchEvent) {
      IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) execution.getCurrentFlowElement();
      if (intermediateCatchEvent.getBehavior() instanceof IntermediateCatchEventActivityBehavior) {
        ((IntermediateCatchEventActivityBehavior) intermediateCatchEvent.getBehavior()).eventCancelledByEventGateway(executionEntity);
        eventActivityIds.remove(executionEntity.getActivityId()); // We only need to delete ONE execution at the event.
      }
    }
  }
}
 
Example 8
Source File: BoundaryEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) {

    // The destroy scope operation will look for the parent execution and
    // destroy the whole scope, and leave the boundary event using this parent execution.
    //
    // The take outgoing seq flows operation below (the non-interrupting else clause) on the other hand uses the
    // child execution to leave, which keeps the scope alive.
    // Which is what we need here.

    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity attachedRefScopeExecution = executionEntityManager.findById(executionEntity.getParentId());

    ExecutionEntity parentScopeExecution = null;
    ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(attachedRefScopeExecution.getParentId());
    while (currentlyExaminedExecution != null && parentScopeExecution == null) {
      if (currentlyExaminedExecution.isScope()) {
        parentScopeExecution = currentlyExaminedExecution;
      } else {
        currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
      }
    }

    if (parentScopeExecution == null) {
      throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }

    deleteChildExecutions(attachedRefScopeExecution, executionEntity, commandContext);

    // set new parent for boundary event execution
    executionEntity.setParent(parentScopeExecution);

    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
  }
 
Example 9
Source File: BoundaryEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeNonInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) {

    // Non-interrupting: the current execution is given the first parent
    // scope (which isn't its direct parent)
    //
    // Why? Because this execution does NOT have anything to do with
    // the current parent execution (the one where the boundary event is on): when it is deleted or whatever,
    // this does not impact this new execution at all, it is completely independent in that regard.

    // Note: if the parent of the parent does not exists, this becomes a concurrent execution in the process instance!

    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();

    ExecutionEntity parentExecutionEntity = executionEntityManager.findById(executionEntity.getParentId());

    ExecutionEntity scopeExecution = null;
    ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(parentExecutionEntity.getParentId());
    while (currentlyExaminedExecution != null && scopeExecution == null) {
      if (currentlyExaminedExecution.isScope()) {
        scopeExecution = currentlyExaminedExecution;
      } else {
        currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
      }
    }

    if (scopeExecution == null) {
      throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }

    ExecutionEntity nonInterruptingExecution = executionEntityManager.createChildExecution(scopeExecution);
    nonInterruptingExecution.setCurrentFlowElement(executionEntity.getCurrentFlowElement());

    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(nonInterruptingExecution, true);
  }
 
Example 10
Source File: BoundaryEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void deleteChildExecutions(ExecutionEntity parentExecution, ExecutionEntity notToDeleteExecution, CommandContext commandContext) {

    // TODO: would be good if this deleteChildExecutions could be removed and the one on the executionEntityManager is used
    // The problem however, is that the 'notToDeleteExecution' is passed here.
    // This could be solved by not reusing an execution, but creating a new

    // Delete all child executions
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    Collection<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecution.getId());
    if (CollectionUtil.isNotEmpty(childExecutions)) {
      for (ExecutionEntity childExecution : childExecutions) {
        if (childExecution.getId().equals(notToDeleteExecution.getId()) == false) {
          deleteChildExecutions(childExecution, notToDeleteExecution, commandContext);
        }
      }
    }

    String deleteReason = DeleteReason.BOUNDARY_EVENT_INTERRUPTING + " (" + notToDeleteExecution.getCurrentActivityId() + ")";
    if (parentExecution.getCurrentFlowElement() instanceof CallActivity) {
      ExecutionEntity subProcessExecution = executionEntityManager.findSubProcessInstanceBySuperExecutionId(parentExecution.getId());
      if (subProcessExecution != null) {
        executionEntityManager.deleteProcessInstanceExecutionEntity(subProcessExecution.getId(),
            subProcessExecution.getCurrentActivityId(), deleteReason, true, true);
      }
    }

    executionEntityManager.deleteExecutionAndRelatedData(parentExecution, deleteReason, false);
  }
 
Example 11
Source File: EventSubProcessMessageStartEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  
  StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
  if (startEvent.isInterrupting()) {  
    List<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(executionEntity.getParentId());
    for (ExecutionEntity childExecution : childExecutions) {
      if (childExecution.getId().equals(executionEntity.getId()) == false) {
        executionEntityManager.deleteExecutionAndRelatedData(childExecution, 
            DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(" + startEvent.getId() + ")", false);
      }
    }
  }
  
  EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
  List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
  for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
    if (eventSubscription instanceof MessageEventSubscriptionEntity && eventSubscription.getEventName().equals(messageEventDefinition.getMessageRef())) {

      eventSubscriptionEntityManager.delete(eventSubscription);
    }
  }
  
  executionEntity.setCurrentFlowElement((SubProcess) executionEntity.getCurrentFlowElement().getParentContainer());
  executionEntity.setScope(true);
  
  ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(executionEntity);
  outgoingFlowExecution.setCurrentFlowElement(startEvent);
  
  leave(outgoingFlowExecution);
}
 
Example 12
Source File: TerminateEndEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();

  if (terminateAll) {
    terminateAllBehaviour(execution, commandContext, executionEntityManager);
  } else if (terminateMultiInstance) {
    terminateMultiInstanceRoot(execution, commandContext, executionEntityManager);
  } else {
    defaultTerminateEndEventBehaviour(execution, commandContext, executionEntityManager);
  }
}
 
Example 13
Source File: ParallelMultiInstanceBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void deleteChildExecutions(ExecutionEntity parentExecution, boolean deleteExecution, CommandContext commandContext) {
  // Delete all child executions
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  Collection<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecution.getId());
  if (CollectionUtil.isNotEmpty(childExecutions)) {
    for (ExecutionEntity childExecution : childExecutions) {
      deleteChildExecutions(childExecution, true, commandContext);
    }
  }

  if (deleteExecution) {
    executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null, false);
  }
}
 
Example 14
Source File: CancelEndEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void deleteChildExecutions(ExecutionEntity parentExecution, ExecutionEntity notToDeleteExecution,
    CommandContext commandContext, String deleteReason) {
  // Delete all child executions
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  Collection<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecution.getId());
  if (CollectionUtil.isNotEmpty(childExecutions)) {
    for (ExecutionEntity childExecution : childExecutions) {
      if (childExecution.getId().equals(notToDeleteExecution.getId()) == false) {
        deleteChildExecutions(childExecution, notToDeleteExecution, commandContext, deleteReason);
      }
    }
  }

  executionEntityManager.deleteExecutionAndRelatedData(parentExecution, deleteReason, false);
}
 
Example 15
Source File: FindActiveActivityIdsCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public List<String> execute(CommandContext commandContext) {
  if (executionId == null) {
    throw new ActivitiIllegalArgumentException("executionId is null");
  }

  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  ExecutionEntity execution = executionEntityManager.findById(executionId);

  if (execution == null) {
    throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
  }

  return findActiveActivityIds(execution);
}
 
Example 16
Source File: InclusiveGatewayActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void executeInclusiveGatewayLogic(ExecutionEntity execution) {
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();

  lockFirstParentScope(execution);

  Collection<ExecutionEntity> allExecutions = executionEntityManager.findChildExecutionsByProcessInstanceId(execution.getProcessInstanceId());
  Iterator<ExecutionEntity> executionIterator = allExecutions.iterator();
  boolean oneExecutionCanReachGateway = false;
  while (!oneExecutionCanReachGateway && executionIterator.hasNext()) {
    ExecutionEntity executionEntity = executionIterator.next();
    if (!executionEntity.getActivityId().equals(execution.getCurrentActivityId())) {
      boolean canReachGateway = ExecutionGraphUtil.isReachable(execution.getProcessDefinitionId(), executionEntity.getActivityId(), execution.getCurrentActivityId());
      if (canReachGateway) {
        oneExecutionCanReachGateway = true;
      }
    } else if (executionEntity.getActivityId().equals(execution.getCurrentActivityId()) && executionEntity.isActive()) {
      // Special case: the execution has reached the inc gw, but the operation hasn't been executed yet for that execution
      oneExecutionCanReachGateway = true;
    }
  }

  // If no execution can reach the gateway, the gateway activates and executes fork behavior
  if (!oneExecutionCanReachGateway) {

    logger.debug("Inclusive gateway cannot be reached by any execution and is activated");

    // Kill all executions here (except the incoming)
    Collection<ExecutionEntity> executionsInGateway = executionEntityManager
        .findInactiveExecutionsByActivityIdAndProcessInstanceId(execution.getCurrentActivityId(), execution.getProcessInstanceId());
    for (ExecutionEntity executionEntityInGateway : executionsInGateway) {
      if (!executionEntityInGateway.getId().equals(execution.getId())) {
        commandContext.getHistoryManager().recordActivityEnd(executionEntityInGateway, null);
        executionEntityManager.deleteExecutionAndRelatedData(executionEntityInGateway, null, false);
      }
    }

    // Leave
    commandContext.getAgenda().planTakeOutgoingSequenceFlowsOperation(execution, true);
  }
}
 
Example 17
Source File: BoundaryCancelEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();
  
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  
  ExecutionEntity subProcessExecution = null;
  // TODO: this can be optimized. A full search in the all executions shouldn't be needed
  List<ExecutionEntity> processInstanceExecutions = executionEntityManager.findChildExecutionsByProcessInstanceId(execution.getProcessInstanceId());
  for (ExecutionEntity childExecution : processInstanceExecutions) {
    if (childExecution.getCurrentFlowElement() != null 
        && childExecution.getCurrentFlowElement().getId().equals(boundaryEvent.getAttachedToRefId())) {
      subProcessExecution = childExecution;
      break;
    }
  }
  
  if (subProcessExecution == null) {
    throw new ActivitiException("No execution found for sub process of boundary cancel event " + boundaryEvent.getId());
  }
  
  EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
  List<CompensateEventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.findCompensateEventSubscriptionsByExecutionId(subProcessExecution.getParentId());

  if (eventSubscriptions.isEmpty()) {
    leave(execution);
  } else {
    
    String deleteReason = DeleteReason.BOUNDARY_EVENT_INTERRUPTING + "(" + boundaryEvent.getId() + ")";
    
    // cancel boundary is always sync
    ScopeUtil.throwCompensationEvent(eventSubscriptions, execution, false);
    executionEntityManager.deleteExecutionAndRelatedData(subProcessExecution, deleteReason, false);
    if (subProcessExecution.getCurrentFlowElement() instanceof Activity) {
      Activity activity = (Activity) subProcessExecution.getCurrentFlowElement();
      if (activity.getLoopCharacteristics() != null) {
        ExecutionEntity miExecution = subProcessExecution.getParent();
        List<ExecutionEntity> miChildExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(miExecution.getId());
        for (ExecutionEntity miChildExecution : miChildExecutions) {
          if (subProcessExecution.getId().equals(miChildExecution.getId()) == false && activity.getId().equals(miChildExecution.getCurrentActivityId())) {
            executionEntityManager.deleteExecutionAndRelatedData(miChildExecution, deleteReason, false);
          }
        }
      }
    }
    leave(execution);
  }
}