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

The following examples show how to use org.camunda.bpm.engine.impl.interceptor.CommandContext#getProcessDefinitionManager() . 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: ProcessDefinitionEntity.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the cached version if exists; does not update the entity from the database in that case
 */
protected ProcessDefinitionEntity loadProcessDefinition(String processDefinitionId) {
  ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
  DeploymentCache deploymentCache = configuration.getDeploymentCache();

  ProcessDefinitionEntity processDefinition = deploymentCache.findProcessDefinitionFromCache(processDefinitionId);

  if (processDefinition == null) {
    CommandContext commandContext = Context.getCommandContext();
    ProcessDefinitionManager processDefinitionManager = commandContext.getProcessDefinitionManager();
    processDefinition = processDefinitionManager.findLatestProcessDefinitionById(processDefinitionId);

    if (processDefinition != null) {
      processDefinition = deploymentCache.resolveProcessDefinition(processDefinition);
    }
  }

  return processDefinition;

}
 
Example 2
Source File: AbstractDeleteProcessDefinitionCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void deleteProcessDefinitionCmd(CommandContext commandContext, String processDefinitionId, boolean cascade, boolean skipCustomListeners, boolean skipIoMappings) {
  ensureNotNull("processDefinitionId", processDefinitionId);

  ProcessDefinition processDefinition = commandContext.getProcessDefinitionManager()
    .findLatestProcessDefinitionById(processDefinitionId);
  ensureNotNull(NotFoundException.class, "No process definition found with id '" + processDefinitionId + "'",
    "processDefinition", processDefinition);

  List<CommandChecker> commandCheckers = commandContext.getProcessEngineConfiguration().getCommandCheckers();
  for (CommandChecker checker: commandCheckers) {
    checker.checkDeleteProcessDefinitionById(processDefinitionId);
  }

  UserOperationLogManager userOperationLogManager = commandContext.getOperationLogManager();
  userOperationLogManager.logProcessDefinitionOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, processDefinitionId,
    processDefinition.getKey(), new PropertyChange("cascade", false, cascade));

  ProcessDefinitionManager definitionManager = commandContext.getProcessDefinitionManager();
  definitionManager.deleteProcessDefinition(processDefinition, processDefinitionId, cascade, cascade, skipCustomListeners, skipIoMappings);
}
 
Example 3
Source File: AbstractSetProcessDefinitionStateCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateSuspensionState(final CommandContext commandContext, SuspensionState suspensionState) {
  ProcessDefinitionManager processDefinitionManager = commandContext.getProcessDefinitionManager();

  if (processDefinitionId != null) {
    processDefinitionManager.updateProcessDefinitionSuspensionStateById(processDefinitionId, suspensionState);

  } else if (isTenantIdSet) {
    processDefinitionManager.updateProcessDefinitionSuspensionStateByKeyAndTenantId(processDefinitionKey, tenantId, suspensionState);

  } else {
    processDefinitionManager.updateProcessDefinitionSuspensionStateByKey(processDefinitionKey, suspensionState);
  }

  commandContext.runWithoutAuthorization(new Callable<Void>() {
    public Void call() throws Exception {
      UpdateJobDefinitionSuspensionStateBuilderImpl jobDefinitionSuspensionStateBuilder = createJobDefinitionCommandBuilder();
      AbstractSetJobDefinitionStateCmd jobDefinitionCmd = getSetJobDefinitionStateCmd(jobDefinitionSuspensionStateBuilder);
      jobDefinitionCmd.disableLogUserOperation();
      jobDefinitionCmd.execute(commandContext);
      return null;
    }
  });
}
 
Example 4
Source File: DeleteProcessDefinitionsByIdsCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected ProcessDefinitionEntity findNewLatestProcessDefinition(ProcessDefinitionGroup group) {
  ProcessDefinitionEntity newLatestProcessDefinition = null;

  List<ProcessDefinitionEntity> processDefinitions = group.processDefinitions;
  ProcessDefinitionEntity firstProcessDefinition = processDefinitions.get(0);

  if (isLatestProcessDefinition(firstProcessDefinition)) {
    for (ProcessDefinitionEntity processDefinition : processDefinitions) {
      String previousProcessDefinitionId = processDefinition.getPreviousProcessDefinitionId();
      if (previousProcessDefinitionId != null && !this.processDefinitionIds.contains(previousProcessDefinitionId)) {
        CommandContext commandContext = Context.getCommandContext();
        ProcessDefinitionManager processDefinitionManager = commandContext.getProcessDefinitionManager();
        newLatestProcessDefinition = processDefinitionManager.findLatestDefinitionById(previousProcessDefinitionId);
        break;
      }
    }
  }

  return newLatestProcessDefinition;
}
 
Example 5
Source File: ProcessApplicationManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<ProcessDefinition> getDeployedProcessDefinitionArtifacts(DeploymentEntity deployment) {
  CommandContext commandContext = Context.getCommandContext();

  // in case deployment was created by this command
  List<ProcessDefinition> entities = deployment.getDeployedProcessDefinitions();

  if (entities == null) {
    String deploymentId = deployment.getId();
    ProcessDefinitionManager manager = commandContext.getProcessDefinitionManager();
    return manager.findProcessDefinitionsByDeploymentId(deploymentId);
  }

  return entities;

}
 
Example 6
Source File: DeployCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<? extends ProcessDefinition>   getDeployedProcesses(CommandContext commandContext, DeploymentWithDefinitions deployment) {
  List<? extends ProcessDefinition> deployedProcessDefinitions = deployment.getDeployedProcessDefinitions();
  if (deployedProcessDefinitions == null) {
    // existing deployment
    ProcessDefinitionManager manager = commandContext.getProcessDefinitionManager();
    deployedProcessDefinitions = manager.findProcessDefinitionsByDeploymentId(deployment.getId());
  }

  return deployedProcessDefinitions;
}
 
Example 7
Source File: DeleteProcessDefinitionsByIdsCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void deleteProcessDefinitions(ProcessDefinitionGroup group) {
  ProcessDefinitionEntity newLatestProcessDefinition = findNewLatestProcessDefinition(group);

  CommandContext commandContext = Context.getCommandContext();
  UserOperationLogManager userOperationLogManager = commandContext.getOperationLogManager();
  ProcessDefinitionManager definitionManager = commandContext.getProcessDefinitionManager();

  List<ProcessDefinitionEntity> processDefinitions = group.processDefinitions;
  for (ProcessDefinitionEntity processDefinition : processDefinitions) {
    String processDefinitionId = processDefinition.getId();

    if (writeUserOperationLog) {
      userOperationLogManager.logProcessDefinitionOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, processDefinitionId, processDefinition.getKey(),
          new PropertyChange("cascade", false, cascadeToHistory));
    }

    definitionManager.deleteProcessDefinition(processDefinition, processDefinitionId, cascadeToHistory, cascadeToInstances, skipCustomListeners, skipIoMappings);
  }

  if (newLatestProcessDefinition != null) {
    ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
    DeploymentCache deploymentCache = configuration.getDeploymentCache();
    newLatestProcessDefinition = deploymentCache.resolveProcessDefinition(newLatestProcessDefinition);

    List<Deployer> deployers = configuration.getDeployers();
    for (Deployer deployer : deployers) {
      if (deployer instanceof BpmnDeployer) {
        ((BpmnDeployer) deployer).addEventSubscriptions(newLatestProcessDefinition);
      }
    }
  }
}