Search in sources :

Example 6 with HumanTaskTransition

use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.

the class CallActivityTaskTest method testCallActivityTaskWithSubprocesWaitBusinessKeyFromVars.

@Test
public void testCallActivityTaskWithSubprocesWaitBusinessKeyFromVars() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/CallActivity.bpmn2", "subprocess/CallActivitySubProcessHT.bpmn2", "subprocess/CallActivitySubProcessHT2.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("ParentProcess_1");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "a");
    parameters.put("y", "b");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("x", "y");
    assertThat(p.instances().findById("b")).isPresent();
    // check if tasks can be accessed via parent process instance even if they are
    // in subprocesses
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("User Task 1", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    // following check shows that task(wi) comes from another process instance
    assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
    Collection<ProcessInstance<? extends Model>> subprocesses = processInstance.subprocesses();
    assertThat(subprocesses).hasSize(1);
    ProcessInstance<?> childProcessInstance = subprocesses.iterator().next();
    // verify that sub processes can be access by business key defined via variable tagging
    Process<? extends Model> sp = (Process<? extends Model>) childProcessInstance.process();
    Optional<?> found = sp.instances().findById("b:a");
    assertThat(found).isPresent();
    workItems = childProcessInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("User Task 1", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    childProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("User Task 2", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    // following check shows that task(wi) comes from another process instance
    assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
    subprocesses = childProcessInstance.subprocesses();
    assertThat(subprocesses).hasSize(1);
    ProcessInstance<?> subChildProcessInstance = subprocesses.iterator().next();
    subChildProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) Process(io.automatiko.engine.api.workflow.Process) WorkItem(io.automatiko.engine.api.workflow.WorkItem) HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 7 with HumanTaskTransition

use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.

the class CallActivityTaskTest method testCallActivityTaskWithSubprocesWait.

@Test
public void testCallActivityTaskWithSubprocesWait() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/CallActivity.bpmn2", "subprocess/CallActivitySubProcessHT.bpmn2", "subprocess/CallActivitySubProcessHT2.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("ParentProcess_1");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "a");
    parameters.put("y", "b");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance("custom-key", m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("x", "y");
    assertThat(p.instances().findById("custom-key")).isPresent();
    assertThat(p.instances().findById("b")).isNotPresent();
    // check if tasks can be accessed via parent process instance even if they are
    // in subprocesses
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("User Task 1", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    // following check shows that task(wi) comes from another process instance
    assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
    Collection<ProcessInstance<? extends Model>> subprocesses = processInstance.subprocesses();
    assertThat(subprocesses).hasSize(1);
    ProcessInstance<?> childProcessInstance = subprocesses.iterator().next();
    // verify that sub processes can be access by business key defined via variable tagging
    Process<? extends Model> sp = (Process<? extends Model>) childProcessInstance.process();
    Optional<?> found = sp.instances().findById("custom-key:a");
    assertThat(found).isPresent();
    workItems = childProcessInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("User Task 1", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    childProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("User Task 2", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    // following check shows that task(wi) comes from another process instance
    assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
    subprocesses = childProcessInstance.subprocesses();
    assertThat(subprocesses).hasSize(1);
    ProcessInstance<?> subChildProcessInstance = subprocesses.iterator().next();
    subChildProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) Process(io.automatiko.engine.api.workflow.Process) WorkItem(io.automatiko.engine.api.workflow.WorkItem) HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 8 with HumanTaskTransition

use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.

the class UserTaskTest method testBasicUserTaskProcessCancelAndRetriggerNode.

@Test
public void testBasicUserTaskProcessCancelAndRetriggerNode() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().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(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) WorkItem(io.automatiko.engine.api.workflow.WorkItem) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 9 with HumanTaskTransition

use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.

the class UserTaskTest method testApprovalWithExcludedOwnerViaPhases.

@Test
public void testApprovalWithExcludedOwnerViaPhases() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/approval.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("approvals");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.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(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) HashMap(java.util.HashMap) WorkItem(io.automatiko.engine.api.workflow.WorkItem) HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 10 with HumanTaskTransition

use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.

the class UserTaskTest method testBasicUserTaskProcessClaimAndCompleteWrongUser.

@Test
public void testBasicUserTaskProcessClaimAndCompleteWrongUser() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().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());
    final String wiId = wi.getId();
    IdentityProvider identity = new StaticIdentityProvider("kelly");
    // if user that is not authorized to work on work item both listing and getting
    // by id should apply it
    List<WorkItem> securedWorkItems = processInstance.workItems(SecurityPolicy.of(identity));
    assertEquals(0, securedWorkItems.size());
    assertThrows(WorkItemNotFoundException.class, () -> processInstance.workItem(wiId, SecurityPolicy.of(identity)));
    assertThrows(NotAuthorizedException.class, () -> processInstance.transitionWorkItem(wiId, new HumanTaskTransition(Claim.ID, null, identity)));
    assertThrows(NotAuthorizedException.class, () -> processInstance.completeWorkItem(wiId, null, SecurityPolicy.of(identity)));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    IdentityProvider identityCorrect = new StaticIdentityProvider("john");
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, identityCorrect));
    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 : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) HashMap(java.util.HashMap) StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) WorkItem(io.automatiko.engine.api.workflow.WorkItem) HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

Application (io.automatiko.engine.api.Application)13 Model (io.automatiko.engine.api.Model)13 WorkItem (io.automatiko.engine.api.workflow.WorkItem)13 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)13 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)13 HashMap (java.util.HashMap)13 Test (org.junit.jupiter.api.Test)13 Process (io.automatiko.engine.api.workflow.Process)2 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)2 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)2 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)1 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)1 DefaultProcessEventListener (io.automatiko.engine.api.event.process.DefaultProcessEventListener)1 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)1 Address (io.automatiko.engine.codegen.data.Address)1 Person (io.automatiko.engine.codegen.data.Person)1 PersonWithAddress (io.automatiko.engine.codegen.data.PersonWithAddress)1 ArrayList (java.util.ArrayList)1