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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations