Search in sources :

Example 46 with CommandChecker

use of org.camunda.bpm.engine.impl.cfg.CommandChecker in project camunda-bpm-platform by camunda.

the class ExecuteJobsCmd method execute.

public Void execute(CommandContext commandContext) {
    ensureNotNull("jobId", jobId);
    final JobEntity job = commandContext.getDbEntityManager().selectById(JobEntity.class, jobId);
    final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    final IdentityService identityService = processEngineConfiguration.getIdentityService();
    final JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
    if (job == null) {
        if (jobExecutorContext != null) {
            // CAM-1842
            // Job was acquired but does not exist anymore. This is not a problem.
            // It usually means that the job has been deleted after it was acquired which can happen if the
            // the activity instance corresponding to the job is cancelled.
            LOG.debugAcquiredJobNotFound(jobId);
            return null;
        } else {
            throw LOG.jobNotFoundException(jobId);
        }
    }
    jobFailureCollector.setJob(job);
    if (jobExecutorContext == null) {
        // if null, then we are not called by the job executor
        for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
            checker.checkUpdateJob(job);
        }
    } else {
        jobExecutorContext.setCurrentJob(job);
        // if the job is called by the job executor then set the tenant id of the job
        // as authenticated tenant to enable tenant checks
        String tenantId = job.getTenantId();
        if (tenantId != null) {
            identityService.setAuthentication(null, null, Collections.singletonList(tenantId));
        }
    }
    try {
        // register as command context close lister to intercept exceptions on flush
        commandContext.registerCommandContextListener(jobFailureCollector);
        commandContext.setCurrentJob(job);
        job.execute(commandContext);
    } finally {
        if (jobExecutorContext != null) {
            jobExecutorContext.setCurrentJob(null);
            identityService.clearAuthentication();
        }
    }
    return null;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) IdentityService(org.camunda.bpm.engine.IdentityService) JobExecutorContext(org.camunda.bpm.engine.impl.jobexecutor.JobExecutorContext) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 47 with CommandChecker

use of org.camunda.bpm.engine.impl.cfg.CommandChecker in project camunda-bpm-platform by camunda.

the class ExternalTaskCmd method execute.

@Override
public Void execute(CommandContext commandContext) {
    EnsureUtil.ensureNotNull("externalTaskId", externalTaskId);
    validateInput();
    ExternalTaskEntity externalTask = commandContext.getExternalTaskManager().findExternalTaskById(externalTaskId);
    ensureNotNull(NotFoundException.class, "Cannot find external task with id " + externalTaskId, "externalTask", externalTask);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkUpdateProcessInstanceById(externalTask.getProcessInstanceId());
    }
    execute(externalTask);
    return null;
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 48 with CommandChecker

use of org.camunda.bpm.engine.impl.cfg.CommandChecker in project camunda-bpm-platform by camunda.

the class GetDeployedProcessDefinitionCmd method execute.

@Override
public ProcessDefinitionEntity execute(CommandContext commandContext) {
    ensureOnlyOneNotNull("either process definition id or key must be set", processDefinitionId, processDefinitionKey);
    ProcessDefinitionEntity processDefinition = find(commandContext);
    if (checkReadPermission) {
        for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
            checker.checkReadProcessDefinition(processDefinition);
        }
    }
    return processDefinition;
}
Also used : ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 49 with CommandChecker

use of org.camunda.bpm.engine.impl.cfg.CommandChecker in project camunda-bpm-platform by camunda.

the class GetDeploymentBpmnModelInstanceCmd method execute.

public BpmnModelInstance execute(CommandContext commandContext) {
    ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
    final DeploymentCache deploymentCache = configuration.getDeploymentCache();
    ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadProcessDefinition(processDefinition);
    }
    BpmnModelInstance modelInstance = deploymentCache.findBpmnModelInstanceForProcessDefinition(processDefinitionId);
    ensureNotNull("no BPMN model instance found for process definition id " + processDefinitionId, "modelInstance", modelInstance);
    return modelInstance;
}
Also used : DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 50 with CommandChecker

use of org.camunda.bpm.engine.impl.cfg.CommandChecker in project camunda-bpm-platform by camunda.

the class GetDeploymentProcessDiagramLayoutCmd method execute.

public DiagramLayout execute(final CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedProcessDefinitionById(processDefinitionId);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadProcessDefinition(processDefinition);
    }
    InputStream processModelStream = commandContext.runWithoutAuthorization(new Callable<InputStream>() {

        public InputStream call() throws Exception {
            return new GetDeploymentProcessModelCmd(processDefinitionId).execute(commandContext);
        }
    });
    InputStream processDiagramStream = commandContext.runWithoutAuthorization(new Callable<InputStream>() {

        public InputStream call() throws Exception {
            return new GetDeploymentProcessDiagramCmd(processDefinitionId).execute(commandContext);
        }
    });
    return new ProcessDiagramLayoutFactory().getProcessDiagramLayout(processModelStream, processDiagramStream);
}
Also used : InputStream(java.io.InputStream) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessDiagramLayoutFactory(org.camunda.bpm.engine.impl.bpmn.diagram.ProcessDiagramLayoutFactory) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)59 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)14 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)10 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)8 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)7 CaseDefinitionEntity (org.camunda.bpm.engine.impl.cmmn.entity.repository.CaseDefinitionEntity)6 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)6 InputStream (java.io.InputStream)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)4 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)3 DecisionDefinitionEntity (org.camunda.bpm.engine.impl.dmn.entity.repository.DecisionDefinitionEntity)3 TaskFormHandler (org.camunda.bpm.engine.impl.form.handler.TaskFormHandler)3 ExternalTaskEntity (org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity)3 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)3 JobDefinitionManager (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager)3 PropertyChange (org.camunda.bpm.engine.impl.persistence.entity.PropertyChange)3 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)3 TaskManager (org.camunda.bpm.engine.impl.persistence.entity.TaskManager)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2