use of org.drools.core.WorkItemHandlerNotFoundException in project jbpm by kiegroup.
the class WorkItemNodeInstance method cancel.
public void cancel() {
WorkItem workItem = getWorkItem();
if (workItem != null && workItem.getState() != WorkItem.COMPLETED && workItem.getState() != WorkItem.ABORTED) {
try {
((WorkItemManager) ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime().getWorkItemManager()).internalAbortWorkItem(workItemId);
} catch (WorkItemHandlerNotFoundException wihnfe) {
getProcessInstance().setState(ProcessInstance.STATE_ABORTED);
throw wihnfe;
}
}
super.cancel();
}
use of org.drools.core.WorkItemHandlerNotFoundException in project jbpm by kiegroup.
the class WorkItemNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
// TODO this should be included for ruleflow only, not for BPEL
// if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
// throw new IllegalArgumentException(
// "A WorkItemNode only accepts default incoming connections!");
// }
WorkItemNode workItemNode = getWorkItemNode();
createWorkItem(workItemNode);
if (workItemNode.isWaitForCompletion()) {
addWorkItemListener();
}
String deploymentId = (String) getProcessInstance().getKnowledgeRuntime().getEnvironment().get(EnvironmentName.DEPLOYMENT_ID);
((WorkItem) workItem).setDeploymentId(deploymentId);
((WorkItem) workItem).setNodeInstanceId(this.getId());
((WorkItem) workItem).setNodeId(getNodeId());
if (isInversionOfControl()) {
((ProcessInstance) getProcessInstance()).getKnowledgeRuntime().update(((ProcessInstance) getProcessInstance()).getKnowledgeRuntime().getFactHandle(this), this);
} else {
try {
((WorkItemManager) ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem((org.drools.core.process.instance.WorkItem) workItem);
} catch (WorkItemHandlerNotFoundException wihnfe) {
getProcessInstance().setState(ProcessInstance.STATE_ABORTED);
throw wihnfe;
} catch (Exception e) {
String exceptionName = e.getClass().getName();
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
if (exceptionScopeInstance == null) {
throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
}
// workItemId must be set otherwise cancel activity will not find the right work item
this.workItemId = workItem.getId();
exceptionScopeInstance.handleException(exceptionName, e);
}
}
if (!workItemNode.isWaitForCompletion()) {
triggerCompleted();
}
this.workItemId = workItem.getId();
}
use of org.drools.core.WorkItemHandlerNotFoundException in project drools by kiegroup.
the class DefaultWorkItemManager method internalAbortWorkItem.
public void internalAbortWorkItem(long id) {
WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
// work item may have been aborted
if (workItem != null) {
WorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
if (handler != null) {
handler.abortWorkItem(workItem, this);
} else {
workItems.remove(workItem.getId());
throw new WorkItemHandlerNotFoundException("Could not find work item handler for " + workItem.getName(), workItem.getName());
}
workItems.remove(workItem.getId());
}
}
use of org.drools.core.WorkItemHandlerNotFoundException in project jbpm by kiegroup.
the class WorkItemTest method testCancelNonRegisteredWorkItemHandler.
@Test
public void testCancelNonRegisteredWorkItemHandler() {
String processId = "org.drools.actions";
String workName = "Unnexistent Task";
RuleFlowProcess process = getWorkItemProcess(processId, workName);
KieSession ksession = createKieSession(process);
ksession.getWorkItemManager().registerWorkItemHandler(workName, new DoNothingWorkItemHandler());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.drools.actions", parameters);
long processInstanceId = processInstance.getId();
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
ksession.getWorkItemManager().registerWorkItemHandler(workName, null);
try {
ksession.abortProcessInstance(processInstanceId);
Assert.fail("should fail if WorkItemHandler for" + workName + "is not registered");
} catch (WorkItemHandlerNotFoundException wihnfe) {
}
Assert.assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState());
}
use of org.drools.core.WorkItemHandlerNotFoundException in project jbpm by kiegroup.
the class WorkItemPersistenceTest method testCancelNonRegisteredWorkItemHandler.
@Test
@Ignore
public void testCancelNonRegisteredWorkItemHandler() {
String processId = "org.drools.actions";
String workName = "Unnexistent Task";
RuleFlowProcess process = getWorkItemProcess(processId, workName);
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
((KnowledgeBaseImpl) kbase).addProcess(process);
KieSession ksession = createSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler(workName, new DoNothingWorkItemHandler());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.drools.actions", parameters);
long processInstanceId = processInstance.getId();
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
ksession.getWorkItemManager().registerWorkItemHandler(workName, null);
try {
ksession.abortProcessInstance(processInstanceId);
Assert.fail("should fail if WorkItemHandler for" + workName + "is not registered");
} catch (WorkItemHandlerNotFoundException wihnfe) {
}
Assert.assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState());
}
Aggregations