Search in sources :

Example 1 with ProcessInstanceWithVariablesImpl

use of org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl in project camunda-bpm-platform by camunda.

the class StartProcessInstanceCmd method execute.

public ProcessInstanceWithVariables execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = new GetDeployedProcessDefinitionCmd(instantiationBuilder, false).execute(commandContext);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkCreateProcessInstance(processDefinition);
    }
    // Start the process instance
    ExecutionEntity processInstance = processDefinition.createProcessInstance(instantiationBuilder.getBusinessKey(), instantiationBuilder.getCaseInstanceId());
    if (instantiationBuilder.getTenantId() != null) {
        processInstance.setTenantId(instantiationBuilder.getTenantId());
    }
    final ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);
    processInstance.start(instantiationBuilder.getVariables());
    return new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.getVariables());
}
Also used : ExecutionVariableSnapshotObserver(org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessInstanceWithVariablesImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 2 with ProcessInstanceWithVariablesImpl

use of org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl in project camunda-bpm-platform by camunda.

the class OnlyDispatchVariableEventOnExistingConditionsTest method testProcessWithEventSubProcessConditionalEvent.

@Test
public void testProcessWithEventSubProcessConditionalEvent() {
    // given
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().serviceTask().camundaClass(CheckDelayedVariablesDelegate.class.getName()).userTask().endEvent().done();
    modelInstance = modify(modelInstance).addSubProcessTo(CONDITIONAL_EVENT_PROCESS_KEY).triggerByEvent().embeddedSubProcess().startEvent().conditionalEventDefinition().condition("${var==1}").conditionalEventDefinitionDone().endEvent().done();
    // when process is deployed and instance created
    rule.manageDeployment(rule.getRepositoryService().createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
    ProcessInstanceWithVariablesImpl processInstance = (ProcessInstanceWithVariablesImpl) rule.getRuntimeService().startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
    // then process definition contains property which indicates that conditional events exists
    Object property = processInstance.getExecutionEntity().getProcessDefinition().getProperty(BpmnParse.PROPERTYNAME_HAS_CONDITIONAL_EVENTS);
    assertNotNull(property);
    assertEquals(Boolean.TRUE, property);
}
Also used : ProcessInstanceWithVariablesImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 3 with ProcessInstanceWithVariablesImpl

use of org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl in project camunda-bpm-platform by camunda.

the class OnlyDispatchVariableEventOnExistingConditionsTest method testProcessWithIntermediateConditionalEvent.

@Test
public void testProcessWithIntermediateConditionalEvent() {
    // given
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().serviceTask().camundaClass(CheckDelayedVariablesDelegate.class.getName()).intermediateCatchEvent().conditionalEventDefinition().condition("${var==1}").conditionalEventDefinitionDone().endEvent().done();
    // when process is deployed and instance created
    rule.manageDeployment(rule.getRepositoryService().createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
    ProcessInstanceWithVariablesImpl processInstance = (ProcessInstanceWithVariablesImpl) rule.getRuntimeService().startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
    // then process definition contains property which indicates that conditional events exists
    Object property = processInstance.getExecutionEntity().getProcessDefinition().getProperty(BpmnParse.PROPERTYNAME_HAS_CONDITIONAL_EVENTS);
    assertNotNull(property);
    assertEquals(Boolean.TRUE, property);
}
Also used : ProcessInstanceWithVariablesImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 4 with ProcessInstanceWithVariablesImpl

use of org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl 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 5 with ProcessInstanceWithVariablesImpl

use of org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl in project camunda-bpm-platform by camunda.

the class OnlyDispatchVariableEventOnExistingConditionsTest method testProcessWithBoundaryConditionalEvent.

@Test
public void testProcessWithBoundaryConditionalEvent() {
    // given
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().serviceTask().camundaClass(CheckDelayedVariablesDelegate.class.getName()).userTask(TASK_WITH_CONDITION_ID).endEvent().done();
    modelInstance = modify(modelInstance).userTaskBuilder(TASK_WITH_CONDITION_ID).boundaryEvent().conditionalEventDefinition().condition("${var==1}").conditionalEventDefinitionDone().endEvent().done();
    // when process is deployed and instance created
    rule.manageDeployment(rule.getRepositoryService().createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
    ProcessInstanceWithVariablesImpl processInstance = (ProcessInstanceWithVariablesImpl) rule.getRuntimeService().startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
    // then process definition contains property which indicates that conditional events exists
    Object property = processInstance.getExecutionEntity().getProcessDefinition().getProperty(BpmnParse.PROPERTYNAME_HAS_CONDITIONAL_EVENTS);
    assertNotNull(property);
    assertEquals(Boolean.TRUE, property);
}
Also used : ProcessInstanceWithVariablesImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Aggregations

ProcessInstanceWithVariablesImpl (org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl)9 Test (org.junit.Test)6 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)4 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)3 VariableMap (org.camunda.bpm.engine.variable.VariableMap)3 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)2 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)2 ExecutionVariableSnapshotObserver (org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver)2 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 ProcessInstanceModificationBuilderImpl (org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl)1