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);
}
}
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;
}
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");
}
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);
}
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);
}
Aggregations