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);
}
}
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);
}
}
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();
}
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();
}
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);
}
Aggregations