Search in sources :

Example 6 with ProcessInstance

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

the class TimerEventTest method testStartTimerEventTimeCycleCron.

@Test
public void testStartTimerEventTimeCycleCron() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerCycleCron.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 2);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(2);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // deactivate to cancel timer, so there should be no more timers fired
    p.deactivate();
    // reset the listener to make sure nothing more is triggered
    listener.reset(1);
    completed = listener.waitTillCompleted(3000);
    // same amount of instances should be active as before deactivation
    instances = p.instances().values(1, 10);
    // clean up by aborting all instances
    instances.forEach(i -> ((ProcessInstance<?>) i).abort());
    instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(0);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) 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 ProcessInstance

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

the class ParticipantsAccessPolicy method whenInitiatorNotSetOrAsIdentity.

@SuppressWarnings("unchecked")
protected boolean whenInitiatorNotSetOrAsIdentity(IdentityProvider identityProvider, ProcessInstance<T> instance) {
    if (identityProvider.isAdmin()) {
        return true;
    }
    WorkflowProcessInstance pi = (WorkflowProcessInstance) ((AbstractProcessInstance<?>) instance).processInstance();
    if (pi.getInitiator() == null || pi.getInitiator().isEmpty() || pi.getInitiator().equals(identityProvider.getName())) {
        return true;
    }
    // next check if the user/group is assigned to any of the active user tasks that
    // can make it eligible to access the instance
    boolean result = ((WorkflowProcessInstanceImpl) pi).getNodeInstances(true).stream().filter(ni -> ni instanceof HumanTaskNodeInstance).anyMatch(ni -> {
        HumanTaskWorkItem workitem = (HumanTaskWorkItem) ((HumanTaskNodeInstance) ni).getWorkItem();
        return workitem.enforce(SecurityPolicy.of(identityProvider));
    });
    if (!result) {
        result = instance.subprocesses().stream().anyMatch(spi -> whenInitiatorNotSetOrAsIdentity(identityProvider, (ProcessInstance<T>) spi));
    }
    return result;
}
Also used : HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Set(java.util.Set) AccessPolicy(io.automatiko.engine.api.auth.AccessPolicy) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Example 8 with ProcessInstance

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

the class CassandraProcessInstances method importInstance.

@Override
public ProcessInstance importInstance(ExportedProcessInstance instance, Process process) {
    ProcessInstance imported = marshaller.importProcessInstance(instance, process);
    if (exists(imported.id())) {
        throw new ProcessInstanceDuplicatedException(imported.id());
    }
    create(imported.id(), imported);
    return imported;
}
Also used : ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance)

Example 9 with ProcessInstance

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

the class AdHocFragmentsTest method testStartUserTask.

@Test
void testStartUserTask() throws Exception {
    String taskName = "AdHoc User Task";
    Application app = generateCodeProcessesOnly("cases/AdHocFragments.bpmn");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("TestCase.AdHocFragments_1_0");
    ProcessInstance<? extends Model> processInstance = p.createInstance(p.createModel());
    processInstance.start();
    Optional<WorkItem> workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
    assertThat(workItem).isNotPresent();
    processInstance.send(Sig.of(taskName, p.createModel()));
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
    workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
    assertThat(workItem).isPresent();
    assertThat(workItem.get().getId()).isNotBlank();
    assertThat(workItem.get().getName()).isNotBlank();
}
Also used : AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Model(io.automatiko.engine.api.Model) AdHocFragment(io.automatiko.engine.api.workflow.flexible.AdHocFragment) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collection(java.util.Collection) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) HashMap(java.util.HashMap) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Application(io.automatiko.engine.api.Application) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) Sig(io.automatiko.engine.workflow.Sig) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Optional(java.util.Optional) Process(io.automatiko.engine.api.workflow.Process) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) WorkItem(io.automatiko.engine.api.workflow.WorkItem) 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 10 with ProcessInstance

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

the class CallActivityTaskTest method testCallActivityTaskWithSubprocesWaitAndAbort.

@Test
public void testCallActivityTaskWithSubprocesWaitAndAbort() 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");
    // 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();
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    assertThat(childProcessInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    subprocesses = processInstance.subprocesses();
    assertThat(subprocesses).hasSize(0);
    assertThat(p.instances().size()).isEqualTo(0);
    assertThat(childProcessInstance.process().instances().size()).isEqualTo(0);
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) 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)

Aggregations

ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)63 Model (io.automatiko.engine.api.Model)29 Application (io.automatiko.engine.api.Application)26 HashMap (java.util.HashMap)23 Test (org.junit.jupiter.api.Test)23 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)22 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)21 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)16 List (java.util.List)15 WorkItem (io.automatiko.engine.api.workflow.WorkItem)14 Process (io.automatiko.engine.api.workflow.Process)13 Optional (java.util.Optional)13 Map (java.util.Map)12 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)10 Collections (java.util.Collections)10 ProcessInstanceDuplicatedException (io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException)9 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 Collectors (java.util.stream.Collectors)9 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)8