Java Code Examples for org.flowable.engine.delegate.DelegateExecution#getCurrentFlowElement()

The following examples show how to use org.flowable.engine.delegate.DelegateExecution#getCurrentFlowElement() . 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: IntermediateCatchEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected EventGateway getPrecedingEventBasedGateway(DelegateExecution execution) {
    FlowElement currentFlowElement = execution.getCurrentFlowElement();
    if (currentFlowElement instanceof IntermediateCatchEvent) {
        IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) currentFlowElement;
        List<SequenceFlow> incomingSequenceFlow = intermediateCatchEvent.getIncomingFlows();

        // If behind an event based gateway, there is only one incoming sequence flow that originates from said gateway
        if (incomingSequenceFlow != null && incomingSequenceFlow.size() == 1) {
            SequenceFlow sequenceFlow = incomingSequenceFlow.get(0);
            FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement();
            if (sourceFlowElement instanceof EventGateway) {
                return (EventGateway) sourceFlowElement;
            }
        }

    }
    return null;
}
 
Example 2
Source File: BpmnLoggingSessionUtil.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void addErrorLoggingData(String type, String message, Throwable t, DelegateExecution execution) {
    FlowElement flowElement = execution.getCurrentFlowElement();
    String activityId = null;
    String activityName = null;
    String activityType = null;
    String activitySubType = null;
    if (flowElement != null) {
        activityId = flowElement.getId();
        activityName = flowElement.getName();
        activityType = flowElement.getClass().getSimpleName();
        activitySubType = getActivitySubType(flowElement);
    }
    
    ObjectNode loggingNode = LoggingSessionUtil.fillLoggingData(message, execution.getProcessInstanceId(), execution.getId(), 
                    ScopeTypes.BPMN, execution.getProcessDefinitionId(), activityId, activityName, activityType, activitySubType);
    fillScopeDefinitionInfo(execution.getProcessDefinitionId(), loggingNode);
    LoggingSessionUtil.addErrorLoggingData(type, loggingNode, t);
}
 
Example 3
Source File: BoundaryEventRegistryEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();
    
    Object eventInstance = execution.getTransientVariables().get(EventConstants.EVENT_INSTANCE);
    if (eventInstance instanceof EventInstance) {
        EventInstanceBpmnUtil.handleEventInstanceOutParameters(execution, boundaryEvent, (EventInstance) eventInstance);
    }

    if (boundaryEvent.isCancelActivity()) {
        EventSubscriptionService eventSubscriptionService = CommandContextUtil.getEventSubscriptionService();
        List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
        
        CommandContext commandContext = Context.getCommandContext();
        String eventDefinitionKey = getEventDefinitionKey(commandContext, executionEntity);
        for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
            if (Objects.equals(eventDefinitionKey, eventSubscription.getEventType())) {
                eventSubscriptionService.deleteEventSubscription(eventSubscription);
                CountingEntityUtil.handleDeleteEventSubscriptionEntityCount(eventSubscription);
            }
        }
    }

    super.trigger(executionEntity, triggerName, triggerData);
}
 
Example 4
Source File: BoundaryCompensateEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();

    if (boundaryEvent.isCancelActivity()) {
        EventSubscriptionService eventSubscriptionService = CommandContextUtil.getEventSubscriptionService();
        List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
        for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
            if (eventSubscription instanceof CompensateEventSubscriptionEntity && eventSubscription.getActivityId().equals(compensateEventDefinition.getActivityRef())) {
                eventSubscriptionService.deleteEventSubscription(eventSubscription);
                CountingEntityUtil.handleDeleteEventSubscriptionEntityCount(eventSubscription);
            }
        }
    }

    super.trigger(executionEntity, triggerName, triggerData);
}
 
Example 5
Source File: ParallelGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected DelegateExecution findMultiInstanceParentExecution(DelegateExecution execution) {
    DelegateExecution multiInstanceExecution = null;
    DelegateExecution parentExecution = execution.getParent();
    if (parentExecution != null && parentExecution.getCurrentFlowElement() != null) {
        FlowElement flowElement = parentExecution.getCurrentFlowElement();
        if (flowElement instanceof Activity) {
            Activity activity = (Activity) flowElement;
            if (activity.getLoopCharacteristics() != null) {
                multiInstanceExecution = parentExecution;
            }
        }

        if (multiInstanceExecution == null) {
            DelegateExecution potentialMultiInstanceExecution = findMultiInstanceParentExecution(parentExecution);
            if (potentialMultiInstanceExecution != null) {
                multiInstanceExecution = potentialMultiInstanceExecution;
            }
        }
    }

    return multiInstanceExecution;
}
 
Example 6
Source File: AbstractBpmnActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Subclasses that call leave() will first pass through this method, before the regular {@link FlowNodeActivityBehavior#leave(DelegateExecution)} is called. This way, we can check if the activity
 * has loop characteristics, and delegate to the behavior if this is the case.
 */
@Override
public void leave(DelegateExecution execution) {
    FlowElement currentFlowElement = execution.getCurrentFlowElement();
    Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), currentFlowElement);
    if (CollectionUtil.isNotEmpty(boundaryEvents)) {
        executeCompensateBoundaryEvents(boundaryEvents, execution);
    }
    if (!hasLoopCharacteristics()) {
        super.leave(execution);
    } else if (hasMultiInstanceCharacteristics()) {
        multiInstanceActivityBehavior.leave(execution);
    }
}
 
Example 7
Source File: BoundaryTimerEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    if (!(execution.getCurrentFlowElement() instanceof BoundaryEvent)) {
        throw new FlowableException("Programmatic error: " + this.getClass() + " should not be used for anything else than a boundary event");
    }

    TimerJobEntity timerJob = TimerUtil.createTimerEntityForTimerEventDefinition(timerEventDefinition, execution.getCurrentFlowElement(),
            interrupting, executionEntity, TriggerTimerEventJobHandler.TYPE, TimerEventHandler.createConfiguration(execution.getCurrentActivityId(), 
                    timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
    if (timerJob != null) {
        CommandContextUtil.getTimerJobService().scheduleTimerJob(timerJob);
    }
}
 
Example 8
Source File: SubProcessActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected SubProcess getSubProcessFromExecution(DelegateExecution execution) {
    FlowElement flowElement = execution.getCurrentFlowElement();
    SubProcess subProcess = null;
    if (flowElement instanceof SubProcess) {
        subProcess = (SubProcess) flowElement;
    } else {
        throw new FlowableException("Programmatic error: sub process behaviour can only be applied" + " to a SubProcess instance, but got an instance of " + flowElement);
    }
    return subProcess;
}
 
Example 9
Source File: AdhocSubProcessActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected SubProcess getSubProcessFromExecution(DelegateExecution execution) {
    FlowElement flowElement = execution.getCurrentFlowElement();
    SubProcess subProcess = null;
    if (flowElement instanceof SubProcess) {
        subProcess = (SubProcess) flowElement;
    } else {
        throw new FlowableException("Programmatic error: sub process behaviour can only be applied" + " to a SubProcess instance, but got an instance of " + flowElement);
    }
    return subProcess;
}
 
Example 10
Source File: MultiInstanceActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected FlowableMultiInstanceActivityCompletedEvent buildCompletedEvent(DelegateExecution execution, FlowableEngineEventType eventType) {
    FlowElement flowNode = execution.getCurrentFlowElement();

    return FlowableEventBuilder.createMultiInstanceActivityCompletedEvent(eventType,
            (int) execution.getVariable(NUMBER_OF_INSTANCES),
            (int) execution.getVariable(NUMBER_OF_ACTIVE_INSTANCES),
            (int) execution.getVariable(NUMBER_OF_COMPLETED_INSTANCES),
            flowNode.getId(),
            flowNode.getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode);
}
 
Example 11
Source File: EventSubProcessSignalStartEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
    EventSubProcess eventSubProcess = (EventSubProcess) startEvent.getSubProcess();

    execution.setScope(true);

    // initialize the template-defined data objects as variables
    Map<String, Object> dataObjectVars = processDataObjects(eventSubProcess.getDataObjects());
    if (dataObjectVars != null) {
        execution.setVariablesLocal(dataObjectVars);
    }
}
 
Example 12
Source File: EventSubProcessTimerStartEventActivityBehavior.java    From flowable-engine 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 = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity executionEntity = (ExecutionEntity) execution;

    StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
    if (startEvent.isInterrupting()) {
        List<ExecutionEntity> childExecutions = executionEntityManager.collectChildren(executionEntity.getParent());
        for (int i = childExecutions.size() - 1; i >= 0; i--) {
            ExecutionEntity childExecutionEntity = childExecutions.get(i);
            if (!childExecutionEntity.isEnded() && !childExecutionEntity.getId().equals(executionEntity.getId())) {
                executionEntityManager.deleteExecutionAndRelatedData(childExecutionEntity,
                        DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(" + startEvent.getId() + ")", false);
            }
        }
    }

    ExecutionEntity newSubProcessExecution = executionEntityManager.createChildExecution(executionEntity.getParent());
    newSubProcessExecution.setCurrentFlowElement((SubProcess) executionEntity.getCurrentFlowElement().getParentContainer());
    newSubProcessExecution.setEventScope(false);
    newSubProcessExecution.setScope(true);

    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(newSubProcessExecution);

    ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(newSubProcessExecution);
    outgoingFlowExecution.setCurrentFlowElement(startEvent);

    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(outgoingFlowExecution);

    leave(outgoingFlowExecution);
}
 
Example 13
Source File: ListenerNotificationHelper.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void planTransactionDependentExecutionListener(ListenerFactory listenerFactory, DelegateExecution execution, 
                TransactionDependentExecutionListener executionListener, FlowableListener listener) {
    
    Map<String, Object> executionVariablesToUse = execution.getVariables();
    CustomPropertiesResolver customPropertiesResolver = createCustomPropertiesResolver(listener);
    Map<String, Object> customPropertiesMapToUse = invokeCustomPropertiesResolver(execution, customPropertiesResolver);

    TransactionDependentExecutionListenerExecutionScope scope = new TransactionDependentExecutionListenerExecutionScope(
            execution.getProcessInstanceId(), execution.getId(), execution.getCurrentFlowElement(), executionVariablesToUse, customPropertiesMapToUse);

    addTransactionListener(listener, new ExecuteExecutionListenerTransactionListener(executionListener, scope, 
                    CommandContextUtil.getProcessEngineConfiguration().getCommandExecutor()));
}
 
Example 14
Source File: BpmnLoggingSessionUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static void fillFlowElementInfo(ObjectNode loggingNode, DelegateExecution execution) {
    FlowElement flowElement = execution.getCurrentFlowElement();
    
    if (flowElement != null) {
        loggingNode.put("elementId", flowElement.getId());
        putIfNotNull("elementName", flowElement.getName(), loggingNode);
        loggingNode.put("elementType", flowElement.getClass().getSimpleName());
    }
}
 
Example 15
Source File: CamelBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected boolean isASync(DelegateExecution execution) {
    boolean async = false;
    if (execution.getCurrentFlowElement() instanceof Activity) {
        async = ((Activity) execution.getCurrentFlowElement()).isAsynchronous();
    }
    return async;
}
 
Example 16
Source File: BoundaryCancelEventActivityBehavior.java    From flowable-engine 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 = CommandContextUtil.getExecutionEntityManager(commandContext);

    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 FlowableException("No execution found for sub process of boundary cancel event " + boundaryEvent.getId());
    }

    EventSubscriptionService eventSubscriptionService = CommandContextUtil.getEventSubscriptionService(commandContext);
    List<CompensateEventSubscriptionEntity> eventSubscriptions = eventSubscriptionService.findCompensateEventSubscriptionsByExecutionId(subProcessExecution.getParentId());

    if (!eventSubscriptions.isEmpty()) {

        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()) && activity.getId().equals(miChildExecution.getCurrentActivityId())) {
                        executionEntityManager.deleteExecutionAndRelatedData(miChildExecution, deleteReason, false);
                    }
                }
            }
        }
    }
    leave(execution);
}
 
Example 17
Source File: ParallelGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

    // First off all, deactivate the execution
    execution.inactivate();

    // Join
    FlowElement flowElement = execution.getCurrentFlowElement();
    ParallelGateway parallelGateway = null;
    if (flowElement instanceof ParallelGateway) {
        parallelGateway = (ParallelGateway) flowElement;
    } else {
        throw new FlowableException("Programmatic error: parallel gateway behaviour can only be applied" + " to a ParallelGateway instance, but got an instance of " + flowElement);
    }

    lockFirstParentScope(execution);

    DelegateExecution multiInstanceExecution = null;
    if (hasMultiInstanceParent(parallelGateway)) {
        multiInstanceExecution = findMultiInstanceParentExecution(execution);
    }

    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
    Collection<ExecutionEntity> joinedExecutions = executionEntityManager.findInactiveExecutionsByActivityIdAndProcessInstanceId(execution.getCurrentActivityId(), execution.getProcessInstanceId());
    if (multiInstanceExecution != null) {
        joinedExecutions = cleanJoinedExecutions(joinedExecutions, multiInstanceExecution);
    }

    int nbrOfExecutionsToJoin = parallelGateway.getIncomingFlows().size();
    int nbrOfExecutionsCurrentlyJoined = joinedExecutions.size();

    // Fork

    // Is needed to set the endTime for all historic activity joins
    CommandContextUtil.getActivityInstanceEntityManager().recordActivityEnd((ExecutionEntity) execution, null);

    if (nbrOfExecutionsCurrentlyJoined == nbrOfExecutionsToJoin) {

        // Fork
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("parallel gateway '{}' ({}) activates: {} of {} joined", execution.getCurrentActivityId(), 
                    execution.getId(), nbrOfExecutionsCurrentlyJoined, nbrOfExecutionsToJoin);
        }

        if (parallelGateway.getIncomingFlows().size() > 1) {

            // All (now inactive) children are deleted.
            for (ExecutionEntity joinedExecution : joinedExecutions) {

                // The current execution will be reused and not deleted
                if (!joinedExecution.getId().equals(execution.getId())) {
                    executionEntityManager.deleteRelatedDataForExecution(joinedExecution, null);
                    executionEntityManager.delete(joinedExecution);
                }

            }
        }

        // TODO: potential optimization here: reuse more then 1 execution, only 1 currently
        CommandContextUtil.getAgenda().planTakeOutgoingSequenceFlowsOperation((ExecutionEntity) execution, false); // false -> ignoring conditions on parallel gw

    } else if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("parallel gateway '{}' ({}) does not activate: {} of {} joined", execution.getCurrentActivityId(), 
                execution.getId(), nbrOfExecutionsCurrentlyJoined, nbrOfExecutionsToJoin);
    }

}
 
Example 18
Source File: EventSubProcessMessageStartEventActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity executionEntity = (ExecutionEntity) execution;

    StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
    if (startEvent.isInterrupting()) {
        List<ExecutionEntity> childExecutions = executionEntityManager.collectChildren(executionEntity.getParent());
        for (int i = childExecutions.size() - 1; i >= 0; i--) {
            ExecutionEntity childExecutionEntity = childExecutions.get(i);
            if (!childExecutionEntity.isEnded() && !childExecutionEntity.getId().equals(executionEntity.getId())) {
                executionEntityManager.deleteExecutionAndRelatedData(childExecutionEntity,
                        DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(" + startEvent.getId() + ")", false);
            }
        }

        EventSubscriptionService eventSubscriptionService = CommandContextUtil.getEventSubscriptionService(commandContext);
        List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();

        String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, execution);
        for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
            if (eventSubscription instanceof MessageEventSubscriptionEntity && eventSubscription.getEventName().equals(messageName)) {

                eventSubscriptionService.deleteEventSubscription(eventSubscription);
                CountingEntityUtil.handleDeleteEventSubscriptionEntityCount(eventSubscription);
            }
        }
    }

    ExecutionEntity newSubProcessExecution = executionEntityManager.createChildExecution(executionEntity.getParent());
    newSubProcessExecution.setCurrentFlowElement((SubProcess) executionEntity.getCurrentFlowElement().getParentContainer());
    newSubProcessExecution.setEventScope(false);
    newSubProcessExecution.setScope(true);

    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(newSubProcessExecution);

    ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(newSubProcessExecution);
    outgoingFlowExecution.setCurrentFlowElement(startEvent);

    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(outgoingFlowExecution);

    leave(outgoingFlowExecution);
}
 
Example 19
Source File: BoundaryCompensateEventActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();

    Process process = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
    if (process == null) {
        throw new FlowableException("Process model (id = " + execution.getId() + ") could not be found");
    }

    Activity sourceActivity = null;
    Activity compensationActivity = null;
    List<Association> associations = process.findAssociationsWithSourceRefRecursive(boundaryEvent.getId());
    for (Association association : associations) {
        sourceActivity = boundaryEvent.getAttachedToRef();
        FlowElement targetElement = process.getFlowElement(association.getTargetRef(), true);
        if (targetElement instanceof Activity) {
            Activity activity = (Activity) targetElement;
            if (activity.isForCompensation()) {
                compensationActivity = activity;
                break;
            }
        }
    }
    
    if (sourceActivity == null) {
        throw new FlowableException("Parent activity for boundary compensation event could not be found");
    }

    if (compensationActivity == null) {
        throw new FlowableException("Compensation activity could not be found (or it is missing 'isForCompensation=\"true\"'");
    }

    // find SubProcess or Process instance execution
    ExecutionEntity scopeExecution = null;
    ExecutionEntity parentExecution = executionEntity.getParent();
    while (scopeExecution == null && parentExecution != null) {
        if (parentExecution.getCurrentFlowElement() instanceof SubProcess) {
            scopeExecution = parentExecution;

        } else if (parentExecution.isProcessInstanceType()) {
            scopeExecution = parentExecution;
        } else {
            parentExecution = parentExecution.getParent();
        }
    }

    if (scopeExecution == null) {
        throw new FlowableException("Could not find a scope execution for compensation boundary event " + boundaryEvent.getId());
    }

    EventSubscriptionEntity eventSubscription = (EventSubscriptionEntity) CommandContextUtil.getEventSubscriptionService().createEventSubscriptionBuilder()
                    .eventType(CompensateEventSubscriptionEntity.EVENT_TYPE)
                    .executionId(scopeExecution.getId())
                    .processInstanceId(scopeExecution.getProcessInstanceId())
                    .activityId(sourceActivity.getId())
                    .tenantId(scopeExecution.getTenantId())
                    .create();
    
    CountingEntityUtil.handleInsertEventSubscriptionEntityCount(eventSubscription);
}
 
Example 20
Source File: EventSubProcessSignalStartEventActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity executionEntity = (ExecutionEntity) execution;

    String eventName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition,
        ProcessDefinitionUtil.getBpmnModel(execution.getProcessDefinitionId()), execution);

    StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
    if (startEvent.isInterrupting()) {
        List<ExecutionEntity> childExecutions = executionEntityManager.collectChildren(executionEntity.getParent());
        for (int i = childExecutions.size() - 1; i >= 0; i--) {
            ExecutionEntity childExecutionEntity = childExecutions.get(i);
            if (!childExecutionEntity.isEnded() && !childExecutionEntity.getId().equals(executionEntity.getId())) {
                executionEntityManager.deleteExecutionAndRelatedData(childExecutionEntity,
                        DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(" + startEvent.getId() + ")", false);
            }
        }

        EventSubscriptionService eventSubscriptionService = CommandContextUtil.getEventSubscriptionService(commandContext);
        List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();

        for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
            if (eventSubscription instanceof SignalEventSubscriptionEntity && eventSubscription.getEventName().equals(eventName)) {

                eventSubscriptionService.deleteEventSubscription(eventSubscription);
                CountingEntityUtil.handleDeleteEventSubscriptionEntityCount(eventSubscription);
            }
        }
    }
    
    ExecutionEntity newSubProcessExecution = executionEntityManager.createChildExecution(executionEntity.getParent());
    newSubProcessExecution.setCurrentFlowElement((SubProcess) executionEntity.getCurrentFlowElement().getParentContainer());
    newSubProcessExecution.setEventScope(false);
    newSubProcessExecution.setScope(true);

    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(newSubProcessExecution);

    ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(newSubProcessExecution);
    outgoingFlowExecution.setCurrentFlowElement(startEvent);

    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(outgoingFlowExecution);

    leave(outgoingFlowExecution);
}