Java Code Examples for org.camunda.bpm.engine.impl.interceptor.CommandContext#getExecutionManager()

The following examples show how to use org.camunda.bpm.engine.impl.interceptor.CommandContext#getExecutionManager() . 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: ModifyProcessInstanceAsyncCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Batch execute(CommandContext commandContext) {
  String processInstanceId = builder.getProcessInstanceId();

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

  ensureProcessInstanceExists(processInstanceId, processInstance);

  String processDefinitionId = processInstance.getProcessDefinitionId();
  String tenantId = processInstance.getTenantId();

  String deploymentId = commandContext.getProcessEngineConfiguration().getDeploymentCache()
    .findDeployedProcessDefinitionById(processDefinitionId)
    .getDeploymentId();

  return new BatchBuilder(commandContext)
      .type(Batch.TYPE_PROCESS_INSTANCE_MODIFICATION)
      .config(getConfiguration(processDefinitionId, deploymentId))
      .tenantId(tenantId)
      .totalJobs(1)
      .permission(BatchPermissions.CREATE_BATCH_MODIFY_PROCESS_INSTANCES)
      .operationLogHandler(this::writeOperationLog)
      .build();
}
 
Example 2
Source File: AbstractSetProcessInstanceStateCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateSuspensionState(CommandContext commandContext, SuspensionState suspensionState) {
  ExecutionManager executionManager = commandContext.getExecutionManager();
  TaskManager taskManager = commandContext.getTaskManager();
  ExternalTaskManager externalTaskManager = commandContext.getExternalTaskManager();

  if (processInstanceId != null) {
    executionManager.updateExecutionSuspensionStateByProcessInstanceId(processInstanceId, suspensionState);
    taskManager.updateTaskSuspensionStateByProcessInstanceId(processInstanceId, suspensionState);
    externalTaskManager.updateExternalTaskSuspensionStateByProcessInstanceId(processInstanceId, suspensionState);

  } else if (processDefinitionId != null) {
    executionManager.updateExecutionSuspensionStateByProcessDefinitionId(processDefinitionId, suspensionState);
    taskManager.updateTaskSuspensionStateByProcessDefinitionId(processDefinitionId, suspensionState);
    externalTaskManager.updateExternalTaskSuspensionStateByProcessDefinitionId(processDefinitionId, suspensionState);

  } else if (isProcessDefinitionTenantIdSet) {
    executionManager.updateExecutionSuspensionStateByProcessDefinitionKeyAndTenantId(processDefinitionKey, processDefinitionTenantId, suspensionState);
    taskManager.updateTaskSuspensionStateByProcessDefinitionKeyAndTenantId(processDefinitionKey, processDefinitionTenantId, suspensionState);
    externalTaskManager.updateExternalTaskSuspensionStateByProcessDefinitionKeyAndTenantId(processDefinitionKey, processDefinitionTenantId, suspensionState);

  } else {
    executionManager.updateExecutionSuspensionStateByProcessDefinitionKey(processDefinitionKey, suspensionState);
    taskManager.updateTaskSuspensionStateByProcessDefinitionKey(processDefinitionKey, suspensionState);
    externalTaskManager.updateExternalTaskSuspensionStateByProcessDefinitionKey(processDefinitionKey, suspensionState);
  }
}
 
Example 3
Source File: FindActiveActivityIdsCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public List<String> execute(CommandContext commandContext) {
  ensureNotNull("executionId", executionId);

  // fetch execution
  ExecutionManager executionManager = commandContext.getExecutionManager();
  ExecutionEntity execution = executionManager.findExecutionById(executionId);
  ensureNotNull("execution " + executionId + " doesn't exist", "execution", execution);

  checkGetActivityIds(execution, commandContext);

  // fetch active activities
  return execution.findActiveActivityIds();
}
 
Example 4
Source File: SignalEventReceivedCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void sendSignalToExecution(CommandContext commandContext, String signalName, String executionId) {

    ExecutionManager executionManager = commandContext.getExecutionManager();
    ExecutionEntity execution = executionManager.findExecutionById(executionId);
    ensureNotNull("Cannot find execution with id '" + executionId + "'", "execution", execution);

    EventSubscriptionManager eventSubscriptionManager = commandContext.getEventSubscriptionManager();
    List<EventSubscriptionEntity> signalEvents = eventSubscriptionManager.findSignalEventSubscriptionsByNameAndExecution(signalName, executionId);
    ensureNotEmpty("Execution '" + executionId + "' has not subscribed to a signal event with name '" + signalName + "'.", signalEvents);

    checkAuthorizationOfCatchSignals(commandContext, signalEvents);
    notifyExecutions(signalEvents);
  }
 
Example 5
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 6
Source File: AbstractDeleteProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void deleteProcessInstance(
    final CommandContext commandContext,
    String processInstanceId,
    final String deleteReason,
    final boolean skipCustomListeners,
    final boolean externallyTerminated,
    final boolean skipIoMappings,
    boolean skipSubprocesses) {
  ensureNotNull(BadUserRequestException.class, "processInstanceId is null", "processInstanceId", processInstanceId);

  // fetch process instance
  ExecutionManager executionManager = commandContext.getExecutionManager();
  final ExecutionEntity execution = executionManager.findExecutionById(processInstanceId);

  if(!failIfNotExists && execution == null) {
    return;
  }

  ensureNotNull(BadUserRequestException.class, "No process instance found for id '" + processInstanceId + "'", "processInstance", execution);

  checkDeleteProcessInstance(execution, commandContext);

  // delete process instance
  commandContext
      .getExecutionManager()
      .deleteProcessInstance(processInstanceId, deleteReason, false, skipCustomListeners, externallyTerminated, skipIoMappings, skipSubprocesses);

  if (skipSubprocesses) {
    List<ProcessInstance> superProcesslist = commandContext.getProcessEngineConfiguration().getRuntimeService().createProcessInstanceQuery()
        .superProcessInstanceId(processInstanceId).list();
    triggerHistoryEvent(superProcesslist);
  }

  final ExecutionEntity superExecution = execution.getSuperExecution();
  if (superExecution != null) {
    commandContext.runWithoutAuthorization(new Callable<Void>() {
      public Void call() {
        ProcessInstanceModificationBuilderImpl builder = (ProcessInstanceModificationBuilderImpl) new ProcessInstanceModificationBuilderImpl(commandContext, superExecution.getProcessInstanceId(), deleteReason)
          .cancellationSourceExternal(externallyTerminated).cancelActivityInstance(superExecution.getActivityInstanceId());
        builder.execute(false, skipCustomListeners, skipIoMappings);
        return null;
      }
    });

  }

  // create user operation log
  commandContext.getOperationLogManager()
      .logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, processInstanceId,
          null, null, Collections.singletonList(PropertyChange.EMPTY_CHANGE));
}