use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.
the class DefaultWorkItemManager method retryWorkItem.
public void retryWorkItem(long workItemId) {
WorkItem workItem = workItems.get(workItemId);
retryWorkItem(workItem);
}
use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.
the class DefaultWorkItemManager method retryWorkItemWithParams.
public void retryWorkItemWithParams(long workItemId, Map<String, Object> map) {
WorkItem workItem = workItems.get(workItemId);
if (workItem != null) {
workItem.setParameters(map);
retryWorkItem(workItem);
}
}
use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.
the class RegisterWorkItemHandlerTest method testRegisterWorkItemHandlerWithStatelessSession.
@Test
public void testRegisterWorkItemHandlerWithStatelessSession() {
String str = "package org.kie.workitem.test \n" + "import " + DefaultWorkItemManager.class.getCanonicalName() + "\n" + "import " + WorkItem.class.getCanonicalName() + "\n" + "import " + WorkItemImpl.class.getCanonicalName() + "\n" + "rule r1 when \n" + "then \n" + " WorkItem wi = new WorkItemImpl(); \n" + " wi.setName( \"wihandler\" ); \n" + " DefaultWorkItemManager wim = ( DefaultWorkItemManager ) kcontext.getKieRuntime().getWorkItemManager(); \n" + " wim.internalExecuteWorkItem(wi); \n" + "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
final boolean[] answer = new boolean[] { false };
StatelessKieSession ks = kbase.newStatelessKieSession();
ks.execute(CommandFactory.newRegisterWorkItemHandlerCommand(new WorkItemHandler() {
public void executeWorkItem(org.kie.api.runtime.process.WorkItem workItem, WorkItemManager manager) {
answer[0] = true;
}
public void abortWorkItem(org.kie.api.runtime.process.WorkItem workItem, WorkItemManager manager) {
// TODO Auto-generated method stub
}
}, "wihandler"));
assertTrue(answer[0]);
}
use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.
the class JPAWorkItemManager method abortWorkItem.
public void abortWorkItem(long id) {
PersistenceContext context = getPersistenceContext();
WorkItemInfo workItemInfo = null;
if (this.workItems != null) {
workItemInfo = this.workItems.get(id);
if (workItemInfo != null) {
workItemInfo = (WorkItemInfo) context.merge(workItemInfo);
}
}
if (workItemInfo == null) {
workItemInfo = (WorkItemInfo) context.findWorkItem(id);
}
// work item may have been aborted
if (workItemInfo != null) {
WorkItem workItem = (WorkItemImpl) internalGetWorkItem(workItemInfo);
ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
workItem.setState(WorkItem.ABORTED);
// process instance may have finished already
if (processInstance != null) {
processInstance.signalEvent("workItemAborted", workItem);
}
context.remove(workItemInfo);
if (workItems != null) {
workItems.remove(workItem.getId());
}
}
}
use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.
the class JPAWorkItemManager method internalGetWorkItem.
private WorkItem internalGetWorkItem(WorkItemInfo workItemInfo) {
Environment env = kruntime.getEnvironment();
WorkItem workItem = workItemInfo.getWorkItem(env, (InternalKnowledgeBase) kruntime.getKieBase());
return workItem;
}
Aggregations