use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class UIWorkItemHandler method abort.
public void abort(WorkItem workItem) {
WorkItemManager manager = workItems.get(workItem);
if (manager != null) {
manager.abortWorkItem(workItem.getId());
workItems.remove(workItem);
reloadWorkItemsList();
}
selectButton.setEnabled(getSelectedWorkItem() != null);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class ProcessTest method main.
public static final void main(String[] args) {
try {
// load up the knowledge base
final KieSession ksession = getKieSession();
UIWorkItemHandler handler = new UIWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
handler.setVisible(true);
ksession.getWorkItemManager().registerWorkItemHandler("Email", new WorkItemHandler() {
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println("Sending email ...");
manager.completeWorkItem(workItem.getId(), null);
}
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
});
KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newFileLogger(ksession, "test");
// start a new process instance
Person person = new Person("john", "John Doe");
person.setAge(20);
Request request = new Request("12345");
request.setPersonId("john");
request.setAmount(1000L);
ksession.insert(person);
ksession.insert(request);
Map<String, Object> params = new HashMap<String, Object>();
params.put("request", request);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("com.sample.requestHandling", params);
ksession.insert(processInstance);
ksession.fireAllRules();
// signaling to select tasks in the ad-hoc sub-process
ksession.signalEvent("Investigate", null, processInstance.getId());
// dynamically adding a new sub-process
DynamicNodeInstance dynamicNodeInstance = (DynamicNodeInstance) processInstance.getNodeInstances().iterator().next();
DynamicUtils.addDynamicSubProcess(dynamicNodeInstance, ksession, "com.sample.contactCustomer", null);
// event processing to detect too much processes being started
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
ksession.insert(event);
}
});
Request request2 = new Request("12346");
request2.setPersonId("john");
request2.setAmount(1000L);
params = new HashMap<String, Object>();
params.put("request", request2);
ksession.startProcess("com.sample.requestHandling", params);
ksession.fireAllRules();
Request request3 = new Request("12347");
request3.setPersonId("john");
request3.setAmount(1000L);
params = new HashMap<String, Object>();
params.put("request", request);
ksession.startProcess("com.sample.requestHandling", params);
ksession.fireAllRules();
Request request4 = new Request("12348");
request4.setPersonId("john");
request4.setAmount(1000L);
params = new HashMap<String, Object>();
params.put("request", request4);
ksession.startProcess("com.sample.requestHandling", params);
ksession.fireAllRules();
Request request5 = new Request("12349");
request5.setPersonId("john");
request5.setAmount(1000L);
params = new HashMap<String, Object>();
params.put("request", request5);
ksession.startProcess("com.sample.requestHandling", params);
ksession.fireAllRules();
Request request6 = new Request("12350");
request6.setPersonId("john");
request6.setAmount(1000L);
params = new HashMap<String, Object>();
params.put("request", request6);
processInstance = (WorkflowProcessInstance) ksession.startProcess("com.sample.requestHandling", params);
FactHandle handle = ksession.insert(request6);
ksession.insert(processInstance);
ksession.fireAllRules();
// exception handling when canceling request
request6.setCanceled(true);
ksession.update(handle, request6);
ksession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class UIWorkItemHandler method abort.
public void abort(WorkItem workItem) {
WorkItemManager manager = workItems.get(workItem);
if (manager != null) {
manager.abortWorkItem(workItem.getId());
workItems.remove(workItem);
reloadWorkItemsList();
}
selectButton.setEnabled(getSelectedWorkItem() != null);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class HumanTaskHandler method complete.
public void complete(WorkItem workItem, Map<String, Object> results) {
WorkItemManager manager = workItems.get(workItem);
if (manager != null) {
manager.completeWorkItem(workItem.getId(), results);
}
workItems.remove(workItem);
update();
selectButton.setEnabled(getSelectedWorkItem() != null);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class DataTest method testDataOutputAssociationsXmlNode.
@Test
public void testDataOutputAssociationsXmlNode() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataOutputAssociations-xml-node.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {
public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
}
public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
try {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
Map<String, Object> params = new HashMap<String, Object>();
params.put("output", document.getFirstChild());
mgr.completeWorkItem(workItem.getId(), params);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
});
ProcessInstance processInstance = ksession.startProcess("process", null);
}
Aggregations