use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method sequentialMultiInstance_should_collectOutputValues.
@Test
public void sequentialMultiInstance_should_collectOutputValues() {
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialUserTasksOutputCollection");
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).hasSize(1);
taskBaseRuntime.completeTask(tasks.get(0), singletonMap("meal", "pizza"));
tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).hasSize(1);
taskBaseRuntime.completeTask(tasks.get(0), singletonMap("meal", "pasta"));
List<VariableInstance> variables = processBaseRuntime.getVariables(processInstance);
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("meals", asList("pizza", "pasta")));
}
use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class DemoApplication method checkAndWorkOnTasksWhenAvailable.
@Scheduled(initialDelay = 1000, fixedDelay = 5000)
public void checkAndWorkOnTasksWhenAvailable() {
securityUtil.logInAs("bob");
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10));
if (tasks.getTotalItems() > 0) {
for (Task t : tasks.getContent()) {
logger.info("> Claiming task: " + t.getId());
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(t.getId()).build());
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(t.getId()).build());
VariableInstance variableInstance = variables.get(0);
if (variableInstance.getName().equals("content")) {
LinkedHashMap contentToProcess = objectMapper.convertValue(variableInstance.getValue(), LinkedHashMap.class);
logger.info("> Content received inside the task to approve: " + contentToProcess);
if (contentToProcess.get("body").toString().contains("activiti")) {
logger.info("> User Approving content");
contentToProcess.put("approved", true);
} else {
logger.info("> User Discarding content");
contentToProcess.put("approved", false);
}
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(t.getId()).withVariable("content", contentToProcess).build());
}
}
} else {
logger.info("> There are no task for me to work on.");
}
}
use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class ProcessRuntimeBPMNMessageIT method shouldTestCatchMessageExpressionWithVariableMappingExtensions.
@Test
public void shouldTestCatchMessageExpressionWithVariableMappingExtensions() {
// when
ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withProcessDefinitionKey("testCatchMessageExpression").build());
// then
List<VariableInstance> variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(process).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("intermediate_var", ""), tuple("inter_message_var", "check2"));
// when
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(process.getId()).build());
// then
assertThat(tasks.getContent()).hasSize(1);
String taskId = tasks.getContent().get(0).getId();
// when
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).withVariable("Text0739ze", "foo").build());
// then
variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(process).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("intermediate_var", "foo"), tuple("inter_message_var", "check2"));
// when
processRuntime.receive(MessagePayloadBuilder.receive("intermediate-catch-message-check2").withCorrelationKey("foo").build());
// then
tasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(process.getId()).build());
assertThat(tasks.getContent()).hasSize(1);
taskId = tasks.getContent().get(0).getId();
// then
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).build());
// then
assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "intermediate-catch-message-check2", "foo", process.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "intermediate-catch-message-check2", "foo", process.getBusinessKey(), null));
}
use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class TaskRuntimeSaveTaskTest method testSaveCompleteReviewOutcomeTasksProcessWithVariables.
@Test()
public void testSaveCompleteReviewOutcomeTasksProcessWithVariables() {
// given
securityUtil.logInAs("user");
Map<String, Object> startVariables = new HashMap<>();
startVariables.put("name", "");
// when
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(COMPLETE_REVIEW_TASK_PROCESS).withVariables(startVariables).build());
// complete task
securityUtil.logInAs("garth");
Task task1 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", ""));
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task1.getId()).withVariable("name", "wrong").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).build());
// reject task
securityUtil.logInAs("user");
Task task2 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables1 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build());
assertThat(variables1).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", "wrong"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task2.getId()).withVariable("approved", false).build());
// fix task
securityUtil.logInAs("garth");
Task task3 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task3.getId()).withVariable("name", "correct").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task3.getId()).build());
// approve task
securityUtil.logInAs("user");
Task task4 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables2 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task4.getId()).build());
assertThat(variables2).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("name", "correct"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task4.getId()).withVariable("approved", true).build());
// then process completes
Throwable throwable = catchThrowable(() -> assertThat(processRuntime.processInstance(processInstance.getId())).isNull());
assertThat(throwable).isInstanceOf(NotFoundException.class);
}
use of org.activiti.api.model.shared.model.VariableInstance in project Activiti by Activiti.
the class ProcessVariablesTest method shouldGetRightVariableType.
@Test
public void shouldGetRightVariableType() {
securityUtil.logInAs("user1");
startProcess();
setVariables();
VariableInstance variableOneRuntime = variableInstanceList.get(0);
VariableInstance variableTwoRuntime = variableInstanceList.get(1);
assertThat(variableOneRuntime.getType()).isEqualTo("string");
assertThat(variableTwoRuntime.getType()).isEqualTo("integer");
assertThat(RuntimeTestConfiguration.collectedEvents).extracting("eventType", "entity.name", "entity.value").containsExactly(tuple(VariableEvent.VariableEvents.VARIABLE_CREATED, variableInstanceList.get(0).getName(), variableInstanceList.get(0).getValue()), tuple(VariableEvent.VariableEvents.VARIABLE_CREATED, variableInstanceList.get(1).getName(), variableInstanceList.get(1).getValue()));
}
Aggregations