use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class EventImplTest method setup.
@BeforeEach
void setup() {
application = mock(Application.class);
when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
process = mock(Process.class);
processInstances = mock(ProcessInstances.class);
processInstance = mock(ProcessInstance.class);
when(process.instances()).thenReturn(processInstances);
when(processInstances.findById(Mockito.anyString())).thenReturn(Optional.of(processInstance));
when(process.createInstance(Mockito.any(DummyModel.class))).thenReturn(processInstance);
processService = mock(ProcessService.class);
executor = Executors.newSingleThreadExecutor();
}
use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class PublishEventIT method testProcessWithMilestoneEvents.
@Test
public void testProcessWithMilestoneEvents() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.get(Processes.class).processById("TestCase.SimpleMilestone");
ProcessInstance<?> processInstance = p.createInstance(p.createModel());
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
uow.end();
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
DataEvent<?> event = events.get(0);
assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
assertThat(processDataEvent.getKogitoProcessinstanceId()).isNotNull();
assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("TestCase.SimpleMilestone");
assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/SimpleMilestone");
Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class AdHocFragmentsIT 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.get(Processes.class).processById("TestCase.AdHocFragments");
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 org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class HumanTaskServiceImpl method get.
@Override
public ExtendedDataContext get(LocalId id, MetaDataContext meta) {
TaskMetaDataContext metaCtx = meta.as(TaskMetaDataContext.class);
SecurityPolicy securityPolicy = convertPolicyObject(metaCtx.policy());
try {
// /tasks
TaskIds taskIds = ProcessIdParser.select(id, TaskIds.class);
ProcessInstanceId instanceId = taskIds.processInstanceId();
Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
String processInstanceIdString = instanceId.processInstanceId();
List<String> tasks = svc.getTasks(process, processInstanceIdString, securityPolicy).orElseThrow().stream().map(wi -> taskIds.get(wi.getName()).instances().get(wi.getId()).asLocalUri().path()).collect(Collectors.toList());
MapDataContext mdc = MapDataContext.create();
mdc.set("tasks", tasks);
return ExtendedDataContext.of(mdc, EmptyDataContext.Instance);
} catch (IllegalArgumentException e) {
// /tasks/id
TaskInstanceId taskInstanceId = ProcessIdParser.select(id, TaskInstanceId.class);
ProcessInstanceId instanceId = taskInstanceId.taskId().processInstanceId();
Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
String taskInstanceIdString = taskInstanceId.taskInstanceId();
String processInstanceIdString = instanceId.processInstanceId();
WorkItem workItem = svc.getTask(process, processInstanceIdString, taskInstanceIdString, securityPolicy, Function.identity()).orElseThrow(() -> new IllegalArgumentException("Cannot find ID " + id.asLocalUri().path()));
return ExtendedDataContext.ofData(MapDataContext.of(workItem.getResults()));
}
}
use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class StatefulProcessServiceImpl method create.
@Override
public ExtendedDataContext create(LocalId localId, DataContext inputContext) {
LocalProcessId processId = ProcessIdParser.select(localId, LocalProcessId.class);
ExtendedDataContext extendedDataContext = inputContext.as(ExtendedDataContext.class);
ProcessMetaDataContext inputMeta = inputContext.as(ProcessMetaDataContext.class);
Process<Model> process = (Process<Model>) (Object) parseProcess(processId);
String businessKey = inputMeta.businessKey();
Model model = toModel(extendedDataContext.data(), process);
String startFromNodeId = inputMeta.startFrom();
ProcessInstance<Model> instance = svc.createProcessInstance(process, businessKey, model, startFromNodeId);
MapDataContext data = MapDataContext.from(instance.variables().toMap());
ProcessMetaDataContext meta = ProcessMetaDataContext.of(processId.instances().get(instance.id()));
return ExtendedDataContext.of(meta, data);
}
Aggregations