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