public boolean evaluate(NodeInstance instance, Connection connection, Constraint constraint) { Object value; try { ProcessContext context = new ProcessContext(((ProcessInstance)instance.getProcessInstance()).getKnowledgeRuntime()); context.setNodeInstance( instance ); value = this.evaluator.evaluate( context ); } catch ( Exception e ) { throw new RuntimeException( "unable to execute ReturnValueEvaluator: ", e ); } if ( !(value instanceof Boolean) ) { throw new RuntimeException( "Constraints must return boolean values: " + value + " for expression " + constraint); } return ((Boolean) value).booleanValue(); }
public void internalSetVariable(String name, Object value) { if (name.startsWith(VariableScope.CASE_FILE_PREFIX)) { String nameInCaseFile = name.replaceFirst(VariableScope.CASE_FILE_PREFIX, ""); // store it under case file rather regular variables @SuppressWarnings("unchecked") Collection<CaseData> caseFiles = (Collection<CaseData>) getProcessInstance().getKnowledgeRuntime().getObjects(new ClassObjectFilter(CaseData.class)); if (caseFiles.size() == 1) { CaseData caseFile = (CaseData) caseFiles.iterator().next(); FactHandle factHandle = getProcessInstance().getKnowledgeRuntime().getFactHandle(caseFile); if (value == null) { caseFile.remove(nameInCaseFile); } else { caseFile.add(nameInCaseFile, value); } getProcessInstance().getKnowledgeRuntime().update(factHandle, caseFile); ((KieSession)getProcessInstance().getKnowledgeRuntime()).fireAllRules(); return; } } // not a case, store it in normal variables variables.put(name, value); }
public WorkItem getWorkItem() { if (workItem == null && workItemId >= 0) { workItem = ((WorkItemManager) ((ProcessInstance) getProcessInstance()) .getKnowledgeRuntime().getWorkItemManager()).getWorkItem(workItemId); } return workItem; }
if (getProcessInstance() != null && getProcessInstance().getKnowledgeRuntime() != null) { value = getProcessInstance().getKnowledgeRuntime().getGlobal(name); if (value != null) { return value; Collection<CaseData> caseFiles = (Collection<CaseData>) getProcessInstance().getKnowledgeRuntime().getObjects(new ClassObjectFilter(CaseData.class)); if (caseFiles.size() == 1) { CaseData caseFile = caseFiles.iterator().next();
public void setVariable(String name, Object value) { if (name == null) { throw new IllegalArgumentException( "The name of a variable may not be null!"); } Object oldValue = getVariable(name); if (oldValue == null) { if (value == null) { return; } } ProcessEventSupport processEventSupport = ((InternalProcessRuntime) getProcessInstance() .getKnowledgeRuntime().getProcessRuntime()).getProcessEventSupport(); processEventSupport.fireBeforeVariableChanged( (variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getProcessInstance(), getProcessInstance().getKnowledgeRuntime()); internalSetVariable(name, value); processEventSupport.fireAfterVariableChanged( (variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getProcessInstance(), getProcessInstance().getKnowledgeRuntime()); }
public void handleException(ExceptionHandler handler, String exception, Object params) { if (handler instanceof ActionExceptionHandler) { ActionExceptionHandler exceptionHandler = (ActionExceptionHandler) handler; Action action = (Action) exceptionHandler.getAction().getMetaData("Action"); try { ProcessInstance processInstance = getProcessInstance(); ProcessContext processContext = new ProcessContext(processInstance.getKnowledgeRuntime()); ContextInstanceContainer contextInstanceContainer = getContextInstanceContainer(); if (contextInstanceContainer instanceof NodeInstance) { processContext.setNodeInstance((NodeInstance) contextInstanceContainer); } else { processContext.setProcessInstance(processInstance); } String faultVariable = exceptionHandler.getFaultVariable(); if (faultVariable != null) { processContext.setVariable(faultVariable, params); } action.execute(processContext); } catch (Exception e) { throw new RuntimeException("unable to execute Action", e); } } else { throw new IllegalArgumentException("Unknown exception handler " + handler); } }
case ABORT: ((WorkItemManager) ((ProcessInstance) getProcessInstance()) .getKnowledgeRuntime().getWorkItemManager()).abortWorkItem(getWorkItem().getId()); break; case RETHROW: .getKnowledgeRuntime().getWorkItemManager()).retryWorkItem(getWorkItem().getId(), parameters); break; case COMPLETE: .getKnowledgeRuntime().getWorkItemManager()).completeWorkItem(getWorkItem().getId(), ((WorkflowProcessInstanceImpl)processInstance).getVariables()); break;
protected KieRuntime getKieRuntimeForSubprocess() { KieRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime(); RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (manager != null) { org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(); String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID); if (caseId != null) { context = CaseContext.get(caseId); } RuntimeEngine runtime = manager.getRuntimeEngine(context); kruntime = (KieRuntime) runtime.getKieSession(); } return kruntime; }
public boolean evaluate(NodeInstance instance, Connection connection, Constraint constraint) { WorkflowProcessInstance processInstance = instance.getProcessInstance(); InternalAgenda agenda = (InternalAgenda) ((ProcessInstance) processInstance).getKnowledgeRuntime().getAgenda(); String rule = "RuleFlow-Split-" + processInstance.getProcessId() + "-" + ((Node) instance.getNode()).getUniqueId() + "-" + ((Node) connection.getTo()).getUniqueId() + "-" + connection.getToType(); return agenda.isRuleActiveInRuleFlowGroup( "DROOLS_SYSTEM", rule, processInstance.getId() ); }
processId = processId.replace("#{" + replacement.getKey() + "}", replacement.getValue()); KieBase kbase = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime().getKieBase(); throw new RuntimeException("Could not find process " + processId); } else { KieRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime(); RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (manager != null) {
KieRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime(); kruntime.update(kruntime.getFactHandle(this), this); } else {
((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) {
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(); }
public void cancel() { super.cancel(); if (getSubProcessNode() == null || !getSubProcessNode().isIndependent()) { ProcessInstance processInstance = null; InternalKnowledgeRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime(); RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (manager != null) { try { org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(processInstanceId); String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID); if (caseId != null) { context = CaseContext.get(caseId); } RuntimeEngine runtime = manager.getRuntimeEngine(context); KieRuntime managedkruntime = (KieRuntime) runtime.getKieSession(); processInstance = (ProcessInstance) managedkruntime.getProcessInstance(processInstanceId); } catch (SessionNotFoundException e) { // in case no session is found for parent process let's skip signal for process instance completion } } else { processInstance = (ProcessInstance) kruntime.getProcessInstance(processInstanceId); } if (processInstance != null) { processInstance.setState(ProcessInstance.STATE_ABORTED); } } }
if ( processInstance.getKnowledgeRuntime() == null ) { Long parentProcessInstanceId = (Long) ((ProcessInstanceImpl) processInstance).getMetaData().get("ParentProcessInstanceId"); if (parentProcessInstanceId != null) {
public boolean evaluate(NodeInstance instance, Connection connection, Constraint constraint) { Object value; try { ProcessContext context = new ProcessContext(((ProcessInstance)instance.getProcessInstance()).getKnowledgeRuntime()); context.setNodeInstance( instance ); value = this.evaluator.evaluate( context ); } catch ( Exception e ) { throw new RuntimeException( "unable to execute ReturnValueEvaluator: ", e ); } if ( !(value instanceof Boolean) ) { throw new RuntimeException( "Constraints must return boolean values: " + value + " for expression " + constraint); } return ((Boolean) value).booleanValue(); }
public void internalSetVariable(String name, Object value) { if (name.startsWith(VariableScope.CASE_FILE_PREFIX)) { String nameInCaseFile = name.replaceFirst(VariableScope.CASE_FILE_PREFIX, ""); // store it under case file rather regular variables @SuppressWarnings("unchecked") Collection<CaseData> caseFiles = (Collection<CaseData>) getProcessInstance().getKnowledgeRuntime().getObjects(new ClassObjectFilter(CaseData.class)); if (caseFiles.size() == 1) { CaseData caseFile = (CaseData) caseFiles.iterator().next(); FactHandle factHandle = getProcessInstance().getKnowledgeRuntime().getFactHandle(caseFile); if (value == null) { caseFile.remove(nameInCaseFile); } else { caseFile.add(nameInCaseFile, value); } getProcessInstance().getKnowledgeRuntime().update(factHandle, caseFile); ((KieSession)getProcessInstance().getKnowledgeRuntime()).fireAllRules(); return; } } // not a case, store it in normal variables variables.put(name, value); }
public WorkItem getWorkItem() { if (workItem == null && workItemId >= 0) { workItem = ((WorkItemManager) ((ProcessInstance) getProcessInstance()) .getKnowledgeRuntime().getWorkItemManager()).getWorkItem(workItemId); } return workItem; }
protected KieRuntime getKieRuntimeForSubprocess() { KieRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime(); RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (manager != null) { org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(); String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID); if (caseId != null) { context = CaseContext.get(caseId); } RuntimeEngine runtime = manager.getRuntimeEngine(context); kruntime = (KieRuntime) runtime.getKieSession(); } return kruntime; }
public boolean evaluate(NodeInstance instance, Connection connection, Constraint constraint) { WorkflowProcessInstance processInstance = instance.getProcessInstance(); InternalAgenda agenda = (InternalAgenda) ((ProcessInstance) processInstance).getKnowledgeRuntime().getAgenda(); String rule = "RuleFlow-Split-" + processInstance.getProcessId() + "-" + ((Node) instance.getNode()).getUniqueId() + "-" + ((Node) connection.getTo()).getUniqueId() + "-" + connection.getToType(); return agenda.isRuleActiveInRuleFlowGroup( "DROOLS_SYSTEM", rule, processInstance.getId() ); }