Search in sources :

Example 36 with CommandChecker

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

the class StartProcessInstanceAtActivitiesCmd method execute.

public ProcessInstanceWithVariables execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = new GetDeployedProcessDefinitionCmd(instantiationBuilder, false).execute(commandContext);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkCreateProcessInstance(processDefinition);
    }
    ProcessInstanceModificationBuilderImpl modificationBuilder = instantiationBuilder.getModificationBuilder();
    ensureNotEmpty("At least one instantiation instruction required (e.g. by invoking startBefore(..), startAfter(..) or startTransition(..))", "instructions", modificationBuilder.getModificationOperations());
    // instantiate the process
    ActivityImpl initialActivity = determineFirstActivity(processDefinition, modificationBuilder);
    ExecutionEntity processInstance = processDefinition.createProcessInstance(instantiationBuilder.getBusinessKey(), instantiationBuilder.getCaseInstanceId(), initialActivity);
    if (instantiationBuilder.getTenantId() != null) {
        processInstance.setTenantId(instantiationBuilder.getTenantId());
    }
    processInstance.setSkipCustomListeners(modificationBuilder.isSkipCustomListeners());
    VariableMap variables = modificationBuilder.getProcessVariables();
    final ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);
    processInstance.startWithoutExecuting(variables);
    // prevent ending of the process instance between instructions
    processInstance.setPreserveScope(true);
    // apply modifications
    List<AbstractProcessInstanceModificationCommand> instructions = modificationBuilder.getModificationOperations();
    for (int i = 0; i < instructions.size(); i++) {
        AbstractProcessInstanceModificationCommand instruction = instructions.get(i);
        LOG.debugStartingInstruction(processInstance.getId(), i, instruction.describe());
        instruction.setProcessInstanceId(processInstance.getId());
        instruction.setSkipCustomListeners(modificationBuilder.isSkipCustomListeners());
        instruction.setSkipIoMappings(modificationBuilder.isSkipIoMappings());
        instruction.execute(commandContext);
    }
    if (!processInstance.hasChildren() && processInstance.isEnded()) {
        // process instance has ended regularly but this has not been propagated yet
        // due to preserveScope setting
        processInstance.propagateEnd();
    }
    return new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.getVariables());
}
Also used : ExecutionVariableSnapshotObserver(org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessInstanceWithVariablesImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 37 with CommandChecker

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

the class SubmitStartFormCmd method execute.

@Override
public ProcessInstance execute(CommandContext commandContext) {
    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache();
    ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
    ensureNotNull("No process definition found for id = '" + processDefinitionId + "'", "processDefinition", processDefinition);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkCreateProcessInstance(processDefinition);
    }
    ExecutionEntity processInstance = null;
    if (businessKey != null) {
        processInstance = processDefinition.createProcessInstance(businessKey);
    } else {
        processInstance = processDefinition.createProcessInstance();
    }
    // see CAM-2828
    if (processDefinition.getInitial().isAsyncBefore()) {
        // avoid firing history events
        processInstance.setStartContext(new ProcessInstanceStartContext(processInstance.getActivity()));
        FormPropertyHelper.initFormPropertiesOnScope(variables, processInstance);
        processInstance.start();
    } else {
        processInstance.startWithFormProperties(variables);
    }
    return processInstance;
}
Also used : ProcessInstanceStartContext(org.camunda.bpm.engine.impl.pvm.runtime.ProcessInstanceStartContext) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 38 with CommandChecker

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

the class CreateCaseInstanceCmd method execute.

public CaseInstance execute(CommandContext commandContext) {
    ensureAtLeastOneNotNull("caseDefinitionId and caseDefinitionKey are null", caseDefinitionId, caseDefinitionKey);
    CaseDefinitionEntity caseDefinition = find(commandContext);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkCreateCaseInstance(caseDefinition);
    }
    // Start the case instance
    CaseExecutionEntity caseInstance = (CaseExecutionEntity) caseDefinition.createCaseInstance(businessKey);
    caseInstance.create(variables);
    return caseInstance;
}
Also used : CaseExecutionEntity(org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity) CaseDefinitionEntity(org.camunda.bpm.engine.impl.cmmn.entity.repository.CaseDefinitionEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 39 with CommandChecker

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

the class GetDeploymentCmmnModelInstanceCmd method execute.

public CmmnModelInstance execute(CommandContext commandContext) {
    ensureNotNull("caseDefinitionId", caseDefinitionId);
    ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
    final DeploymentCache deploymentCache = configuration.getDeploymentCache();
    CaseDefinitionEntity caseDefinition = deploymentCache.findDeployedCaseDefinitionById(caseDefinitionId);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadCaseDefinition(caseDefinition);
    }
    CmmnModelInstance modelInstance = Context.getProcessEngineConfiguration().getDeploymentCache().findCmmnModelInstanceForCaseDefinition(caseDefinitionId);
    ensureNotNull(CmmnModelInstanceNotFoundException.class, "No CMMN model instance found for case definition id " + caseDefinitionId, "modelInstance", modelInstance);
    return modelInstance;
}
Also used : CaseDefinitionEntity(org.camunda.bpm.engine.impl.cmmn.entity.repository.CaseDefinitionEntity) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) CmmnModelInstance(org.camunda.bpm.model.cmmn.CmmnModelInstance) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 40 with CommandChecker

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

the class CaseExecutionVariableCmd method execute.

public Void execute(CommandContext commandContext) {
    ensureNotNull("caseExecutionId", caseExecutionId);
    caseExecution = commandContext.getCaseExecutionManager().findCaseExecutionById(caseExecutionId);
    ensureNotNull(CaseExecutionNotFoundException.class, "There does not exist any case execution with id: '" + caseExecutionId + "'", "caseExecution", caseExecution);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkUpdateCaseInstance(caseExecution);
    }
    if (variablesDeletions != null && !variablesDeletions.isEmpty()) {
        caseExecution.removeVariables(variablesDeletions);
    }
    if (variablesLocalDeletions != null && !variablesLocalDeletions.isEmpty()) {
        caseExecution.removeVariablesLocal(variablesLocalDeletions);
    }
    if (variables != null && !variables.isEmpty()) {
        caseExecution.setVariables(variables);
    }
    if (variablesLocal != null && !variablesLocal.isEmpty()) {
        caseExecution.setVariablesLocal(variablesLocal);
    }
    return null;
}
Also used : CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

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