Search in sources :

Example 1 with WorkItemHandlerNotFoundException

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();
}
Also used : WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) ProcessInstance(org.jbpm.process.instance.ProcessInstance) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Example 2 with WorkItemHandlerNotFoundException

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();
}
Also used : WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) ProcessInstance(org.jbpm.process.instance.ProcessInstance) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) ExceptionScopeInstance(org.jbpm.process.instance.context.exception.ExceptionScopeInstance)

Example 3 with WorkItemHandlerNotFoundException

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());
    }
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException)

Example 4 with WorkItemHandlerNotFoundException

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());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) HashMap(java.util.HashMap) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.process.test.Person) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with WorkItemHandlerNotFoundException

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());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) HashMap(java.util.HashMap) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.persistence.session.objects.Person) Ignore(org.junit.Ignore) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

WorkItemHandlerNotFoundException (org.drools.core.WorkItemHandlerNotFoundException)6 HashMap (java.util.HashMap)2 WorkItem (org.drools.core.process.instance.WorkItem)2 WorkItemManager (org.drools.core.process.instance.WorkItemManager)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)2 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 Person (org.jbpm.persistence.session.objects.Person)1 ExceptionScopeInstance (org.jbpm.process.instance.context.exception.ExceptionScopeInstance)1 Person (org.jbpm.process.test.Person)1 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)1 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)1 Ignore (org.junit.Ignore)1 KieBase (org.kie.api.KieBase)1