Search in sources :

Example 26 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.

the class MilestoneTest method testConditionalMilestone.

@Test
void testConditionalMilestone() throws Exception {
    Application app = generateCodeProcessesOnly("cases/milestones/ConditionalMilestone.bpmn");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("TestCase.ConditionalMilestone_1_0");
    Model model = p.createModel();
    Map<String, Object> params = new HashMap<>();
    params.put("favouriteColour", "orange");
    model.fromMap(params);
    ProcessInstance<?> processInstance = p.createInstance(model);
    assertState(processInstance, ProcessInstance.STATE_PENDING);
    Collection<Milestone> expected = new ArrayList<>();
    expected.add(Milestone.builder().withName("Milestone").withStatus(AVAILABLE).build());
    assertMilestones(expected, processInstance.milestones());
    processInstance.start();
    assertState(processInstance, ProcessInstance.STATE_ACTIVE);
    expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(AVAILABLE).build()).collect(Collectors.toList());
    assertMilestones(expected, processInstance.milestones());
    List<WorkItem> workItems = processInstance.workItems();
    params.put("favouriteColour", "blue");
    processInstance.completeWorkItem(workItems.get(0).getId(), params);
    expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(COMPLETED).build()).collect(Collectors.toList());
    assertMilestones(expected, processInstance.milestones());
}
Also used : HashMap(java.util.HashMap) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) ArrayList(java.util.ArrayList) WorkItem(io.automatiko.engine.api.workflow.WorkItem) 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 27 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.

the class ExportProcessInstanceTest method testBasicUserTaskProcessArchive.

@Test
public void testBasicUserTaskProcessArchive() 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<>();
    parameters.put("name", "John");
    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("FirstTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // archive active process instance
    ArchivedProcessInstance archived = processInstance.archive(new ArchiveBuilder() {

        @Override
        public ArchivedVariable variable(String name, Object value) {
            return new ArchivedVariable(name, value) {

                @Override
                public byte[] data() {
                    return getValue().toString().getBytes();
                }
            };
        }

        @Override
        public ArchivedProcessInstance instance(String id, String processId, ExportedProcessInstance<?> exported) {
            return new ArchivedProcessInstance(id, processId, exported);
        }
    });
    assertThat(archived).isNotNull();
    assertThat(archived.getExport()).isNotNull();
    assertThat(archived.getVariables()).isNotNull();
    assertThat(archived.getSubInstances()).isNotNull();
    assertThat(archived.getVariables()).hasSize(1);
    assertThat(archived.getSubInstances()).hasSize(0);
    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);
    // and now let's export completed instance
    archived = processInstance.archive(new ArchiveBuilder() {

        @Override
        public ArchivedVariable variable(String name, Object value) {
            return new ArchivedVariable(name, value) {

                @Override
                public byte[] data() {
                    return getValue().toString().getBytes();
                }
            };
        }

        @Override
        public ArchivedProcessInstance instance(String id, String processId, ExportedProcessInstance<?> exported) {
            return new ArchivedProcessInstance(id, processId, exported);
        }
    });
    assertThat(archived).isNotNull();
    assertThat(archived.getExport()).isNotNull();
    assertThat(archived.getVariables()).isNotNull();
    assertThat(archived.getSubInstances()).isNotNull();
    assertThat(archived.getVariables()).hasSize(1);
    assertThat(archived.getSubInstances()).hasSize(0);
}
Also used : HashMap(java.util.HashMap) ArchivedVariable(io.automatiko.engine.api.workflow.ArchivedVariable) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) ArchiveBuilder(io.automatiko.engine.api.workflow.ArchiveBuilder) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 28 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem 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 29 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem 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 30 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.

the class CompensationEventTest method testEndEventCompensationEventProcess.

@Test
public void testEndEventCompensationEventProcess() throws Exception {
    Application app = generateCodeProcessesOnly("compensation/UserTaskBeforeAssociatedActivityEnd.bpmn2");
    Process<? extends Model> p = app.processes().processById("CompensateEndEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "0");
    m.fromMap(parameters);
    ProcessInstance<? extends Model> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems();
    assertEquals(1, workItems.size());
    assertEquals("task", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(processInstance.variables().toMap()).containsEntry("x", "1");
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Test(org.junit.jupiter.api.Test) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest)

Aggregations

WorkItem (io.automatiko.engine.api.workflow.WorkItem)51 Test (org.junit.jupiter.api.Test)46 Model (io.automatiko.engine.api.Model)41 Application (io.automatiko.engine.api.Application)39 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)39 HashMap (java.util.HashMap)38 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)13 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)8 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)7 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)7 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)6 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)5 ArrayList (java.util.ArrayList)5 WorkItemNotFoundException (io.automatiko.engine.api.runtime.process.WorkItemNotFoundException)4 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)3 DataEvent (io.automatiko.engine.api.event.DataEvent)3 DefaultProcessEventListener (io.automatiko.engine.api.event.process.DefaultProcessEventListener)3 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)3 Process (io.automatiko.engine.api.workflow.Process)3 Person (io.automatiko.engine.codegen.data.Person)3