Search in sources :

Example 16 with WorkItem

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();
}
Also used : ActionNode(org.jbpm.workflow.core.node.ActionNode) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Collection(java.util.Collection) AdHocFragment(org.kie.kogito.process.flexible.AdHocFragment) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Application(org.kie.kogito.Application) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) ProcessInstance(org.kie.kogito.process.ProcessInstance) Model(org.kie.kogito.Model) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) Map(java.util.Map) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Process(org.kie.kogito.process.Process) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) WorkItem(org.kie.kogito.process.WorkItem) Test(org.junit.jupiter.api.Test)

Example 17 with WorkItem

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);
}
Also used : HashMap(java.util.HashMap) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) WorkItem(org.kie.kogito.process.WorkItem) Test(org.junit.jupiter.api.Test)

Example 18 with WorkItem

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());
}
Also used : HashMap(java.util.HashMap) Model(org.kie.kogito.Model) WorkItem(org.kie.kogito.process.WorkItem) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 19 with WorkItem

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);
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 20 with WorkItem

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;
}
Also used : ArrayList(java.util.ArrayList) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) WorkItem(org.kie.kogito.process.WorkItem) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) NodeInstance(org.jbpm.workflow.instance.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Aggregations

WorkItem (org.kie.kogito.process.WorkItem)41 Test (org.junit.jupiter.api.Test)38 HashMap (java.util.HashMap)27 Model (org.kie.kogito.Model)26 Application (org.kie.kogito.Application)24 Processes (org.kie.kogito.process.Processes)24 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)14 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)14 HumanTaskTransition (org.jbpm.process.instance.impl.humantask.HumanTaskTransition)11 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)9 ArrayList (java.util.ArrayList)7 ClassPathResource (org.drools.util.io.ClassPathResource)7 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)5 List (java.util.List)4 Person (org.kie.kogito.codegen.data.Person)3 ProcessConfig (org.kie.kogito.process.ProcessConfig)3 UnitOfWork (org.kie.kogito.uow.UnitOfWork)3 Optional (java.util.Optional)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ActionNode (org.jbpm.workflow.core.node.ActionNode)2