Refine search
private void exceptionHandlingCompleted(ProcessInstance processInstance, ProcessWorkItemHandlerException handlerException) { handlerException = (ProcessWorkItemHandlerException) ((WorkflowProcessInstance)processInstance).getVariable("Error"); ((WorkItemManager) ((ProcessInstance) getProcessInstance()) .getKnowledgeRuntime().getWorkItemManager()).abortWorkItem(getWorkItem().getId()); break; case RETHROW: String exceptionName = handlerException.getCause().getClass().getName(); ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName); if (exceptionScopeInstance == null) { throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute work item " + handlerException.getMessage(), handlerException.getCause()); break; case RETRY: Map<String, Object> parameters = new HashMap<>(getWorkItem().getParameters()); ((WorkItemManager) ((ProcessInstance) getProcessInstance()) .getKnowledgeRuntime().getWorkItemManager()).retryWorkItem(getWorkItem().getId(), parameters); break; case COMPLETE: ((WorkItemManager) ((ProcessInstance) getProcessInstance()) .getKnowledgeRuntime().getWorkItemManager()).completeWorkItem(getWorkItem().getId(), ((WorkflowProcessInstanceImpl)processInstance).getVariables()); break;
final WorkItemImpl workItem = new WorkItemImpl(); workItem.setState(WorkItem.ACTIVE); workItem.setProcessInstanceId(processInstance.getId()); workItem.setDeploymentId((String) ksession.getEnvironment().get(EnvironmentName.DEPLOYMENT_ID)); workItem.setName(workItemName); while (matcher.find()) { String paramName = matcher.group(1); variableValue = processInstance.getVariable(paramName); if (variableValue == null) { try { final WorkItemNodeInstance workItemNodeInstance = new WorkItemNodeInstance(); workItemNodeInstance.internalSetWorkItem(workItem); workItemNodeInstance.setMetaData("NodeType", workItemName); workItem.setNodeInstanceId(workItemNodeInstance.getId()); if (ksession instanceof StatefulKnowledgeSessionImpl) { workItemNodeInstance.setProcessInstance(processInstance); workItemNodeInstance.setNodeInstanceContainer(dynamicContext == null ? processInstance : dynamicContext); workItemNodeInstance.addEventListeners(); executeWorkItem((StatefulKnowledgeSessionImpl) ksession, workItem,
private void handleWorkItemHandlerException(ProcessWorkItemHandlerException handlerException, WorkItem workItem) { Map<String, Object> parameters = new HashMap<>(); parameters.put("DeploymentId", workItem.getDeploymentId()); parameters.put("ProcessInstanceId", workItem.getProcessInstanceId()); parameters.put("WorkItemId", workItem.getId()); parameters.put("NodeInstanceId", this.getId()); parameters.put("ErrorMessage", handlerException.getMessage()); parameters.put("Error", handlerException); parameters.putAll(workItem.getParameters()); KieRuntime kruntime = getKieRuntimeForSubprocess(); ((ProcessInstanceImpl) processInstance).setMetaData("ParentProcessInstanceId", getProcessInstance().getId()); ((ProcessInstanceImpl) processInstance).setMetaData("ParentNodeInstanceId", getUniqueId()); ((ProcessInstanceImpl) processInstance).setParentProcessInstanceId(getProcessInstance().getId()); ((ProcessInstanceImpl) processInstance).setSignalCompletion(true); if (processInstance.getState() == ProcessInstance.STATE_COMPLETED || processInstance.getState() == ProcessInstance.STATE_ABORTED) { exceptionHandlingCompleted(processInstance, handlerException); } else { addExceptionProcessListener();
public void workItemCompleted(WorkItem workItem) { if (workItemId == workItem.getId() || (workItemId == -1 && getWorkItem().getId() == workItem.getId())) { removeEventListeners(); triggerCompleted(workItem); } }
public void addEventListeners() { super.addEventListeners(); addWorkItemListener(); addExceptionProcessListener(); }
public String getNodeName() { Node node = getNode(); if (node == null) { String nodeName = "[Dynamic]"; WorkItem workItem = getWorkItem(); if (workItem != null) { nodeName += " " + workItem.getParameter("TaskName"); } return nodeName; } return super.getNodeName(); }
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; 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; handleWorkItemHandlerException(handlerException, workItem); } catch (Exception e) { String exceptionName = e.getClass().getName(); ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName); if (exceptionScopeInstance == null) {
@Override public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte, Object log) { NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance(); NodeInstanceLog logEvent =null; if (log != null) { logEvent = (NodeInstanceLog) log; if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) { logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId()); } if (nodeInstance instanceof SubProcessNodeInstance) { logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId()); } return logEvent; } return null; }
@Override public Void execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); ProcessInstance processInstance = ksession.getProcessInstance(pId); assertNotNull(processInstance); NodeInstance nodeInstance = ((WorkflowProcessInstance) processInstance) .getNodeInstance(((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId()); assertNotNull(nodeInstance); assertTrue(nodeInstance instanceof WorkItemNodeInstance); String deploymentId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getDeploymentId(); long nodeInstanceId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeInstanceId(); long nodeId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeId(); assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId(), deploymentId); assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getNodeId(), nodeId); assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId(), nodeInstanceId); return null; } });
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; } } if (exceptionHandlingProcessInstanceId > -1) { ProcessInstance processInstance = null; KieRuntime kruntime = getKieRuntimeForSubprocess(); processInstance = (ProcessInstance) kruntime.getProcessInstance(exceptionHandlingProcessInstanceId); if (processInstance != null) { processInstance.setState(ProcessInstance.STATE_ABORTED); } } super.cancel(); }
private void handleAssignment(Assignment assignment) { AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action"); try { ProcessContext context = new ProcessContext(getProcessInstance().getKnowledgeRuntime()); context.setNodeInstance(this); action.execute(getWorkItem(), context); } catch (Exception e) { throw new RuntimeException("unable to execute Assignment", e); } }
protected WorkItem createWorkItem(WorkItemNode workItemNode) { WorkItem workItem = super.createWorkItem(workItemNode); String actorId = assignWorkItem(workItem); if (actorId != null) { ((org.drools.core.process.instance.WorkItem) workItem).setParameter("ActorId", actorId); } return workItem; }
} else if ( nodeInstance instanceof WorkItemNodeInstance ) { JBPMMessages.ProcessInstance.NodeInstanceContent.WorkItemNode.Builder _wi = JBPMMessages.ProcessInstance.NodeInstanceContent.WorkItemNode.newBuilder() .setWorkItemId( ((WorkItemNodeInstance) nodeInstance).getWorkItemId() ); ((WorkItemNodeInstance) nodeInstance).getTimerInstances(); if ( timerInstances != null ) { for ( Long id : timerInstances ) { _wi.setErrorHandlingProcessInstanceId(((WorkItemNodeInstance) nodeInstance).getExceptionHandlingProcessInstanceId()); _content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder() .setType( NodeInstanceType.WORK_ITEM_NODE )
protected NodeInstance getNodeInstance(WorkItem workItem, Collection<NodeInstance> nodeInstances) { for (NodeInstance nodeInstance : nodeInstances) { if (nodeInstance instanceof WorkItemNodeInstance) { if (((WorkItemNodeInstance) nodeInstance).getWorkItemId() == workItem.getId()) { return nodeInstance; } } else if (nodeInstance instanceof NodeInstanceContainer) { NodeInstance found = getNodeInstance(workItem, ((NodeInstanceContainer) nodeInstance).getNodeInstances()); if (found != null) { return found; } } } return null; }
public Void execute(Context context) { StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class); WorkflowProcessInstance realProcessInstance = (WorkflowProcessInstance) ksession.getProcessInstance(processInstance.getId()); workItemNodeInstance.setProcessInstance(realProcessInstance); if (dynamicContext == null) { workItemNodeInstance.setNodeInstanceContainer(realProcessInstance); } else { DynamicNodeInstance realDynamicContext = findDynamicContext(realProcessInstance, dynamicContext.getUniqueId()); workItemNodeInstance.setNodeInstanceContainer(realDynamicContext); } workItemNodeInstance.addEventListeners(); executeWorkItem((StatefulKnowledgeSessionImpl) ksession, workItem, workItemNodeInstance); return null; } });
private WorkItemNodeInstance findWorkItemNodeInstance(long workItemId, Collection<NodeInstance> nodeInstances) { for (NodeInstance nodeInstance : nodeInstances) { if (nodeInstance instanceof WorkItemNodeInstance) { WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) nodeInstance; WorkItem workItem = workItemNodeInstance.getWorkItem(); if (workItem != null && workItemId == workItem.getId()) { return workItemNodeInstance; } } if (nodeInstance instanceof NodeInstanceContainer) { WorkItemNodeInstance result = findWorkItemNodeInstance(workItemId, ((NodeInstanceContainer) nodeInstance).getNodeInstances()); if (result != null) { return result; } } } return null; } }
((WorkItemNodeInstance) nodeInstance).internalSetProcessInstanceId( _content.getHumanTask().getErrorHandlingProcessInstanceId() ); break; case WORK_ITEM_NODE : nodeInstance = new WorkItemNodeInstance(); ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId( _content.getWorkItem().getWorkItemId() ); if ( _content.getWorkItem().getTimerInstanceIdCount() > 0 ) { List<Long> timerInstances = new ArrayList<Long>(); timerInstances.add( _timerId ); ((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances( timerInstances ); ((WorkItemNodeInstance) nodeInstance).internalSetProcessInstanceId( _content.getWorkItem().getErrorHandlingProcessInstanceId() ); break; case SUBPROCESS_NODE :
stream.writeLong(((WorkItemNodeInstance) nodeInstance).getWorkItemId()); List<Long> timerInstances = ((WorkItemNodeInstance) nodeInstance).getTimerInstances(); if (timerInstances != null) { stream.writeInt(timerInstances.size());
nodeInstance = new WorkItemNodeInstance(); ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(stream.readLong()); nbTimerInstances = stream.readInt(); if (nbTimerInstances > 0) { timerInstances.add(stream.readLong()); ((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; 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; handleWorkItemHandlerException(handlerException, workItem); } catch (Exception e) { String exceptionName = e.getClass().getName(); ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName); if (exceptionScopeInstance == null) {