Search in sources :

Example 1 with KogitoWorkflowProcessInstance

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

the class ProcessInstanceEventBatch method createUserTask.

protected UserTaskInstanceEventBody createUserTask(ProcessWorkItemTransitionEvent workItemTransitionEvent) {
    KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) workItemTransitionEvent.getProcessInstance();
    HumanTaskWorkItem workItem = (HumanTaskWorkItem) workItemTransitionEvent.getWorkItem();
    return UserTaskInstanceEventBody.create().id(workItem.getStringId()).state(workItem.getPhaseStatus()).taskName(workItem.getTaskName()).taskDescription(workItem.getTaskDescription()).taskPriority(workItem.getTaskPriority()).referenceName(workItem.getReferenceName()).actualOwner(workItem.getActualOwner()).startDate(workItem.getStartDate()).completeDate(workItem.getCompleteDate()).adminGroups(workItem.getAdminGroups()).adminUsers(workItem.getAdminUsers()).excludedUsers(workItem.getExcludedUsers()).potentialGroups(workItem.getPotentialGroups()).potentialUsers(workItem.getPotentialUsers()).processInstanceId(pi.getStringId()).rootProcessInstanceId(pi.getRootProcessInstanceId()).processId(pi.getProcessId()).rootProcessId(pi.getRootProcessId()).inputs(workItem.getParameters()).outputs(workItem.getResults()).comments(workItem.getComments().values()).attachments(workItem.getAttachments().values()).build();
}
Also used : HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance)

Example 2 with KogitoWorkflowProcessInstance

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

the class ActivityTest method testServiceTaskWithAccessToWorkItemInfo.

@Test
public void testServiceTaskWithAccessToWorkItemInfo() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcess.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler() {

        @Override
        public void executeWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem, KogitoWorkItemManager manager) {
            assertThat(workItem.getProcessInstance()).isNotNull();
            assertThat(workItem.getNodeInstance()).isNotNull();
            super.executeWorkItem(workItem, manager);
        }
    });
    Map<String, Object> params = new HashMap<>();
    params.put("s", "john");
    KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("ServiceProcess", params);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertEquals("Hello john!", processInstance.getVariable("s"));
}
Also used : ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) HashMap(java.util.HashMap) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 3 with KogitoWorkflowProcessInstance

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

the class ActivityTest method testDMNBusinessRuleTask.

@Test
public void testDMNBusinessRuleTask() throws Exception {
    kruntime = createKogitoProcessRuntime("dmn/BPMN2-BusinessRuleTaskDMN.bpmn2", "dmn/0020-vacation-days.dmn");
    // first run 16, 1 and expected days is 27
    Map<String, Object> params = new HashMap<>();
    params.put("age", 16);
    params.put("yearsOfService", 1);
    KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-BusinessRuleTask", params);
    assertProcessInstanceFinished(processInstance, kruntime);
    BigDecimal vacationDays = (BigDecimal) ((KogitoWorkflowProcessInstance) processInstance).getVariable("vacationDays");
    assertEquals(BigDecimal.valueOf(27), vacationDays);
    // second run 44, 20 and expected days is 24
    params = new HashMap<>();
    params.put("age", 44);
    params.put("yearsOfService", 20);
    processInstance = kruntime.startProcess("BPMN2-BusinessRuleTask", params);
    assertProcessInstanceFinished(processInstance, kruntime);
    vacationDays = (BigDecimal) ((KogitoWorkflowProcessInstance) processInstance).getVariable("vacationDays");
    assertEquals(BigDecimal.valueOf(24), vacationDays);
    // second run 50, 30 and expected days is 30
    params = new HashMap<>();
    params.put("age", 50);
    params.put("yearsOfService", 30);
    processInstance = kruntime.startProcess("BPMN2-BusinessRuleTask", params);
    assertProcessInstanceFinished(processInstance, kruntime);
    vacationDays = (BigDecimal) ((KogitoWorkflowProcessInstance) processInstance).getVariable("vacationDays");
    assertEquals(BigDecimal.valueOf(30), vacationDays);
}
Also used : KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with KogitoWorkflowProcessInstance

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

the class ActivityTest method testServiceTaskNoInterfaceName.

@Test
public void testServiceTaskNoInterfaceName() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask-web-service.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new SystemOutWorkItemHandler() {

        @Override
        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
            assertEquals("SimpleService", workItem.getParameter("Interface"));
            assertEquals("hello", workItem.getParameter("Operation"));
            assertEquals("java.lang.String", workItem.getParameter("ParameterType"));
            assertEquals("##WebService", workItem.getParameter("implementation"));
            assertEquals("hello", workItem.getParameter("operationImplementationRef"));
            assertEquals("SimpleService", workItem.getParameter("interfaceImplementationRef"));
            super.executeWorkItem(workItem, manager);
        }
    });
    Map<String, Object> params = new HashMap<>();
    KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("org.jboss.qa.jbpm.CallWS", params);
    assertProcessInstanceFinished(processInstance, kruntime);
}
Also used : KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) HashMap(java.util.HashMap) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 5 with KogitoWorkflowProcessInstance

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

the class ActivityTest method testServiceTask.

@Test
public void testServiceTask() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcess.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
    Map<String, Object> params = new HashMap<>();
    params.put("s", "john");
    KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("ServiceProcess", params);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertEquals("Hello john!", processInstance.getVariable("s"));
}
Also used : ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

KogitoWorkflowProcessInstance (org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance)33 Test (org.junit.jupiter.api.Test)25 HashMap (java.util.HashMap)18 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)13 ServiceTaskHandler (org.jbpm.bpmn2.handler.ServiceTaskHandler)7 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)6 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)6 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)6 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)5 KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)4 SLAViolatedEvent (org.kie.api.event.process.SLAViolatedEvent)4 ReceiveTaskHandler (org.jbpm.bpmn2.handler.ReceiveTaskHandler)3 SendTaskHandler (org.jbpm.bpmn2.handler.SendTaskHandler)3 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 Map (java.util.Map)2