Search in sources :

Example 1 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.

the class ProcessServiceImpl method abortWorkItem.

@Override
public void abortWorkItem(String deploymentId, Long processInstanceId, Long id) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
        if (workItem == null) {
            throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
        }
        ksession.getWorkItemManager().abortWorkItem(id);
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 2 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.

the class ProcessServiceImpl method getWorkItem.

@Override
public WorkItem getWorkItem(String deploymentId, Long processInstanceId, Long id) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
        if (workItem == null) {
            throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
        }
        return workItem;
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 3 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager 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 4 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager 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 5 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.

the class DynamicUtils method executeWorkItem.

private static void executeWorkItem(StatefulKnowledgeSessionImpl ksession, WorkItemImpl workItem, WorkItemNodeInstance workItemNodeInstance) {
    ProcessEventSupport eventSupport = ((InternalProcessRuntime) ksession.getProcessRuntime()).getProcessEventSupport();
    eventSupport.fireBeforeNodeTriggered(workItemNodeInstance, ksession);
    ((WorkItemManager) ksession.getWorkItemManager()).internalExecuteWorkItem(workItem);
    workItemNodeInstance.internalSetWorkItemId(workItem.getId());
    eventSupport.fireAfterNodeTriggered(workItemNodeInstance, ksession);
}
Also used : ProcessEventSupport(org.drools.core.event.ProcessEventSupport) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Aggregations

WorkItemManager (org.drools.core.process.instance.WorkItemManager)13 KieSession (org.kie.api.runtime.KieSession)8 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)6 WorkItem (org.drools.core.process.instance.WorkItem)4 Test (org.junit.Test)4 WorkItem (org.kie.api.runtime.process.WorkItem)4 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)3 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)3 WorkItemNotFoundException (org.jbpm.services.api.WorkItemNotFoundException)3 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)3 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)3 HashMap (java.util.HashMap)2 WorkItemHandlerNotFoundException (org.drools.core.WorkItemHandlerNotFoundException)2 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 NodeInstance (org.kie.api.runtime.process.NodeInstance)2 TaskService (org.kie.api.task.TaskService)2