Java Code Examples for org.camunda.bpm.engine.impl.pvm.process.ScopeImpl#getProcessDefinition()

The following examples show how to use org.camunda.bpm.engine.impl.pvm.process.ScopeImpl#getProcessDefinition() . 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: SupportedActivityInstanceValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(MigratingActivityInstance migratingInstance, MigratingProcessInstance migratingProcessInstance,
    MigratingActivityInstanceValidationReportImpl instanceReport) {

  ScopeImpl sourceScope = migratingInstance.getSourceScope();

  if (sourceScope != sourceScope.getProcessDefinition()) {
    ActivityImpl sourceActivity = (ActivityImpl) migratingInstance.getSourceScope();

    if (!SupportedActivityValidator.INSTANCE.isSupportedActivity(sourceActivity)) {
      instanceReport.addFailure("The type of the source activity is not supported for activity instance migration");
    }
  }
}
 
Example 2
Source File: GatewayMappingValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void validateParentScopeMigrates(ValidatingMigrationInstruction instruction, ValidatingMigrationInstructions instructions,
    MigrationInstructionValidationReportImpl report) {
  ActivityImpl sourceActivity = instruction.getSourceActivity();
  ScopeImpl flowScope = sourceActivity.getFlowScope();

  if (flowScope != flowScope.getProcessDefinition()) {
    if (instructions.getInstructionsBySourceScope(flowScope).isEmpty()) {
      report.addFailure("The gateway's flow scope '" + flowScope.getId() + "' must be mapped");
    }
  }
}
 
Example 3
Source File: AdditionalFlowScopeInstructionValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void validate(ValidatingMigrationInstruction instruction, ValidatingMigrationInstructions instructions, MigrationInstructionValidationReportImpl report) {
  ValidatingMigrationInstruction ancestorScopeInstruction = getClosestPreservedAncestorScopeMigrationInstruction(instruction, instructions);
  ScopeImpl targetScope = instruction.getTargetActivity();

  if (ancestorScopeInstruction != null && targetScope != null && targetScope != targetScope.getProcessDefinition()) {
    ScopeImpl parentInstanceTargetScope = ancestorScopeInstruction.getTargetActivity();
    if (parentInstanceTargetScope != null && !parentInstanceTargetScope.isAncestorFlowScopeOf(targetScope)) {
      report.addFailure("The closest mapped ancestor '" + ancestorScopeInstruction.getSourceActivity().getId() + "' is mapped to scope '" +
        parentInstanceTargetScope.getId() + "' which is not an ancestor of target scope '" + targetScope.getId() + "'");
    }
  }
}
 
Example 4
Source File: SameEventScopeInstructionValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ScopeImpl findMappedEventScope(ScopeImpl sourceEventScope, ValidatingMigrationInstruction instruction, ValidatingMigrationInstructions instructions) {
  if (sourceEventScope != null) {
    if (sourceEventScope == sourceEventScope.getProcessDefinition()) {
      return instruction.getTargetActivity().getProcessDefinition();
    }
    else {
      List<ValidatingMigrationInstruction> eventScopeInstructions = instructions.getInstructionsBySourceScope(sourceEventScope);
      if (eventScopeInstructions.size() > 0) {
        return eventScopeInstructions.get(0).getTargetActivity();
      }
    }
  }
  return null;
}
 
Example 5
Source File: MigratingExternalTaskInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void migrateState() {
  ScopeImpl targetActivity = migratingActivityInstance.getTargetScope();
  ProcessDefinition targetProcessDefinition = (ProcessDefinition) targetActivity.getProcessDefinition();

  externalTask.setActivityId(targetActivity.getId());
  externalTask.setProcessDefinitionId(targetProcessDefinition.getId());
  externalTask.setProcessDefinitionKey(targetProcessDefinition.getKey());
}
 
Example 6
Source File: MigratingProcessElementInstanceVisitor.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
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();
}