Search in sources :

Example 21 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class AbstractInstanceCancellationCmd method execute.

public Void execute(CommandContext commandContext) {
    ExecutionEntity sourceInstanceExecution = determineSourceInstanceExecution(commandContext);
    // Outline:
    // 1. find topmost scope execution beginning at scopeExecution that has exactly
    // one child (this is the topmost scope we can cancel)
    // 2. cancel all children of the topmost execution
    // 3. cancel the activity of the topmost execution itself (if applicable)
    // 4. remove topmost execution (and concurrent parent) if topmostExecution is not the process instance
    ExecutionEntity topmostCancellableExecution = sourceInstanceExecution;
    ExecutionEntity parentScopeExecution = (ExecutionEntity) topmostCancellableExecution.getParentScopeExecution(false);
    // we have reached the correct execution
    while (parentScopeExecution != null && (parentScopeExecution.getNonEventScopeExecutions().size() <= 1)) {
        topmostCancellableExecution = parentScopeExecution;
        parentScopeExecution = (ExecutionEntity) topmostCancellableExecution.getParentScopeExecution(false);
    }
    if (topmostCancellableExecution.isPreserveScope()) {
        topmostCancellableExecution.interrupt(cancellationReason, skipCustomListeners, skipIoMappings);
        topmostCancellableExecution.leaveActivityInstance();
        topmostCancellableExecution.setActivity(null);
    } else {
        topmostCancellableExecution.deleteCascade(cancellationReason, skipCustomListeners, skipIoMappings);
        handleChildRemovalInScope(topmostCancellableExecution);
    }
    return null;
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)

Example 22 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class AbstractProcessInstanceModificationCommand method getScopeExecutionForActivityInstance.

protected ExecutionEntity getScopeExecutionForActivityInstance(ExecutionEntity processInstance, ActivityExecutionTreeMapping mapping, ActivityInstance activityInstance) {
    ensureNotNull("activityInstance", activityInstance);
    ProcessDefinitionImpl processDefinition = processInstance.getProcessDefinition();
    ScopeImpl scope = getScopeForActivityInstance(processDefinition, activityInstance);
    Set<ExecutionEntity> executions = mapping.getExecutions(scope);
    Set<String> activityInstanceExecutions = new HashSet<String>(Arrays.asList(activityInstance.getExecutionIds()));
    // remove with fix of CAM-3574
    for (String activityInstanceExecutionId : activityInstance.getExecutionIds()) {
        ExecutionEntity execution = Context.getCommandContext().getExecutionManager().findExecutionById(activityInstanceExecutionId);
        if (execution.isConcurrent() && execution.hasChildren()) {
            // concurrent executions have at most one child
            ExecutionEntity child = execution.getExecutions().get(0);
            activityInstanceExecutions.add(child.getId());
        }
    }
    // find the scope execution for the given activity instance
    Set<ExecutionEntity> retainedExecutionsForInstance = new HashSet<ExecutionEntity>();
    for (ExecutionEntity execution : executions) {
        if (activityInstanceExecutions.contains(execution.getId())) {
            retainedExecutionsForInstance.add(execution);
        }
    }
    if (retainedExecutionsForInstance.size() != 1) {
        throw new ProcessEngineException("There are " + retainedExecutionsForInstance.size() + " (!= 1) executions for activity instance " + activityInstance.getId());
    }
    return retainedExecutionsForInstance.iterator().next();
}
Also used : ProcessDefinitionImpl(org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) HashSet(java.util.HashSet)

Example 23 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class CompensationUtil method createEventScopeExecution.

/**
 * creates an event scope for the given execution:
 *
 * create a new event scope execution under the parent of the given execution
 * and move all event subscriptions to that execution.
 *
 * this allows us to "remember" the event subscriptions after finishing a
 * scope
 */
public static void createEventScopeExecution(ExecutionEntity execution) {
    // parent execution is a subprocess or a miBody
    ActivityImpl activity = execution.getActivity();
    ExecutionEntity scopeExecution = (ExecutionEntity) execution.findExecutionForFlowScope(activity.getFlowScope());
    List<EventSubscriptionEntity> eventSubscriptions = execution.getCompensateEventSubscriptions();
    if (eventSubscriptions.size() > 0 || hasCompensationEventSubprocess(activity)) {
        ExecutionEntity eventScopeExecution = scopeExecution.createExecution();
        eventScopeExecution.setActivity(execution.getActivity());
        eventScopeExecution.activityInstanceStarting();
        eventScopeExecution.enterActivityInstance();
        eventScopeExecution.setActive(false);
        eventScopeExecution.setConcurrent(false);
        eventScopeExecution.setEventScope(true);
        // copy local variables to eventScopeExecution by value. This way,
        // the eventScopeExecution references a 'snapshot' of the local variables
        Map<String, Object> variables = execution.getVariablesLocal();
        for (Entry<String, Object> variable : variables.entrySet()) {
            eventScopeExecution.setVariableLocal(variable.getKey(), variable.getValue());
        }
        // set event subscriptions to the event scope execution:
        for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
            EventSubscriptionEntity newSubscription = EventSubscriptionEntity.createAndInsert(eventScopeExecution, EventType.COMPENSATE, eventSubscriptionEntity.getActivity());
            newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
            // use the original date
            newSubscription.setCreated(eventSubscriptionEntity.getCreated());
        }
        // (ensuring they don't get removed when 'execution' gets removed)
        for (PvmExecutionImpl childEventScopeExecution : execution.getEventScopeExecutions()) {
            childEventScopeExecution.setParent(eventScopeExecution);
        }
        ActivityImpl compensationHandler = getEventScopeCompensationHandler(execution);
        EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(scopeExecution, EventType.COMPENSATE, compensationHandler);
        eventSubscription.setConfiguration(eventScopeExecution.getId());
    }
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 24 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class CompensationUtil method throwCompensationEvent.

/**
 * we create a separate execution for each compensation handler invocation.
 */
public static void throwCompensationEvent(List<EventSubscriptionEntity> eventSubscriptions, ActivityExecution execution, boolean async) {
    // first spawn the compensating executions
    for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
        // check whether compensating execution is already created
        // (which is the case when compensating an embedded subprocess,
        // where the compensating execution is created when leaving the subprocess
        // and holds snapshot data).
        ExecutionEntity compensatingExecution = getCompensatingExecution(eventSubscription);
        if (compensatingExecution != null) {
            if (compensatingExecution.getParent() != execution) {
                // move the compensating execution under this execution if this is not the case yet
                compensatingExecution.setParent((PvmExecutionImpl) execution);
            }
            compensatingExecution.setEventScope(false);
        } else {
            compensatingExecution = (ExecutionEntity) execution.createExecution();
            eventSubscription.setConfiguration(compensatingExecution.getId());
        }
        compensatingExecution.setConcurrent(true);
    }
    // signal compensation events in REVERSE order of their 'created' timestamp
    Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {

        @Override
        public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
            return o2.getCreated().compareTo(o1.getCreated());
        }
    });
    for (EventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
        compensateEventSubscriptionEntity.eventReceived(null, async);
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 25 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class AbstractCorrelateMessageCmd method instantiateProcess.

protected ProcessInstance instantiateProcess(CommandContext commandContext, CorrelationHandlerResult correlationResult) {
    ProcessDefinitionEntity processDefinitionEntity = correlationResult.getProcessDefinitionEntity();
    ActivityImpl messageStartEvent = processDefinitionEntity.findActivity(correlationResult.getStartEventActivityId());
    ExecutionEntity processInstance = processDefinitionEntity.createProcessInstance(builder.getBusinessKey(), messageStartEvent);
    processInstance.start(builder.getPayloadProcessInstanceVariables());
    return processInstance;
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Aggregations

ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)170 Deployment (org.camunda.bpm.engine.test.Deployment)42 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)18 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)17 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)16 Execution (org.camunda.bpm.engine.runtime.Execution)14 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)13 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)12 Task (org.camunda.bpm.engine.task.Task)12 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)10 ArrayList (java.util.ArrayList)9 VariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity)9 Test (org.junit.Test)9 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)7 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)7 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)7 ProcessDefinitionImpl (org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl)6 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)5