Search in sources :

Example 1 with KogitoWorkItemHandler

use of org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler in project kogito-runtimes by kiegroup.

the class KogitoDefaultWorkItemManager method internalExecuteWorkItem.

@Override
public void internalExecuteWorkItem(InternalKogitoWorkItem workItem) {
    ((KogitoWorkItemImpl) workItem).setId(UUID.randomUUID().toString());
    internalAddWorkItem(workItem);
    KogitoWorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
    if (handler != null) {
        handler.executeWorkItem(workItem, this);
    } else
        throw new KogitoWorkItemHandlerNotFoundException(workItem.getName());
}
Also used : KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItemHandlerNotFoundException(org.kie.kogito.process.workitems.KogitoWorkItemHandlerNotFoundException)

Example 2 with KogitoWorkItemHandler

use of org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler in project kogito-runtimes by kiegroup.

the class DataTest method testDataInputAssociationsWithStringObject.

@Test
public void testDataInputAssociationsWithStringObject() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-DataInputAssociations-string-object.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new KogitoWorkItemHandler() {

        @Override
        public void abortWorkItem(KogitoWorkItem manager, KogitoWorkItemManager mgr) {
        }

        @Override
        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
            assertEquals("hello", workItem.getParameter("coId"));
        }
    });
    Map<String, Object> params = new HashMap<>();
    params.put("instanceMetadata", "hello");
    KogitoProcessInstance processInstance = kruntime.startProcess("process", params);
}
Also used : KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 3 with KogitoWorkItemHandler

use of org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler in project kogito-runtimes by kiegroup.

the class DataTest method testDataInputAssociationsWithStringWithoutQuotes.

@Test
public void testDataInputAssociationsWithStringWithoutQuotes() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-DataInputAssociations-string-no-quotes.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new KogitoWorkItemHandler() {

        public void abortWorkItem(KogitoWorkItem manager, KogitoWorkItemManager mgr) {
        }

        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
            assertEquals("hello", workItem.getParameter("coId"));
        }
    });
    KogitoProcessInstance processInstance = kruntime.startProcess("process");
}
Also used : KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 4 with KogitoWorkItemHandler

use of org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler in project kogito-runtimes by kiegroup.

the class DataTest method testDataInputAssociationsWithLazyLoading.

/**
 * TODO testDataInputAssociationsWithLazyLoading
 */
@Test
@Disabled
public void testDataInputAssociationsWithLazyLoading() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-DataInputAssociations-lazy-creating.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new KogitoWorkItemHandler() {

        public void abortWorkItem(KogitoWorkItem manager, KogitoWorkItemManager mgr) {
        }

        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
            Object coIdParamObj = workItem.getParameter("coId");
            assertEquals("mydoc", ((Element) coIdParamObj).getNodeName());
            assertEquals("mynode", ((Element) workItem.getParameter("coId")).getFirstChild().getNodeName());
            assertEquals("user", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getNodeName());
            assertEquals("hello world", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getAttributes().getNamedItem("hello").getNodeValue());
        }
    });
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
    Map<String, Object> params = new HashMap<>();
    params.put("instanceMetadata", document.getFirstChild());
    KogitoProcessInstance processInstance = kruntime.startProcess("process", params);
}
Also used : KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) Element(org.w3c.dom.Element) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with KogitoWorkItemHandler

use of org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler in project kogito-runtimes by kiegroup.

the class DataTest method testDataOutputAssociations.

@Test
public void testDataOutputAssociations() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-DataOutputAssociations.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new KogitoWorkItemHandler() {

        public void abortWorkItem(KogitoWorkItem manager, KogitoWorkItemManager mgr) {
        }

        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
            try {
                Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
                Map<String, Object> params = new HashMap<>();
                params.put("output", document.getFirstChild());
                mgr.completeWorkItem(workItem.getStringId(), params);
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
        }
    });
    KogitoProcessInstance processInstance = kruntime.startProcess("process");
}
Also used : KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) ByteArrayInputStream(java.io.ByteArrayInputStream) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Document(org.w3c.dom.Document) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

KogitoWorkItemHandler (org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler)21 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)16 Test (org.junit.jupiter.api.Test)15 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)14 KogitoWorkItemManager (org.kie.kogito.internal.process.runtime.KogitoWorkItemManager)14 HashMap (java.util.HashMap)10 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Document (org.w3c.dom.Document)6 KogitoWorkItemHandlerNotFoundException (org.kie.kogito.process.workitems.KogitoWorkItemHandlerNotFoundException)5 Map (java.util.Map)3 Element (org.w3c.dom.Element)3 Disabled (org.junit.jupiter.api.Disabled)2 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)2 ProcessConfig (org.kie.kogito.process.ProcessConfig)2 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)2 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)2 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Method (java.lang.reflect.Method)1