Java Code Examples for org.camunda.bpm.engine.impl.context.Context#getCommandContext()

The following examples show how to use org.camunda.bpm.engine.impl.context.Context#getCommandContext() . 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: HistoricTaskInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes all data related with tasks, which belongs to specified process instance ids.
 * @param processInstanceIds
 * @param deleteVariableInstances when true, will also delete variable instances. Can be false when variable instances were deleted separately.
 */
public void deleteHistoricTaskInstancesByProcessInstanceIds(List<String> processInstanceIds, boolean deleteVariableInstances) {

  CommandContext commandContext = Context.getCommandContext();

  if (deleteVariableInstances) {
    getHistoricVariableInstanceManager().deleteHistoricVariableInstancesByTaskProcessInstanceIds(processInstanceIds);
  }

  getHistoricDetailManager()
      .deleteHistoricDetailsByTaskProcessInstanceIds(processInstanceIds);

  commandContext
      .getCommentManager()
      .deleteCommentsByTaskProcessInstanceIds(processInstanceIds);

  getAttachmentManager()
      .deleteAttachmentsByTaskProcessInstanceIds(processInstanceIds);

  getHistoricIdentityLinkManager()
      .deleteHistoricIdentityLinksLogByTaskProcessInstanceIds(processInstanceIds);

  getDbEntityManager().deletePreserveOrder(HistoricTaskInstanceEntity.class, "deleteHistoricTaskInstanceByProcessInstanceIds", processInstanceIds);
}
 
Example 2
Source File: AbstractQuery.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public Object executeResult(ResultType resultType) {

    if (commandExecutor != null) {
      if (!maxResultsLimitEnabled) {
        maxResultsLimitEnabled = Context.getCommandContext() == null;
      }

      return commandExecutor.execute(this);
    }

    switch (resultType) {
      case SINGLE_RESULT:
        return executeSingleResult(Context.getCommandContext());
      case LIST_PAGE:
      case LIST:
        return evaluateExpressionsAndExecuteList(Context.getCommandContext(), null);
      default:
        throw new ProcessEngineException("Unknown result type!");
    }
  }
 
Example 3
Source File: HistoricProcessInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void deleteHistoricProcessInstanceByIds(List<String> processInstanceIds) {
  if (isHistoryEnabled()) {
    CommandContext commandContext = Context.getCommandContext();

    commandContext.getHistoricDetailManager().deleteHistoricDetailsByProcessInstanceIds(processInstanceIds);
    commandContext.getHistoricVariableInstanceManager().deleteHistoricVariableInstanceByProcessInstanceIds(processInstanceIds);
    commandContext.getCommentManager().deleteCommentsByProcessInstanceIds(processInstanceIds);
    commandContext.getAttachmentManager().deleteAttachmentsByProcessInstanceIds(processInstanceIds);
    commandContext.getHistoricTaskInstanceManager().deleteHistoricTaskInstancesByProcessInstanceIds(processInstanceIds, false);
    commandContext.getHistoricActivityInstanceManager().deleteHistoricActivityInstancesByProcessInstanceIds(processInstanceIds);
    commandContext.getHistoricIncidentManager().deleteHistoricIncidentsByProcessInstanceIds(processInstanceIds);
    commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByProcessInstanceIds(processInstanceIds);
    commandContext.getHistoricExternalTaskLogManager().deleteHistoricExternalTaskLogsByProcessInstanceIds(processInstanceIds);
    commandContext.getAuthorizationManager().deleteAuthorizationsByResourceIds(Resources.HISTORIC_PROCESS_INSTANCE, processInstanceIds);

    commandContext.getDbEntityManager().deletePreserveOrder(HistoricProcessInstanceEntity.class, "deleteHistoricProcessInstances", processInstanceIds);
  }
}
 
Example 4
Source File: JobEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void delete(boolean incidentResolved) {
  CommandContext commandContext = Context.getCommandContext();

  incrementSequenceCounter();

  // clean additional data related to this job
  JobHandler jobHandler = getJobHandler();
  if (jobHandler != null) {
    jobHandler.onDelete(getJobHandlerConfiguration(), this);
  }

  // fire delete event if this job is not being executed
  boolean executingJob = this.equals(commandContext.getCurrentJob());
  commandContext.getJobManager().deleteJob(this, !executingJob);

  // Also delete the job's exception byte array
  if (exceptionByteArrayId != null) {
    commandContext.getByteArrayManager().deleteByteArrayById(exceptionByteArrayId);
  }

  // remove link to execution
  ExecutionEntity execution = getExecution();
  if (execution != null) {
    execution.removeJob(this);
  }

  removeFailedJobIncident(incidentResolved);
}
 
Example 5
Source File: CommandContextFunctionMapper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static List<String> currentUserGroups() {
  CommandContext commandContext = Context.getCommandContext();
  if (commandContext != null) {
    return commandContext.getAuthenticatedGroupIds();
  }
  else {
    return null;
  }
}
 
Example 6
Source File: AuthorizationManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected boolean isAuthCheckExecuted() {

    Authentication currentAuthentication = getCurrentAuthentication();
    CommandContext commandContext = Context.getCommandContext();

    return isAuthorizationEnabled()
        && commandContext.isAuthorizationCheckEnabled()
        && currentAuthentication != null
        && currentAuthentication.getUserId() != null;

  }
 
Example 7
Source File: AbstractCorrelateMessageCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void checkAuthorization(CorrelationHandlerResult correlation) {
  CommandContext commandContext = Context.getCommandContext();

  for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    if (MessageCorrelationResultType.Execution.equals(correlation.getResultType())) {
      ExecutionEntity execution = correlation.getExecutionEntity();
      checker.checkUpdateProcessInstanceById(execution.getProcessInstanceId());

    } else {
      ProcessDefinitionEntity definition = correlation.getProcessDefinitionEntity();

      checker.checkCreateProcessInstance(definition);
    }
  }
}
 
Example 8
Source File: ResourceDefinitionCache.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public T findDeployedDefinitionByKeyVersionTagAndTenantId(final String definitionKey, final String definitionVersionTag, final String tenantId) {
  final CommandContext commandContext = Context.getCommandContext();
  T definition = commandContext.runWithoutAuthorization(new Callable<T>() {
    public T call() throws Exception {
      return getManager().findDefinitionByKeyVersionTagAndTenantId(definitionKey, definitionVersionTag, tenantId);
    }
  });
  checkInvalidDefinitionByKeyVersionTagAndTenantId(definitionKey, definitionVersionTag, tenantId, definition);
  definition = resolveDefinition(definition);
  return definition;
}
 
Example 9
Source File: RestartProcessInstancesJobHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void postProcessJob(RestartProcessInstancesBatchConfiguration configuration, JobEntity job) {
  if (job.getDeploymentId() == null) {
    CommandContext commandContext = Context.getCommandContext();
    ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessEngineConfiguration().getDeploymentCache()
        .findDeployedProcessDefinitionById(configuration.getProcessDefinitionId());
    job.setDeploymentId(processDefinitionEntity.getDeploymentId());
  }
}
 
Example 10
Source File: JtaTransactionContext.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void addTransactionListener(TransactionState transactionState, final TransactionListener transactionListener) {
  Transaction transaction = getTransaction();
  CommandContext commandContext = Context.getCommandContext();
  try {
    transaction.registerSynchronization(new TransactionStateSynchronization(transactionState, transactionListener, commandContext));
  }
  catch (Exception e) {
    throw LOG.exceptionWhileInteractingWithTransaction("registering synchronization", e);
  }
}
 
Example 11
Source File: BpmnModelInstanceCache.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected List<ProcessDefinition> getAllDefinitionsForDeployment(final String deploymentId) {
  final CommandContext commandContext = Context.getCommandContext();
  List<ProcessDefinition> allDefinitionsForDeployment = commandContext.runWithoutAuthorization(new Callable<List<ProcessDefinition>>() {
    public List<ProcessDefinition> call() throws Exception {
      return new ProcessDefinitionQueryImpl()
          .deploymentId(deploymentId)
          .list();
    }
  });
  return allDefinitionsForDeployment;
}
 
Example 12
Source File: TaskEntity.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void insert() {
  CommandContext commandContext = Context.getCommandContext();
  TaskManager taskManager = commandContext.getTaskManager();
  taskManager.insertTask(this);
}
 
Example 13
Source File: AbstractManager.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected CommandContext getCommandContext() {
  return Context.getCommandContext();
}
 
Example 14
Source File: HistoricProcessInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void addRemovalTimeById(String processInstanceId, Date removalTime) {
  CommandContext commandContext = Context.getCommandContext();

  commandContext.getHistoricActivityInstanceManager()
    .addRemovalTimeToActivityInstancesByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getHistoricTaskInstanceManager()
    .addRemovalTimeToTaskInstancesByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getHistoricVariableInstanceManager()
    .addRemovalTimeToVariableInstancesByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getHistoricDetailManager()
    .addRemovalTimeToDetailsByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getHistoricIncidentManager()
    .addRemovalTimeToIncidentsByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getHistoricExternalTaskLogManager()
    .addRemovalTimeToExternalTaskLogByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getHistoricJobLogManager()
    .addRemovalTimeToJobLogByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getOperationLogManager()
    .addRemovalTimeToUserOperationLogByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getHistoricIdentityLinkManager()
    .addRemovalTimeToIdentityLinkLogByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getCommentManager()
    .addRemovalTimeToCommentsByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getAttachmentManager()
    .addRemovalTimeToAttachmentsByProcessInstanceId(processInstanceId, removalTime);

  commandContext.getByteArrayManager()
    .addRemovalTimeToByteArraysByProcessInstanceId(processInstanceId, removalTime);

  if (isEnableHistoricInstancePermissions()) {
    commandContext.getAuthorizationManager()
        .addRemovalTimeToAuthorizationsByProcessInstanceId(processInstanceId, removalTime);
  }

  Map<String, Object> parameters = new HashMap<>();
  parameters.put("processInstanceId", processInstanceId);
  parameters.put("removalTime", removalTime);

  getDbEntityManager()
    .updatePreserveOrder(HistoricProcessInstanceEventEntity.class, "updateHistoricProcessInstanceByProcessInstanceId", parameters);
}
 
Example 15
Source File: ExternalTaskEntity.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void produceHistoricExternalTaskSuccessfulEvent() {
  CommandContext commandContext = Context.getCommandContext();
  commandContext.getHistoricExternalTaskLogManager().fireExternalTaskSuccessfulEvent(this);
}
 
Example 16
Source File: DefaultAuthorizationProvider.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected AuthorizationManager getAuthorizationManager() {
  CommandContext commandContext = Context.getCommandContext();
  return commandContext.getAuthorizationManager();
}
 
Example 17
Source File: HistoryCleanupCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected List<Job> getHistoryCleanupJobs() {
  CommandContext commandContext = Context.getCommandContext();
  return commandContext.getJobManager().findJobsByHandlerType(HistoryCleanupJobHandler.TYPE);
}
 
Example 18
Source File: DefaultContextAssociationManager.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void ensureCommandContextNotActive() {
  if(Context.getCommandContext() != null) {
    throw new ProcessEngineCdiException("Cannot work with scoped associations inside command context.");
  }
}
 
Example 19
Source File: TaskEntity.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
public void update() {
  ensureTenantIdNotChanged();

  registerCommandContextCloseListener();

  CommandContext commandContext = Context.getCommandContext();
  DbEntityManager dbEntityManger = commandContext.getDbEntityManager();

  dbEntityManger.merge(this);
}
 
Example 20
Source File: HistoricProcessInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 2 votes vote down vote up
public Map<Class<? extends DbEntity>, DbOperation> deleteHistoricProcessInstancesByRemovalTime(Date removalTime, int minuteFrom, int minuteTo, int batchSize) {
  CommandContext commandContext = Context.getCommandContext();

  Map<Class<? extends DbEntity>, DbOperation> deleteOperations = new HashMap<>();

  DbOperation deleteActivityInstances = commandContext.getHistoricActivityInstanceManager()
    .deleteHistoricActivityInstancesByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteActivityInstances.getEntityType(), deleteActivityInstances);

  DbOperation deleteTaskInstances = commandContext.getHistoricTaskInstanceManager()
    .deleteHistoricTaskInstancesByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteTaskInstances.getEntityType(), deleteTaskInstances);

  DbOperation deleteVariableInstances = commandContext.getHistoricVariableInstanceManager()
    .deleteHistoricVariableInstancesByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteVariableInstances.getEntityType(), deleteVariableInstances);

  DbOperation deleteDetails = commandContext.getHistoricDetailManager()
    .deleteHistoricDetailsByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteDetails.getEntityType(), deleteDetails);

  DbOperation deleteIncidents = commandContext.getHistoricIncidentManager()
    .deleteHistoricIncidentsByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteIncidents.getEntityType(), deleteIncidents);

  DbOperation deleteTaskLog = commandContext.getHistoricExternalTaskLogManager()
    .deleteExternalTaskLogByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteTaskLog.getEntityType(), deleteTaskLog);

  DbOperation deleteJobLog = commandContext.getHistoricJobLogManager()
    .deleteJobLogByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteJobLog.getEntityType(), deleteJobLog);

  DbOperation deleteOperationLog = commandContext.getOperationLogManager()
    .deleteOperationLogByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteOperationLog.getEntityType(), deleteOperationLog);

  DbOperation deleteIdentityLinkLog = commandContext.getHistoricIdentityLinkManager()
    .deleteHistoricIdentityLinkLogByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteIdentityLinkLog.getEntityType(), deleteIdentityLinkLog);

  DbOperation deleteComments = commandContext.getCommentManager()
    .deleteCommentsByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteComments.getEntityType(), deleteComments);

  DbOperation deleteAttachments = commandContext.getAttachmentManager()
    .deleteAttachmentsByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteAttachments.getEntityType(), deleteAttachments);

  DbOperation deleteByteArrays = commandContext.getByteArrayManager()
    .deleteByteArraysByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteByteArrays.getEntityType(), deleteByteArrays);

  DbOperation deleteAuthorizations = commandContext.getAuthorizationManager()
      .deleteAuthorizationsByRemovalTime(removalTime, minuteFrom, minuteTo, batchSize);

  deleteOperations.put(deleteAuthorizations.getEntityType(), deleteAuthorizations);

  Map<String, Object> parameters = new HashMap<>();
  parameters.put("removalTime", removalTime);
  if (minuteTo - minuteFrom + 1 < 60) {
    parameters.put("minuteFrom", minuteFrom);
    parameters.put("minuteTo", minuteTo);
  }
  parameters.put("batchSize", batchSize);

  DbOperation deleteProcessInstances = getDbEntityManager()
    .deletePreserveOrder(HistoricProcessInstanceEntity.class, "deleteHistoricProcessInstancesByRemovalTime",
      new ListQueryParameterObject(parameters, 0, batchSize));

  deleteOperations.put(deleteProcessInstances.getEntityType(), deleteProcessInstances);

  return deleteOperations;
}