use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class $Type$Resource method $parentprocessprefix$_getTask.
@Query
@Description("Retrieves $taskName$ task instance with given id")
public $TaskInput$ $parentprocessprefix$_getTask(@Name("parentId") String id, @Name("id") String id_$name$, @Name("workItemId") final String workItemId, @Name("user") final String user, @Name("group") final List<String> groups) {
try {
identitySupplier.buildIdentityProvider(user, groups);
return io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
String combinedId;
if (id_$name$.contains(":")) {
combinedId = id_$name$;
} else {
combinedId = $parentprocessid$ + ":" + id_$name$;
}
ProcessInstance<$Type$> pi = subprocess_$name$.instances().findById(combinedId, io.automatiko.engine.api.workflow.ProcessInstanceReadMode.READ_ONLY).orElseThrow(() -> new ProcessInstanceNotFoundException(id_$name$));
WorkItem workItem = pi.workItem(workItemId, policies(user, groups));
if (workItem == null) {
return null;
}
return $TaskInput$.fromMap(workItem.getId(), workItem.getName(), workItem.getParameters());
});
} catch (WorkItemNotFoundException e) {
return null;
} finally {
IdentityProvider.set(null);
}
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlowControlledByUnitOfWork.
@Test
void testBasicFlowControlledByUnitOfWork() {
UnitOfWorkManager uowManager = new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory());
ProcessConfig config = new StaticProcessConfig(new DefaultWorkItemHandlerConfig(), new DefaultProcessEventListenerConfig(), uowManager, null, new DefaultVariableInitializer(), new FileSystemProcessInstancesFactory());
BpmnProcess process = createProcess(config, "BPMN2-UserTask.bpmn2");
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
UnitOfWork uow = uowManager.newUnitOfWork();
uow.start();
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
assertThat(processInstance.description()).isEqualTo("User Task");
assertThat(process.instances().values(1, 10)).hasSize(1);
FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(2)).create(any(), any());
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
assertThat(processInstance.description()).isEqualTo("User Task");
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
uow = uowManager.newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
uow.end();
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(1)).remove(any(), any());
assertThat(fileSystemBasedStorage.size()).isZero();
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlowVersionedProcess.
@Test
void testBasicFlowVersionedProcess() {
BpmnProcess process = createProcess(null, "BPMN2-UserTaskVersioned.bpmn2");
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
processInstance.start();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
assertThat(processInstance.description()).isEqualTo("User Task");
FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
assertThat(fileSystemBasedStorage.size()).isOne();
verify(fileSystemBasedStorage, times(2)).create(any(), any());
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
assertThat(processInstance.description()).isEqualTo("User Task");
assertThat(process.instances().values(1, 10).iterator().next().workItems(securityPolicy)).hasSize(1);
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(2)).remove(any(), any());
assertThat(fileSystemBasedStorage.size()).isZero();
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlowWithTransientVariable.
@Test
void testBasicFlowWithTransientVariable() {
BpmnProcess process = createProcess(null, "BPMN2-UserTask.bpmn2");
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("temp", "test")));
processInstance.start();
assertThat(processInstance.variables().get("temp")).isEqualTo("test");
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
assertThat(processInstance.description()).isEqualTo("User Task");
FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
assertThat(fileSystemBasedStorage.size()).isOne();
ProcessInstance<BpmnVariables> processInstanceLoaded = (ProcessInstance<BpmnVariables>) fileSystemBasedStorage.findById(processInstance.id()).get();
assertThat(processInstanceLoaded.variables().get("temp")).isNull();
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(2)).remove(any(), any());
assertThat(fileSystemBasedStorage.size()).isZero();
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class PredictionAwareHumanTaskLifeCycleTest method testUserTaskWithoutPredictionService.
@Test
public void testUserTaskWithoutPredictionService() {
BpmnProcess process = (BpmnProcess) BpmnProcess.from(config, new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
processInstance.start();
assertEquals(STATE_ACTIVE, processInstance.status());
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertNotNull(workItem);
assertEquals("john", workItem.getParameters().get("ActorId"));
processInstance.completeWorkItem(workItem.getId(), Collections.singletonMap("output", "given value"), securityPolicy);
assertEquals(STATE_COMPLETED, processInstance.status());
Model result = (Model) processInstance.variables();
assertEquals(2, result.toMap().size());
assertEquals("given value", result.toMap().get("s"));
assertEquals(1, trainedTasks.size());
}
Aggregations