Java Code Examples for org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity#setActivity()

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity#setActivity() . 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: MigratingActivityInstanceVisitor.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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));
  }
}
 
Example 2
Source File: MigratingTransitionInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void migrateState() {
  ExecutionEntity representativeExecution = resolveRepresentativeExecution();

  representativeExecution.setProcessDefinition(targetScope.getProcessDefinition());
  representativeExecution.setActivity((PvmActivity) targetScope);
}
 
Example 3
Source File: MigrationCompensationInstanceVisitor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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;
  }

}
 
Example 4
Source File: MigratingActivityInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void detachState() {
  ExecutionEntity currentExecution = resolveRepresentativeExecution();

  currentExecution.setActivity(null);
  currentExecution.leaveActivityInstance();
  currentExecution.setActive(false);

  getParent().destroyAttachableExecution(currentExecution);
}
 
Example 5
Source File: MigratingActivityInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void migrateState() {
  ExecutionEntity currentExecution = resolveRepresentativeExecution();
  currentExecution.setProcessDefinition(targetScope.getProcessDefinition());
  currentExecution.setActivity((PvmActivity) targetScope);

  currentScope = targetScope;

  if (targetScope.isScope()) {
    becomeScope();
  }

  migrateHistory(currentExecution);
}
 
Example 6
Source File: MigratingActivityInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void migrateState() {
  ExecutionEntity currentScopeExecution = resolveRepresentativeExecution();
  currentScopeExecution.setProcessDefinition(targetScope.getProcessDefinition());

  ExecutionEntity parentExecution = currentScopeExecution.getParent();

  if (parentExecution != null && parentExecution.isConcurrent()) {
    parentExecution.setProcessDefinition(targetScope.getProcessDefinition());
  }

  currentScope = targetScope;

  if (!targetScope.isScope()) {
    becomeNonScope();
    currentScopeExecution = resolveRepresentativeExecution();
  }

  if (isLeafActivity(targetScope)) {
    currentScopeExecution.setActivity((PvmActivity) targetScope);
  }

  if (sourceScope.getActivityBehavior() instanceof MigrationObserverBehavior) {
    ((MigrationObserverBehavior) sourceScope.getActivityBehavior()).migrateScope(currentScopeExecution);
  }

  migrateHistory(currentScopeExecution);
}
 
Example 7
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * When executing an async job for an activity wrapped in an miBody, set the execution to the
 * miBody except the wrapped activity is marked as async.
 *
 * Background: in <= 7.2 async jobs were created for the inner activity, although the
 * semantics are that they are executed before the miBody is entered
 */
public static void repairMultiInstanceAsyncJob(ExecutionEntity execution) {
  ActivityImpl activity = execution.getActivity();

  if (!isAsync(activity) && isActivityWrappedInMultiInstanceBody(activity)) {
    execution.setActivity((ActivityImpl) activity.getFlowScope());
  }
}
 
Example 8
Source File: SetProcessDefinitionVersionCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinitionEntity newProcessDefinition) {
  // check that the new process definition version contains the current activity
  if (execution.getActivity() != null) {
    String activityId = execution.getActivity().getId();
    PvmActivity newActivity = newProcessDefinition.findActivity(activityId);

    if (newActivity == null) {
      throw new ProcessEngineException(
        "The new process definition " +
        "(key = '" + newProcessDefinition.getKey() + "') " +
        "does not contain the current activity " +
        "(id = '" + activityId + "') " +
        "of the process instance " +
        "(id = '" + processInstanceId + "').");
      }

      // clear cached activity so that outgoing transitions are refreshed
      execution.setActivity(newActivity);
    }

  // switch the process instance to the new process definition version
  execution.setProcessDefinition(newProcessDefinition);

  // and change possible existing tasks (as the process definition id is stored there too)
  List<TaskEntity> tasks = commandContext.getTaskManager().findTasksByExecutionId(execution.getId());
  for (TaskEntity taskEntity : tasks) {
    taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
  }
}
 
Example 9
Source File: CompensationEventHandler.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, Object localPayload, String businessKey, CommandContext commandContext) {
  eventSubscription.delete();

  String configuration = eventSubscription.getConfiguration();
  ensureNotNull("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId(), "configuration", configuration);

  ExecutionEntity compensatingExecution = commandContext.getExecutionManager().findExecutionById(configuration);

  ActivityImpl compensationHandler = eventSubscription.getActivity();

  // activate execution
  compensatingExecution.setActive(true);

  if (compensatingExecution.getActivity().getActivityBehavior() instanceof CompositeActivityBehavior) {
    compensatingExecution.getParent().setActivityInstanceId(compensatingExecution.getActivityInstanceId());
  }

  if (compensationHandler.isScope() && !compensationHandler.isCompensationHandler()) {
    // descend into scope:
    List<EventSubscriptionEntity> eventsForThisScope = compensatingExecution.getCompensateEventSubscriptions();
    CompensationUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);

  } else {
    try {


      if (compensationHandler.isSubProcessScope() && compensationHandler.isTriggeredByEvent()) {
        compensatingExecution.executeActivity(compensationHandler);
      }
      else {
        // since we already have a scope execution, we don't need to create another one
        // for a simple scoped compensation handler
        compensatingExecution.setActivity(compensationHandler);
        compensatingExecution.performOperation(PvmAtomicOperation.ACTIVITY_START);
      }


    } catch (Exception e) {
      throw new ProcessEngineException("Error while handling compensation event " + eventSubscription, e);
    }
  }
}
 
Example 10
Source File: CompensationUtil.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * 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());
    }

    // set existing event scope executions as children of new event scope execution
    // (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());

  }
}