Search in sources :

Example 21 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class MongoDBProcessInstancesIT method test.

private void test(MongoDBTransactionManager transactionManager) {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new MongoDBProcessInstancesFactory(mongoClient, transactionManager));
    process.configure();
    testIndexCreation(process);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("test", "test");
    parameters.put("integerVar", 10);
    parameters.put("booleanVar", true);
    parameters.put("doubleVar", 10.11);
    parameters.put("floatVar", 3.5f);
    parameters.put("address", new Address("main street", "Boston", "10005", "US"));
    PersonWithAddresses pa = new PersonWithAddresses("bob", 16);
    List<Address> list = new ArrayList<>();
    list.add(new Address("main street", "Boston", "10005", "US"));
    list.add(new Address("new Street", "Charlotte", "28200", "US"));
    pa.setAddresses(list);
    parameters.put("pa", pa);
    parameters.put("addresslist", list);
    Map<Object, Object> map = new HashMap<>();
    map.put("addresslist", list);
    map.put(1, "ss");
    map.put("2", "kk");
    Map<Object, Object> testMap = new HashMap<>();
    testMap.put("addresslist", list);
    testMap.put(1, "integer");
    testMap.put("2", "string");
    testMap.put("map", map);
    parameters.put("testMap", testMap);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(parameters));
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    Collection<? extends ProcessInstance<BpmnVariables>> values = process.instances().values();
    assertThat(values).hasSize(1);
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    Object addr = processInstance.variables().get("address");
    assertThat(addr.getClass().getName()).isEqualTo("org.kie.kogito.mongodb.Address");
    Object flt = processInstance.variables().get("floatVar");
    assertThat(flt.getClass().getName()).isEqualTo("java.lang.Float");
    assertThat(processInstance.description()).isEqualTo("User Task");
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertThat(workItems).hasSize(1);
    WorkItem workItem = workItems.get(0);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    assertEquals(STATE_COMPLETED, processInstance.status());
    assertThat(process.instances().size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables)

Example 22 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class PublishEventIT method testBasicUserTaskProcess.

@Test
public void testBasicUserTaskProcess() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active thus null for leave time
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    assertUserTaskInstanceEvent(events.get(1), "FirstTask", null, "1", "Ready", "UserTasksProcess", "First Task");
    List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(3);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active thus null for leave time
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    assertUserTaskInstanceEvent(events.get(1), "SecondTask", null, "1", "Ready", "UserTasksProcess", "Second Task");
    assertUserTaskInstanceEvent(events.get(2), "FirstTask", null, "1", "Completed", "UserTasksProcess", "First Task");
    workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertUserTaskInstanceEvent(events.get(1), "SecondTask", null, "1", "Completed", "UserTasksProcess", "Second Task");
}
Also used : StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) UnitOfWork(org.kie.kogito.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(org.kie.kogito.event.process.ProcessInstanceEventBody) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 23 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class SignalEventIT method testIntermediateSignalEventWithDataControlledByUnitOfWork.

@Test
public void testIntermediateSignalEventWithDataControlledByUnitOfWork() throws Exception {
    Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("signalevent/IntermediateCatchEventSignal.bpmn2"));
    resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
    Application app = generateCode(resourcesTypeMap);
    assertThat(app).isNotNull();
    // create first unit of work
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.get(Processes.class).processById("IntermediateCatchEventSignal");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    uow.end();
    // after the unit of work is ended process instance shows up in the list
    assertThat(p.instances().size()).isEqualTo(1);
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    List<WorkItem> workItems = processInstance.workItems();
    assertThat(workItems).hasSize(1);
    processInstance.completeWorkItem(workItems.get(0).getId(), null);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    uow.end();
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.send(Sig.of("MyMessage", "test"));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKey("x");
    assertThat(result.toMap().get("x")).isEqualTo("test");
    // since the unit of work is not ended yet there is still instance visible
    assertThat(p.instances().size()).isEqualTo(1);
    uow.end();
    // after unit of work is ended instance is gone from the list
    assertThat(p.instances().size()).isZero();
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) HashMap(java.util.HashMap) Model(org.kie.kogito.Model) List(java.util.List) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) WorkItem(org.kie.kogito.process.WorkItem) Test(org.junit.jupiter.api.Test)

Example 24 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class UserTaskIT method testApprovalWithExcludedOwner.

@Test
public void testApprovalWithExcludedOwner() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/approval.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("approvals");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.status());
    StaticIdentityProvider identity = new StaticIdentityProvider("admin", Collections.singletonList("managers"));
    SecurityPolicy policy = SecurityPolicy.of(identity);
    processInstance.workItems(policy);
    List<WorkItem> workItems = processInstance.workItems(policy);
    assertEquals(1, workItems.size());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
    // actual owner of the first task is excluded owner on the second task so won't find it
    workItems = processInstance.workItems(policy);
    assertEquals(0, workItems.size());
    identity = new StaticIdentityProvider("john", Collections.singletonList("managers"));
    policy = SecurityPolicy.of(identity);
    workItems = processInstance.workItems(policy);
    assertEquals(1, workItems.size());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
    assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.status());
}
Also used : StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) HashMap(java.util.HashMap) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 25 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class UserTaskIT method testBasicUserTaskProcessClaimAndCompletePhases.

@Test
public void testBasicUserTaskProcessClaimAndCompletePhases() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Claim.ID, wi.getPhase());
    assertEquals(Claim.STATUS, wi.getPhaseStatus());
    assertEquals(2, wi.getResults().size());
    assertEquals("value", wi.getResults().get("test"));
    assertEquals("john", wi.getResults().get("ActorId"));
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("SecondTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Also used : HumanTaskTransition(org.jbpm.process.instance.impl.humantask.HumanTaskTransition) 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)

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