use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.
the class AdHocFragmentsIT method testStartUserTask.
@Test
void testStartUserTask() throws Exception {
String taskName = "AdHoc User Task";
Application app = generateCodeProcessesOnly("cases/AdHocFragments.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("TestCase.AdHocFragments");
ProcessInstance<? extends Model> processInstance = p.createInstance(p.createModel());
processInstance.start();
Optional<WorkItem> workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
assertThat(workItem).isNotPresent();
processInstance.send(Sig.of(taskName, p.createModel()));
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
assertThat(workItem).isPresent();
assertThat(workItem.get().getId()).isNotBlank();
assertThat(workItem.get().getName()).isNotBlank();
}
use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.
the class AdHocSubProcessIT method testActivationAdHoc.
@Test
void testActivationAdHoc() throws Exception {
Application app = generateCodeProcessesOnly("cases/ActivationAdHoc.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("TestCase.ActivationAdHoc");
Model model = p.createModel();
Map<String, Object> params = new HashMap<>();
params.put("favouriteColour", "yellow");
model.fromMap(params);
ProcessInstance<?> processInstance = p.createInstance(model);
assertState(processInstance, ProcessInstance.STATE_PENDING);
processInstance.start();
assertState(processInstance, ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems();
assertThat(workItems.size()).isEqualTo(1);
WorkItem workItem = workItems.get(0);
params = new HashMap<>();
params.put("favouriteColour", "blue");
processInstance.completeWorkItem(workItem.getId(), params);
assertState(processInstance, ProcessInstance.STATE_COMPLETED);
}
use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.
the class PersonProcessTest method testChild.
@Test
public void testChild() {
Model m = personProcess.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("person", new Person("Jenny Quark", 14));
m.fromMap(parameters);
ProcessInstance<?> processInstance = personProcess.createInstance(m);
processInstance.start();
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
Model result = (Model) processInstance.variables();
assertEquals(1, result.toMap().size());
assertFalse(((Person) result.toMap().get("person")).isAdult());
List<WorkItem> workItems = processInstance.workItems();
assertEquals(1, workItems.size());
processInstance.completeWorkItem(workItems.get(0).getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.status());
}
use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.
the class KafkaProcessInstancesIT method testBasicFlow.
@Test
void testBasicFlow() {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
listener.setKafkaStreams(createStreams());
process.setProcessInstancesFactory(factory);
process.configure();
listener.getKafkaStreams().start();
ProcessInstances<BpmnVariables> instances = process.instances();
assertThat(instances.size()).isZero();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(singletonMap("test", "test")));
processInstance.start();
assertEquals(STATE_ACTIVE, processInstance.status());
await().atMost(TIMEOUT).until(() -> instances.values().size() == 1);
SecurityPolicy asJohn = SecurityPolicy.of(IdentityProviders.of("john"));
assertThat(instances.values().iterator().next().workItems(asJohn)).hasSize(1);
List<WorkItem> workItems = processInstance.workItems(asJohn);
assertThat(workItems).hasSize(1);
WorkItem workItem = workItems.get(0);
assertEquals("john", workItem.getParameters().get("ActorId"));
processInstance.completeWorkItem(workItem.getId(), null, asJohn);
assertEquals(STATE_COMPLETED, processInstance.status());
await().atMost(TIMEOUT).until(() -> instances.size() == 0);
}
use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.
the class AbstractProcessInstance method workItems.
@Override
public List<WorkItem> workItems(Predicate<KogitoNodeInstance> p, Policy<?>... policies) {
List<WorkItem> list = new ArrayList<>();
for (NodeInstance ni : processInstance().getNodeInstances(true)) {
if (p.test(ni) && ((WorkItemNodeInstance) ni).getWorkItem().enforce(policies)) {
BaseWorkItem taskName = new BaseWorkItem(ni.getStringId(), ((WorkItemNodeInstance) ni).getWorkItemId(), Long.toString(ni.getNode().getId()), (String) ((WorkItemNodeInstance) ni).getWorkItem().getParameters().getOrDefault("TaskName", ni.getNodeName()), ((WorkItemNodeInstance) ni).getWorkItem().getState(), ((WorkItemNodeInstance) ni).getWorkItem().getPhaseId(), ((WorkItemNodeInstance) ni).getWorkItem().getPhaseStatus(), ((WorkItemNodeInstance) ni).getWorkItem().getParameters(), ((WorkItemNodeInstance) ni).getWorkItem().getResults());
list.add(taskName);
}
}
return list;
}
Aggregations