Search in sources :

Example 16 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class WebServiceCommand method execute.

@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
    // since JaxWsDynamicClientFactory will change the TCCL we need to restore it after creating client
    ClassLoader origClassloader = Thread.currentThread().getContextClassLoader();
    try {
        Object[] parameters = null;
        WorkItem workItem = (WorkItem) ctx.getData("workItem");
        String interfaceRef = (String) workItem.getParameter("Interface");
        String operationRef = (String) workItem.getParameter("Operation");
        String endpointAddress = (String) workItem.getParameter("Endpoint");
        String username = (String) workItem.getParameter("Username");
        String password = (String) workItem.getParameter("Password");
        if (workItem.getParameter("Parameter") instanceof Object[]) {
            parameters = (Object[]) workItem.getParameter("Parameter");
        } else if (workItem.getParameter("Parameter") != null && workItem.getParameter("Parameter").getClass().isArray()) {
            int length = Array.getLength(workItem.getParameter("Parameter"));
            parameters = new Object[length];
            for (int i = 0; i < length; i++) {
                parameters[i] = Array.get(workItem.getParameter("Parameter"), i);
            }
        } else {
            parameters = new Object[] { workItem.getParameter("Parameter") };
        }
        Client client = getWSClient(workItem, interfaceRef, ctx);
        // Override endpoint address if configured.
        if (endpointAddress != null && !"".equals(endpointAddress)) {
            client.getRequestContext().put(Message.ENDPOINT_ADDRESS, endpointAddress);
        }
        // apply authorization if needed
        applyAuthorization(username, password, client);
        Object[] result = client.invoke(operationRef, parameters);
        ExecutionResults results = new ExecutionResults();
        if (result == null || result.length == 0) {
            results.setData("Result", null);
        } else {
            results.setData("Result", result[0]);
        }
        logger.debug("Received sync response {}", result);
        return results;
    } finally {
        Thread.currentThread().setContextClassLoader(origClassloader);
    }
}
Also used : ExecutionResults(org.kie.api.executor.ExecutionResults) Client(org.apache.cxf.endpoint.Client) WorkItem(org.kie.api.runtime.process.WorkItem)

Example 17 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class AbstractWorkItemHandler method findWorkItemNodeInstance.

private WorkItemNodeInstance findWorkItemNodeInstance(long workItemId, Collection<NodeInstance> nodeInstances) {
    for (NodeInstance nodeInstance : nodeInstances) {
        if (nodeInstance instanceof WorkItemNodeInstance) {
            WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) nodeInstance;
            WorkItem workItem = workItemNodeInstance.getWorkItem();
            if (workItem != null && workItemId == workItem.getId()) {
                return workItemNodeInstance;
            }
        }
        if (nodeInstance instanceof NodeInstanceContainer) {
            WorkItemNodeInstance result = findWorkItemNodeInstance(workItemId, ((NodeInstanceContainer) nodeInstance).getNodeInstances());
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
Also used : NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) WorkItem(org.kie.api.runtime.process.WorkItem)

Example 18 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class IntermediateEventTest method testMessageIntermediateThrowWithTransformation.

@Test
public void testMessageIntermediateThrowWithTransformation() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final StringBuffer messageContent = new StringBuffer();
    ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            // collect message content for verification
            messageContent.append(workItem.getParameter("Message"));
            super.executeWorkItem(workItem, manager);
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "MyValue");
    ProcessInstance processInstance = ksession.startProcess("MessageIntermediateEvent", params);
    assertProcessInstanceCompleted(processInstance);
    assertThat(messageContent.toString()).isEqualTo("MYVALUE");
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) SendTaskHandler(org.jbpm.bpmn2.handler.SendTaskHandler) Test(org.junit.Test)

Example 19 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class IntermediateEventTest method testEventSubprocessConditional.

@Test
public void testEventSubprocessConditional() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessConditional.bpmn2");
    final List<Long> executednodes = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
                executednodes.add(event.getNodeInstance().getId());
            }
        }
    };
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(listener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessConditional");
    assertProcessInstanceActive(processInstance);
    Person person = new Person();
    person.setName("john");
    ksession.insert(person);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertThat(executednodes.size()).isEqualTo(1);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Person(org.jbpm.bpmn2.objects.Person) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 20 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class IntermediateEventTest method testIntermediateCatchEventSignalAndBoundarySignalEvent.

@Test
public void testIntermediateCatchEventSignalAndBoundarySignalEvent() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryEventWithSignals.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("boundaryeventtest");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    // now signal process instance
    ksession.signalEvent("moveon", "", processInstance.getId());
    assertProcessInstanceActive(processInstance);
    WorkItem wi = handler.getWorkItem();
    assertThat(wi).isNotNull();
    // signal boundary event on user task
    ksession.signalEvent("moveon", "", processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Aggregations

WorkItem (org.kie.api.runtime.process.WorkItem)174 Test (org.junit.Test)139 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)127 KieBase (org.kie.api.KieBase)110 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)91 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)87 HashMap (java.util.HashMap)72 KieSession (org.kie.api.runtime.KieSession)48 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)33 ArrayList (java.util.ArrayList)29 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)27 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)26 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)22 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)14 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)13 Map (java.util.Map)11 StringReader (java.io.StringReader)10 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)10