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

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity#getActivity() . 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: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Required for migrating active sequential MI receive tasks. These activities were formerly not scope,
 * but are now. This has the following implications:
 *
 * <p>Before migration:
 * <ul><li> the event subscription is attached to the miBody scope execution</ul>
 *
 * <p>After migration:
 * <ul><li> a new subscription is created for every instance
 * <li> the new subscription is attached to a dedicated scope execution as a child of the miBody scope
 *   execution</ul>
 *
 * <p>Thus, this method removes the subscription on the miBody scope
 */
public static void removeLegacySubscriptionOnParent(ExecutionEntity execution, EventSubscriptionEntity eventSubscription) {
  ActivityImpl activity = execution.getActivity();
  if (activity == null) {
    return;
  }

  ActivityBehavior behavior = activity.getActivityBehavior();
  ActivityBehavior parentBehavior = (ActivityBehavior) (activity.getFlowScope() != null ? activity.getFlowScope().getActivityBehavior() : null);

  if (behavior instanceof ReceiveTaskActivityBehavior &&
      parentBehavior instanceof MultiInstanceActivityBehavior) {
    List<EventSubscriptionEntity> parentSubscriptions = execution.getParent().getEventSubscriptions();

    for (EventSubscriptionEntity subscription : parentSubscriptions) {
      // distinguish a boundary event on the mi body with the same message name from the receive task subscription
      if (areEqualEventSubscriptions(subscription, eventSubscription)) {
        subscription.delete();
      }
    }
  }

}
 
Example 2
Source File: ActivityExecutionTreeMapping.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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());
    }
  }
}
 
Example 3
Source File: MessageJobDeclaration.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected JobHandlerConfiguration resolveJobHandlerConfiguration(AtomicOperationInvocation context) {
  AsyncContinuationConfiguration configuration = new AsyncContinuationConfiguration();

  configuration.setAtomicOperation(context.getOperation().getCanonicalName());

  ExecutionEntity execution = context.getExecution();
  PvmActivity activity = execution.getActivity();
  if(activity != null && activity.isAsyncAfter()) {
    if(execution.getTransition() != null) {
      // store id of selected transition in case this is async after.
      // id is not serialized with the execution -> we need to remember it as
      // job handler configuration.
      configuration.setTransitionId(execution.getTransition().getId());
    }
  }

  return configuration;
}
 
Example 4
Source File: AsyncContinuationJobHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(AsyncContinuationConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {

  LegacyBehavior.repairMultiInstanceAsyncJob(execution);

  PvmAtomicOperation atomicOperation = findMatchingAtomicOperation(configuration.getAtomicOperation());
  ensureNotNull("Cannot process job with configuration " + configuration, "atomicOperation", atomicOperation);

  // reset transition id.
  String transitionId = configuration.getTransitionId();
  if (transitionId != null) {
    PvmActivity activity = execution.getActivity();
    TransitionImpl transition = (TransitionImpl) activity.findOutgoingTransition(transitionId);
    execution.setTransition(transition);
  }

  Context.getCommandInvocationContext()
    .performOperation(atomicOperation, execution);
}
 
Example 5
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initActivityInstanceEvent(HistoricActivityInstanceEventEntity evt, ExecutionEntity execution, HistoryEventType eventType) {
  PvmScope eventSource = execution.getActivity();
  if (eventSource == null) {
    eventSource = (PvmScope) execution.getEventSource();
  }
  String activityInstanceId = execution.getActivityInstanceId();

  String parentActivityInstanceId = null;
  ExecutionEntity parentExecution = execution.getParent();

  if (parentExecution != null && CompensationBehavior.isCompensationThrowing(parentExecution) && execution.getActivity() != null) {
    parentActivityInstanceId = CompensationBehavior.getParentActivityInstanceId(execution);
  } else {
    parentActivityInstanceId = execution.getParentActivityInstanceId();
  }

  initActivityInstanceEvent(evt,
      execution,
      eventSource,
      activityInstanceId,
      parentActivityInstanceId,
      eventType);
}
 
Example 6
Source File: RecorderExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void notify(DelegateExecution execution) throws Exception {
  ExecutionEntity executionCasted = ((ExecutionEntity)execution);
  String parameterValue = null;
  if (parameter != null) {
    parameterValue = (String)parameter.getValue(execution);
  }

  String activityName = null;
  if (executionCasted.getActivity() != null) {
    activityName = executionCasted.getActivity().getProperties().get(new PropertyKey<String>("name"));
  }

  recordedEvents.add( new RecordedEvent(
                  executionCasted.getActivityId(),
                  activityName,
                  execution.getEventName(),
                  parameterValue,
                  execution.getActivityInstanceId(),
                  execution.getCurrentTransitionId(),
                  execution.isCanceled(),
                  execution.getId()));
}
 
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: ModificationUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void handleChildRemovalInScope(ExecutionEntity removedExecution) {
  ActivityImpl activity = removedExecution.getActivity();
  if (activity == null) {
    if (removedExecution.getSuperExecution() != null) {
      removedExecution = removedExecution.getSuperExecution();
      activity = removedExecution.getActivity();
      if (activity == null) {
        return;
      }
    } else {
      return;
    }
  }
  ScopeImpl flowScope = activity.getFlowScope();

  PvmExecutionImpl scopeExecution = removedExecution.getParentScopeExecution(false);
  PvmExecutionImpl executionInParentScope = removedExecution.isConcurrent() ? removedExecution : removedExecution.getParent();

  if (flowScope.getActivityBehavior() != null && flowScope.getActivityBehavior() instanceof ModificationObserverBehavior) {
    // let child removal be handled by the scope itself
    ModificationObserverBehavior behavior = (ModificationObserverBehavior) flowScope.getActivityBehavior();
    behavior.destroyInnerInstance(executionInParentScope);
  }
  else {
    if (executionInParentScope.isConcurrent()) {
      executionInParentScope.remove();
      scopeExecution.tryPruneLastConcurrentChild();
      scopeExecution.forceUpdate();
    }
  }
}
 
Example 9
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 10
Source File: CompensationUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * In the context when an event scope execution is created (i.e. a scope such as a subprocess has completed),
 * this method returns the compensation handler activity that is going to be executed when by the event scope execution.
 *
 * This method is not relevant when the scope has a boundary compensation handler.
 */
protected static ActivityImpl getEventScopeCompensationHandler(ExecutionEntity execution) {
  ActivityImpl activity = execution.getActivity();

  ActivityImpl compensationHandler = activity.findCompensationHandler();
  if (compensationHandler != null && compensationHandler.isSubProcessScope()) {
    // subprocess with inner compensation event subprocess
    return compensationHandler;
  } else {
    // subprocess without compensation handler or
    // multi instance activity
    return activity;
  }
}
 
Example 11
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void determineEndState(ExecutionEntity executionEntity, HistoricProcessInstanceEventEntity evt) {
  //determine state
  if (executionEntity.getActivity() != null) {
    evt.setState(HistoricProcessInstance.STATE_COMPLETED);
  } else {
    if (executionEntity.isExternallyTerminated()) {
      evt.setState(HistoricProcessInstance.STATE_EXTERNALLY_TERMINATED);
    } else if (!executionEntity.isExternallyTerminated()) {
      evt.setState(HistoricProcessInstance.STATE_INTERNALLY_TERMINATED);
    }
  }
}
 
Example 12
Source File: ModifyProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
  String processInstanceId = builder.getProcessInstanceId();

  ExecutionManager executionManager = commandContext.getExecutionManager();
  ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);

  ensureProcessInstanceExist(processInstanceId, processInstance);

  checkUpdateProcessInstance(processInstance, commandContext);

  processInstance.setPreserveScope(true);

  List<AbstractProcessInstanceModificationCommand> instructions = builder.getModificationOperations();

  checkCancellation(commandContext);
  for (int i = 0; i < instructions.size(); i++) {

    AbstractProcessInstanceModificationCommand instruction = instructions.get(i);
    LOG.debugModificationInstruction(processInstanceId, i + 1, instruction.describe());

    instruction.setSkipCustomListeners(builder.isSkipCustomListeners());
    instruction.setSkipIoMappings(builder.isSkipIoMappings());
    instruction.setExternallyTerminated(builder.isExternallyTerminated());
    instruction.execute(commandContext);
  }

  processInstance = executionManager.findExecutionById(processInstanceId);

  if (!processInstance.hasChildren()) {
    if (processInstance.getActivity() == null) {
      // process instance was cancelled
      checkDeleteProcessInstance(processInstance, commandContext);
      deletePropagate(processInstance, builder.getModificationReason(), builder.isSkipCustomListeners(), builder.isSkipIoMappings(),
          builder.isExternallyTerminated());
    }
    else if (processInstance.isEnded()) {
      // process instance has ended regularly
      processInstance.propagateEnd();
    }
  }

  if (writeOperationLog) {
    commandContext.getOperationLogManager().logProcessInstanceOperation(getLogEntryOperation(),
      processInstanceId,
      null,
      null,
      Collections.singletonList(PropertyChange.EMPTY_CHANGE),
      builder.getAnnotation());
  }

  return null;
}
 
Example 13
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());

  }
}