Search in sources :

Example 11 with ScopeImpl

use of org.camunda.bpm.engine.impl.pvm.process.ScopeImpl in project camunda-bpm-platform by camunda.

the class ActivityInstanceHandler method handle.

@Override
public void handle(MigratingInstanceParseContext parseContext, ActivityInstance element) {
    MigratingActivityInstance migratingInstance = null;
    MigrationInstruction applyingInstruction = parseContext.getInstructionFor(element.getActivityId());
    ScopeImpl sourceScope = null;
    ScopeImpl targetScope = null;
    ExecutionEntity representativeExecution = parseContext.getMapping().getExecution(element);
    if (element.getId().equals(element.getProcessInstanceId())) {
        sourceScope = parseContext.getSourceProcessDefinition();
        targetScope = parseContext.getTargetProcessDefinition();
    } else {
        sourceScope = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());
        if (applyingInstruction != null) {
            String activityId = applyingInstruction.getTargetActivityId();
            targetScope = parseContext.getTargetProcessDefinition().findActivity(activityId);
        }
    }
    migratingInstance = parseContext.getMigratingProcessInstance().addActivityInstance(applyingInstruction, element, sourceScope, targetScope, representativeExecution);
    MigratingActivityInstance parentInstance = parseContext.getMigratingActivityInstanceById(element.getParentActivityInstanceId());
    if (parentInstance != null) {
        migratingInstance.setParent(parentInstance);
    }
    CoreActivityBehavior<?> sourceActivityBehavior = sourceScope.getActivityBehavior();
    if (sourceActivityBehavior instanceof MigrationObserverBehavior) {
        ((MigrationObserverBehavior) sourceActivityBehavior).onParseMigratingInstance(parseContext, migratingInstance);
    }
    parseContext.submit(migratingInstance);
    parseTransitionInstances(parseContext, migratingInstance);
    parseDependentInstances(parseContext, migratingInstance);
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigrationObserverBehavior(org.camunda.bpm.engine.impl.pvm.delegate.MigrationObserverBehavior) MigratingActivityInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)

Example 12 with ScopeImpl

use of org.camunda.bpm.engine.impl.pvm.process.ScopeImpl in project camunda-bpm-platform by camunda.

the class MigratingProcessElementInstanceVisitor method migrateProcessElementInstance.

protected void migrateProcessElementInstance(MigratingProcessElementInstance migratingInstance, MigratingScopeInstanceBranch migratingInstanceBranch) {
    final MigratingScopeInstance parentMigratingInstance = migratingInstance.getParent();
    ScopeImpl sourceScope = migratingInstance.getSourceScope();
    ScopeImpl targetScope = migratingInstance.getTargetScope();
    ScopeImpl targetFlowScope = targetScope.getFlowScope();
    ScopeImpl parentActivityInstanceTargetScope = parentMigratingInstance != null ? parentMigratingInstance.getTargetScope() : null;
    if (sourceScope != sourceScope.getProcessDefinition() && targetFlowScope != parentActivityInstanceTargetScope) {
        // create intermediate scopes
        // 1. manipulate execution tree
        // determine the list of ancestor scopes (parent, grandparent, etc.) for which
        // no executions exist yet
        List<ScopeImpl> nonExistingScopes = collectNonExistingFlowScopes(targetFlowScope, migratingInstanceBranch);
        // get the closest ancestor scope that is instantiated already
        ScopeImpl existingScope = nonExistingScopes.isEmpty() ? targetFlowScope : nonExistingScopes.get(0).getFlowScope();
        // and its scope instance
        MigratingScopeInstance ancestorScopeInstance = migratingInstanceBranch.getInstance(existingScope);
        // Instantiate the scopes as children of the scope execution
        instantiateScopes(ancestorScopeInstance, migratingInstanceBranch, nonExistingScopes);
        MigratingScopeInstance targetFlowScopeInstance = migratingInstanceBranch.getInstance(targetFlowScope);
        // 2. detach instance
        // The order of steps 1 and 2 avoids intermediate execution tree compaction
        // which in turn could overwrite some dependent instances (e.g. variables)
        migratingInstance.detachState();
        // 3. attach to newly created activity instance
        migratingInstance.attachState(targetFlowScopeInstance);
    }
    // 4. update state (e.g. activity id)
    migratingInstance.migrateState();
    // 5. migrate instance state other than execution-tree structure
    migratingInstance.migrateDependentEntities();
}
Also used : ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)

Example 13 with ScopeImpl

use of org.camunda.bpm.engine.impl.pvm.process.ScopeImpl in project camunda-bpm-platform by camunda.

the class MigrationCompensationInstanceVisitor method instantiateScopes.

@Override
protected void instantiateScopes(MigratingScopeInstance ancestorScopeInstance, MigratingScopeInstanceBranch executionBranch, List<ScopeImpl> scopesToInstantiate) {
    if (scopesToInstantiate.isEmpty()) {
        return;
    }
    ExecutionEntity ancestorScopeExecution = ancestorScopeInstance.resolveRepresentativeExecution();
    ExecutionEntity parentExecution = ancestorScopeExecution;
    for (ScopeImpl scope : scopesToInstantiate) {
        ExecutionEntity compensationScopeExecution = parentExecution.createExecution();
        compensationScopeExecution.setScope(true);
        compensationScopeExecution.setEventScope(true);
        compensationScopeExecution.setActivity((PvmActivity) scope);
        compensationScopeExecution.setActive(false);
        compensationScopeExecution.activityInstanceStarting();
        compensationScopeExecution.enterActivityInstance();
        EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(parentExecution, EventType.COMPENSATE, (ActivityImpl) scope);
        eventSubscription.setConfiguration(compensationScopeExecution.getId());
        executionBranch.visited(new MigratingEventScopeInstance(eventSubscription, compensationScopeExecution, scope));
        parentExecution = compensationScopeExecution;
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 14 with ScopeImpl

use of org.camunda.bpm.engine.impl.pvm.process.ScopeImpl in project camunda-bpm-platform by camunda.

the class MigratingActivityInstanceVisitor method instantiateScopes.

protected void instantiateScopes(MigratingScopeInstance ancestorScopeInstance, MigratingScopeInstanceBranch executionBranch, List<ScopeImpl> scopesToInstantiate) {
    if (scopesToInstantiate.isEmpty()) {
        return;
    }
    // must always be an activity instance
    MigratingActivityInstance ancestorActivityInstance = (MigratingActivityInstance) ancestorScopeInstance;
    ExecutionEntity newParentExecution = ancestorActivityInstance.createAttachableExecution();
    Map<PvmActivity, PvmExecutionImpl> createdExecutions = newParentExecution.instantiateScopes((List) scopesToInstantiate, skipCustomListeners, skipIoMappings);
    for (ScopeImpl scope : scopesToInstantiate) {
        ExecutionEntity createdExecution = (ExecutionEntity) createdExecutions.get(scope);
        createdExecution.setActivity(null);
        createdExecution.setActive(false);
        executionBranch.visited(new MigratingActivityInstance(scope, createdExecution));
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 15 with ScopeImpl

use of org.camunda.bpm.engine.impl.pvm.process.ScopeImpl in project camunda-bpm-platform by camunda.

the class ActivityExecutionTreeMapping method assignExecutionsToActivities.

protected void assignExecutionsToActivities(List<ExecutionEntity> leaves) {
    for (ExecutionEntity leaf : leaves) {
        ScopeImpl activity = leaf.getActivity();
        if (activity != null) {
            if (leaf.getActivityInstanceId() != null) {
                EnsureUtil.ensureNotNull("activity", activity);
                submitExecution(leaf, activity);
            }
            mergeScopeExecutions(leaf);
        } else if (leaf.isProcessInstanceExecution()) {
            submitExecution(leaf, leaf.getProcessDefinition());
        }
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)

Aggregations

ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)37 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)10 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)10 PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)6 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)6 FlowScopeWalker (org.camunda.bpm.engine.impl.tree.FlowScopeWalker)5 HashMap (java.util.HashMap)4 List (java.util.List)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 ReferenceWalker (org.camunda.bpm.engine.impl.tree.ReferenceWalker)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 PvmScope (org.camunda.bpm.engine.impl.pvm.PvmScope)3 Deployment (org.camunda.bpm.engine.test.Deployment)3 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)2 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)2 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)2 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)2 CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)2