Search in sources :

Example 26 with WorkItem

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

the class UserTaskIT method testApprovalWithExcludedOwnerViaPhases.

@Test
public void testApprovalWithExcludedOwnerViaPhases() 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());
    HumanTaskTransition transition = new HumanTaskTransition(Complete.ID, null, identity);
    processInstance.transitionWorkItem(workItems.get(0).getId(), transition);
    // 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());
    transition = new HumanTaskTransition(Complete.ID, null, identity);
    processInstance.transitionWorkItem(workItems.get(0).getId(), transition);
    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) HumanTaskTransition(org.jbpm.process.instance.impl.humantask.HumanTaskTransition) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 27 with WorkItem

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

the class UserTaskIT method testBasicUserTaskProcessCancelAndTriggerNode.

@Test
public void testBasicUserTaskProcessCancelAndTriggerNode() 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());
    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());
    String firstSecondTaskNodeInstanceId = wi.getNodeInstanceId();
    processInstance.cancelNodeInstance(wi.getNodeInstanceId());
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    processInstance.triggerNode("UserTask_2");
    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());
    // since it was triggered again it must have different node instance id
    assertNotEquals(firstSecondTaskNodeInstanceId, wi.getNodeInstanceId());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
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)

Example 28 with WorkItem

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

the class UserTaskIT method testBasicUserTaskProcessWithBusinessKey.

@Test
public void testBasicUserTaskProcessWithBusinessKey() 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);
    // assign custom business key for process instance
    String businessKey = "business key";
    ProcessInstance<?> processInstance = p.createInstance(businessKey, m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // verify that custom business key is assigned properly
    assertThat(processInstance.businessKey()).isEqualTo(businessKey);
    // find the process instance by ID and verify business key
    Optional<? extends ProcessInstance<? extends Model>> processInstanceByBussinesKey = p.instances().findById(processInstance.id());
    assertThat(processInstanceByBussinesKey.isPresent()).isTrue();
    assertThat(processInstanceByBussinesKey.get().businessKey()).isEqualTo(businessKey);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(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 29 with WorkItem

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

the class UserTaskIT method testUserTaskWithIOexpressionProcess.

@Test
public void testUserTaskWithIOexpressionProcess() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTaskWithIOexpression.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("UserTask");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("person", new Person("john", 0));
    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());
    assertEquals("Hello", workItems.get(0).getName());
    assertEquals("john", workItems.get(0).getParameters().get("personName"));
    processInstance.completeWorkItem(workItems.get(0).getId(), Collections.singletonMap("personAge", 50), securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model output = (Model) processInstance.variables();
    Person person = (Person) output.toMap().get("person");
    assertEquals(50, person.getAge());
}
Also used : HashMap(java.util.HashMap) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) WorkItem(org.kie.kogito.process.WorkItem) Test(org.junit.jupiter.api.Test)

Example 30 with WorkItem

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

the class UserTaskIT method testBasicUserTaskProcessCancelAndRetriggerNode.

@Test
public void testBasicUserTaskProcessCancelAndRetriggerNode() 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());
    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());
    String firstSecondTaskNodeInstanceId = wi.getNodeInstanceId();
    processInstance.retriggerNodeInstance(wi.getNodeInstanceId());
    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());
    // since it was retriggered it must have different node instance id
    assertNotEquals(firstSecondTaskNodeInstanceId, wi.getNodeInstanceId());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
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