Search in sources :

Example 6 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationCmd method createProcessInstanceModificationBuilder.

protected ProcessInstanceModificationBuilderImpl createProcessInstanceModificationBuilder(final String processInstanceId, final CommandContext commandContext) {
    ProcessInstanceModificationBuilderImpl processInstanceModificationBuilder = new ProcessInstanceModificationBuilderImpl(commandContext, processInstanceId);
    List<AbstractProcessInstanceModificationCommand> operations = processInstanceModificationBuilder.getModificationOperations();
    ActivityInstance activityInstanceTree = null;
    for (AbstractProcessInstanceModificationCommand instruction : builder.getInstructions()) {
        instruction.setProcessInstanceId(processInstanceId);
        if (!(instruction instanceof ActivityCancellationCmd) || !((ActivityCancellationCmd) instruction).isCancelCurrentActiveActivityInstances()) {
            operations.add(instruction);
        } else {
            if (activityInstanceTree == null) {
                activityInstanceTree = commandContext.runWithoutAuthorization(new Callable<ActivityInstance>() {

                    @Override
                    public ActivityInstance call() throws Exception {
                        return new GetActivityInstanceCmd(processInstanceId).execute(commandContext);
                    }
                });
            }
            ActivityCancellationCmd cancellationInstruction = (ActivityCancellationCmd) instruction;
            List<AbstractInstanceCancellationCmd> cmds = cancellationInstruction.createActivityInstanceCancellations(activityInstanceTree, commandContext);
            operations.addAll(cmds);
        }
    }
    return processInstanceModificationBuilder;
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl) Callable(java.util.concurrent.Callable)

Example 7 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class TransitionInstanceCancellationCmd method determineSourceInstanceExecution.

protected ExecutionEntity determineSourceInstanceExecution(final CommandContext commandContext) {
    ActivityInstance instance = commandContext.runWithoutAuthorization(new Callable<ActivityInstance>() {

        public ActivityInstance call() throws Exception {
            return new GetActivityInstanceCmd(processInstanceId).execute(commandContext);
        }
    });
    TransitionInstance instanceToCancel = findTransitionInstance(instance, transitionInstanceId);
    EnsureUtil.ensureNotNull(NotValidException.class, describeFailure("Transition instance '" + transitionInstanceId + "' does not exist"), "transitionInstance", instanceToCancel);
    ExecutionEntity transitionExecution = commandContext.getExecutionManager().findExecutionById(instanceToCancel.getExecutionId());
    return transitionExecution;
}
Also used : TransitionInstance(org.camunda.bpm.engine.runtime.TransitionInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) NotValidException(org.camunda.bpm.engine.exception.NotValidException)

Example 8 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ExternalTaskQueryTest method testQueryByExecutionId.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testQueryByExecutionId() {
    // given
    List<ProcessInstance> processInstances = startInstancesByKey("oneExternalTaskProcess", 3);
    ProcessInstance firstInstance = processInstances.get(0);
    ActivityInstance externalTaskActivityInstance = runtimeService.getActivityInstance(firstInstance.getId()).getActivityInstances("externalTask")[0];
    String executionId = externalTaskActivityInstance.getExecutionIds()[0];
    // when
    ExternalTask externalTask = externalTaskService.createExternalTaskQuery().executionId(executionId).singleResult();
    // then
    assertNotNull(externalTask);
    assertEquals(executionId, externalTask.getExecutionId());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 9 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ExternalTaskServiceTest method testFetchWithPriorityExpression.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/externalTaskPriorityExpression.bpmn20.xml")
public void testFetchWithPriorityExpression() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoExternalTaskWithPriorityProcess", Variables.createVariables().putValue("priority", 18));
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID, true).topic(TOPIC_NAME, LOCK_TIME).execute();
    // then
    assertEquals(1, externalTasks.size());
    LockedExternalTask task = externalTasks.get(0);
    assertNotNull(task.getId());
    assertEquals(processInstance.getId(), task.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), task.getProcessDefinitionId());
    assertEquals("externalTaskWithPrio", task.getActivityId());
    assertEquals("twoExternalTaskWithPriorityProcess", task.getProcessDefinitionKey());
    assertEquals(TOPIC_NAME, task.getTopicName());
    assertEquals(18, task.getPriority());
    ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId()).getActivityInstances("externalTaskWithPrio")[0];
    assertEquals(activityInstance.getId(), task.getActivityInstanceId());
    assertEquals(activityInstance.getExecutionIds()[0], task.getExecutionId());
    AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME), task.getLockExpirationTime());
    assertEquals(WORKER_ID, task.getWorkerId());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ExternalTaskServiceTest method testExternalTaskExecutionTreeExpansion.

@Deployment
public void testExternalTaskExecutionTreeExpansion() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("boundaryExternalTaskProcess");
    List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    LockedExternalTask externalTask = tasks.get(0);
    // when a non-interrupting boundary event is triggered meanwhile
    // such that the execution tree is expanded
    runtimeService.correlateMessage("Message");
    // then the external task can still be completed
    externalTaskService.complete(externalTask.getId(), WORKER_ID);
    ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(activityInstance).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("afterBoundaryTask").done());
    Task afterBoundaryTask = taskService.createTaskQuery().singleResult();
    taskService.complete(afterBoundaryTask.getId());
    assertProcessEnded(processInstance.getId());
}
Also used : ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)427 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)372 Deployment (org.camunda.bpm.engine.test.Deployment)277 Test (org.junit.Test)159 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)130 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)129 Task (org.camunda.bpm.engine.task.Task)108 ScenarioUnderTest (org.camunda.bpm.qa.upgrade.ScenarioUnderTest)80 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)56 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)54 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)47 TransitionInstance (org.camunda.bpm.engine.runtime.TransitionInstance)31 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)22 Job (org.camunda.bpm.engine.runtime.Job)21 Batch (org.camunda.bpm.engine.batch.Batch)15 DeploymentWithDefinitions (org.camunda.bpm.engine.repository.DeploymentWithDefinitions)12 Execution (org.camunda.bpm.engine.runtime.Execution)12 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)10 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)10 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)9