Search in sources :

Example 1 with AbstractProcessInstance

use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.

the class LambdaSubProcessNodeInstance method internalTrigger.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void internalTrigger(KogitoNodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getStringId()) == null) {
        return;
    }
    if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A SubProcess node only accepts default incoming connections!");
    }
    KogitoProcessContextImpl context = ContextFactory.fromNode(this);
    SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
    Object o = subProcessFactory.bind(context);
    org.kie.kogito.process.ProcessInstance<?> processInstance = subProcessFactory.createInstance(o);
    org.kie.api.runtime.process.ProcessInstance pi = ((AbstractProcessInstance<?>) processInstance).internalGetProcessInstance();
    ((ProcessInstanceImpl) pi).setMetaData("ParentProcessInstanceId", getProcessInstance().getStringId());
    ((ProcessInstanceImpl) pi).setMetaData("ParentNodeInstanceId", getUniqueId());
    ((ProcessInstanceImpl) pi).setMetaData("ParentNodeId", getSubProcessNode().getUniqueId());
    ((ProcessInstanceImpl) pi).setParentProcessInstanceId(getProcessInstance().getStringId());
    ((ProcessInstanceImpl) pi).setRootProcessInstanceId(StringUtils.isEmpty(getProcessInstance().getRootProcessInstanceId()) ? getProcessInstance().getStringId() : getProcessInstance().getRootProcessInstanceId());
    ((ProcessInstanceImpl) pi).setRootProcessId(StringUtils.isEmpty(getProcessInstance().getRootProcessId()) ? getProcessInstance().getProcessId() : getProcessInstance().getRootProcessId());
    ((ProcessInstanceImpl) pi).setSignalCompletion(getSubProcessNode().isWaitForCompletion());
    processInstance.start();
    this.processInstanceId = processInstance.id();
    this.asyncWaitingNodeInstance = hasAsyncNodeInstance(pi);
    subProcessFactory.unbind(context, processInstance.variables());
    if (!getSubProcessNode().isWaitForCompletion()) {
        triggerCompleted();
    } else if (processInstance.status() == ProcessInstance.STATE_COMPLETED || processInstance.status() == ProcessInstance.STATE_ABORTED) {
        processInstanceCompleted((ProcessInstanceImpl) pi);
    } else {
        addProcessListener();
    }
}
Also used : AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) SubProcessFactory(org.jbpm.workflow.core.node.SubProcessFactory) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) KogitoProcessContextImpl(org.jbpm.process.instance.KogitoProcessContextImpl)

Example 2 with AbstractProcessInstance

use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.

the class KafkaProcessInstancesTest method testProcessInstancesCreateNotActive.

@Test
public void testProcessInstancesCreateNotActive() {
    AbstractProcessInstance instance = mock(AbstractProcessInstance.class);
    when(instance.status()).thenReturn(ProcessInstance.STATE_COMPLETED);
    instances.create(id, instance);
    verify(producer, never()).send(any(), any());
}
Also used : AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) Test(org.junit.jupiter.api.Test)

Example 3 with AbstractProcessInstance

use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.

the class KafkaProcessInstancesTest method testProcessInstancesUpdate.

@Test
public void testProcessInstancesUpdate() {
    doReturn(mock(Future.class)).when(producer).send(any());
    AbstractProcessInstance instance = mock(AbstractProcessInstance.class);
    doReturn(new byte[] {}).when(marshaller).marshallProcessInstance(instance);
    when(instance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    instances.update(id, instance);
    ArgumentCaptor<ProducerRecord> captor = ArgumentCaptor.forClass(ProducerRecord.class);
    verify(producer).send(captor.capture());
    assertThat(captor.getValue().value()).isEqualTo(new byte[] {});
    assertThat(captor.getValue().key()).isEqualTo(id);
    assertThat(captor.getValue().topic()).isEqualTo(topicName(process.id()));
    verify(instance).internalRemoveProcessInstance(any());
    verify(marshaller).createdReloadFunction(any());
}
Also used : AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 4 with AbstractProcessInstance

use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.

the class KafkaProcessInstancesTest method testProcessInstancesCreateDuplicate.

@Test
public void testProcessInstancesCreateDuplicate() {
    when(store.get(id)).thenReturn(new byte[] {});
    AbstractProcessInstance instance = mock(AbstractProcessInstance.class);
    when(instance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    assertThatExceptionOfType(ProcessInstanceDuplicatedException.class).isThrownBy(() -> instances.create(id, instance));
}
Also used : AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) ProcessInstanceDuplicatedException(org.kie.kogito.process.ProcessInstanceDuplicatedException) Test(org.junit.jupiter.api.Test)

Example 5 with AbstractProcessInstance

use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.

the class CacheProcessInstancesWithLockIT method testBasic.

@Test
public void testBasic() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    CacheProcessInstances pi = new CacheProcessInstances(process, cacheManager, null, true);
    assertNotNull(pi);
    WorkflowProcessInstance createPi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
    createPi.setId(TEST_ID);
    createPi.setStartDate(new Date());
    AbstractProcessInstance<?> mockCreatePi = mock(AbstractProcessInstance.class);
    mockCreatePi.setVersion(1L);
    when(mockCreatePi.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    when(mockCreatePi.internalGetProcessInstance()).thenReturn(createPi);
    when(mockCreatePi.id()).thenReturn(TEST_ID);
    pi.create(TEST_ID, mockCreatePi);
    assertThat(pi.size()).isOne();
    assertTrue(pi.exists(TEST_ID));
    WorkflowProcessInstance updatePi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
    updatePi.setId(TEST_ID);
    updatePi.setStartDate(new Date());
    AbstractProcessInstance<?> mockUpdatePi = mock(AbstractProcessInstance.class);
    when(mockUpdatePi.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    when(mockUpdatePi.internalGetProcessInstance()).thenReturn(updatePi);
    when(mockUpdatePi.id()).thenReturn(TEST_ID);
    try {
        pi.update(TEST_ID, mockUpdatePi);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + TEST_ID + " was updated or deleted by other request.");
    }
    pi.remove(TEST_ID);
    assertFalse(pi.exists(TEST_ID));
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractProcessInstance (org.kie.kogito.process.impl.AbstractProcessInstance)12 Test (org.junit.jupiter.api.Test)10 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)4 Date (java.util.Date)3 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 Future (java.util.concurrent.Future)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2 ClientSession (com.mongodb.client.ClientSession)1 MongoClient (com.mongodb.client.MongoClient)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Document (org.bson.Document)1 Bson (org.bson.conversions.Bson)1 ClassPathResource (org.drools.core.io.impl.ClassPathResource)1 KogitoProcessContextImpl (org.jbpm.process.instance.KogitoProcessContextImpl)1 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)1 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)1