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);
}
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();
}
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;
}
}
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));
}
}
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());
}
}
}
Aggregations