use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class ProcessEventDispatcher method startNewInstance.
private ProcessInstance<M> startNewInstance(String trigger, Object event) {
if (modelConverter == null) {
return null;
}
final String businessKey = businessKeyResolver.resolve(event).asString();
final String fromNode = nodeIdResolver.resolve(event).asString();
// keep reference with the caller starting the instance (usually the caller process instance)
final String referenceId = referenceIdResolver.resolve(event).asString();
final Object data = dataResolver.apply(event);
// event correlation, extract if any, the workflow instance correlation
final CompositeCorrelation correlation = instanceCorrelationResolver.map(r -> r.resolve(event)).orElse(null);
LOGGER.info("Starting new process instance with signal '{}'", trigger);
return processService.createProcessInstance(process, businessKey, modelConverter.apply(data), fromNode, trigger, referenceId, correlation);
}
use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class ProcessEventDispatcherTest 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(processInstance.id()).thenReturn("1");
when(process.instances()).thenReturn(processInstances);
correlationService = spy(new DefaultCorrelationService());
when(process.correlations()).thenReturn(correlationService);
when(processInstances.findById(Mockito.anyString())).thenReturn(Optional.empty());
when(processInstances.findById("1")).thenReturn(Optional.of(processInstance));
processService = mock(ProcessService.class);
when(processService.createProcessInstance(eq(process), any(), any(), any(), any(), any(), any())).thenReturn(processInstance);
when(processService.signalProcessInstance(eq(process), any(), any(), any())).thenReturn(Optional.of(mock(DummyModel.class)));
executor = Executors.newSingleThreadExecutor();
}
use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class ProcessEventDispatcherTest method testSigCloudEventWithCorrelation.
@Test
void testSigCloudEventWithCorrelation() throws Exception {
String userId = "userId";
String name = "name";
String userValue = UUID.randomUUID().toString();
String nameValue = UUID.randomUUID().toString();
SimpleCorrelation<String> userCorrelation = new SimpleCorrelation<>(userId, userValue);
SimpleCorrelation<String> nameCorrelation = new SimpleCorrelation<>(name, nameValue);
Set<Correlation<?>> correlations = Set.of(userCorrelation, nameCorrelation);
CompositeCorrelation compositeCorrelation = new CompositeCorrelation(correlations);
correlationService.create(compositeCorrelation, "1");
EventDispatcher<DummyModel> dispatcher = new ProcessEventDispatcher<>(process, modelConverter().get(), processService, executor, correlations.stream().map(Correlation::getKey).collect(Collectors.toSet()), AbstractMessageConsumer::cloudEventResolver);
DummyCloudEvent event = new DummyCloudEvent(new DummyEvent("pepe"), DUMMY_TOPIC, "source");
event.addExtensionAttribute(userId, userValue);
event.addExtensionAttribute(name, nameValue);
ProcessInstance<DummyModel> instance = dispatcher.dispatch(DUMMY_TOPIC, event).toCompletableFuture().get();
ArgumentCaptor<String> signal = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> processInstanceId = ArgumentCaptor.forClass(String.class);
verify(correlationService).find(compositeCorrelation);
verify(processService).signalProcessInstance(Mockito.any(Process.class), processInstanceId.capture(), Mockito.any(Object.class), signal.capture());
assertEquals("Message-" + DUMMY_TOPIC, signal.getValue());
assertEquals("1", processInstanceId.getValue());
assertEquals(instance, processInstance);
}
use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class HumanTaskServiceImpl method update.
@Override
public ExtendedDataContext update(LocalId id, DataContext dataContext) {
ExtendedDataContext edc = dataContext.as(ExtendedDataContext.class);
TaskMetaDataContext mdc = edc.meta().as(TaskMetaDataContext.class);
SecurityPolicy securityPolicy = convertPolicyObject(mdc.policy());
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();
Map<String, Object> map = dataContext.as(MapDataContext.class).toMap();
Map<String, Object> result = UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(processInstanceIdString).map(pi -> {
pi.updateWorkItem(taskInstanceIdString, wi -> HumanTaskHelper.updateContent(wi, map), securityPolicy);
return pi.variables().toModel();
})).orElseThrow().toMap();
return ExtendedDataContext.ofData(MapDataContext.of(result));
}
use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.
the class ProcessEventDispatcherTest method testStringSigCloudEvent.
@Test
void testStringSigCloudEvent() throws Exception {
EventDispatcher<DummyModel> dispatcher = new ProcessEventDispatcher<>(process, null, processService, executor, null, AbstractMessageConsumer::cloudEventResolver);
ProcessInstance<DummyModel> instance = dispatcher.dispatch(DUMMY_TOPIC, new StringCloudEvent("pepe", DUMMY_TOPIC, "source", "1")).toCompletableFuture().get();
ArgumentCaptor<String> signal = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> processInstanceId = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Object> signalObject = ArgumentCaptor.forClass(Object.class);
verify(processService, times(1)).signalProcessInstance(Mockito.any(Process.class), processInstanceId.capture(), signalObject.capture(), signal.capture());
assertEquals("Message-" + DUMMY_TOPIC, signal.getValue());
assertEquals("pepe", signalObject.getValue());
assertEquals("1", processInstanceId.getValue());
assertEquals(instance, processInstance);
}
Aggregations