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;
}
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;
}
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());
}
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());
}
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());
}
Aggregations