use of org.kie.kogito.process.workitems.InternalKogitoWorkItemManager in project kogito-runtimes by kiegroup.
the class SignalProcessInstanceAction method execute.
@Override
public void execute(KogitoProcessContext context) throws Exception {
String variableName = VariableUtil.resolveVariable(this.variableNameExpression, context.getNodeInstance());
KogitoProcessInstance processInstance = context.getProcessInstance();
KogitoNodeInstance nodeInstance = context.getNodeInstance();
Object signal = null;
if (inputVariable != null) {
signal = context.getContextData().get(inputVariable);
} else {
if (variableName != null) {
signal = context.getVariable(variableName);
} else {
signal = eventDataSupplier.apply(context);
}
}
signal = signal != null ? signal : variableName;
// compute inputs for throwing
Map<String, Object> inputSet = new HashMap<>();
inputSet.put("Data", signal);
String signalName = VariableUtil.resolveVariable(this.signalNameTemplate, context.getNodeInstance());
context.getKogitoProcessRuntime().getProcessEventSupport().fireOnSignal(processInstance, nodeInstance, context.getKieRuntime(), signalName, signal);
if (DEFAULT_SCOPE.equals(scope)) {
context.getKogitoProcessRuntime().signalEvent(signalName, signal);
} else if (PROCESS_INSTANCE_SCOPE.equals(scope)) {
context.getProcessInstance().signalEvent(signalName, signal);
} else if (EXTERNAL_SCOPE.equals(scope)) {
KogitoWorkItemImpl workItem = new KogitoWorkItemImpl();
workItem.setName("External Send Task");
workItem.setNodeInstanceId(context.getNodeInstance().getStringId());
workItem.setProcessInstanceId(context.getProcessInstance().getStringId());
workItem.setNodeId(context.getNodeInstance().getNodeId());
workItem.getParameters().putAll(inputSet);
workItem.setParameter("Signal", signalName);
workItem.setParameter("SignalProcessInstanceId", context.getVariable("SignalProcessInstanceId"));
workItem.setParameter("SignalWorkItemId", context.getVariable("SignalWorkItemId"));
workItem.setParameter("SignalDeploymentId", context.getVariable("SignalDeploymentId"));
((InternalKogitoWorkItemManager) context.getKogitoProcessRuntime().getKogitoWorkItemManager()).internalExecuteWorkItem(workItem);
}
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItemManager in project kogito-runtimes by kiegroup.
the class HandleMessageAction method execute.
@Override
public void execute(KogitoProcessContext context) throws Exception {
KogitoWorkItemImpl workItem = new KogitoWorkItemImpl();
workItem.setName("Send Task");
workItem.setNodeInstanceId((context.getNodeInstance()).getStringId());
workItem.setProcessInstanceId((context.getProcessInstance()).getStringId());
workItem.setNodeId(context.getNodeInstance().getNodeId());
workItem.setParameter(Metadata.MESSAGE_TYPE, messageType);
// compute inputs for message action
NodeInstanceImpl impl = ((NodeInstanceImpl) context.getNodeInstance());
Map<String, Object> inputSet = NodeIoHelper.processInputs(impl, varRef -> impl.getVariable(varRef));
workItem.getParameters().put(variableName, inputSet.get(variableName));
((InternalKogitoWorkItemManager) context.getKogitoProcessRuntime().getKogitoWorkItemManager()).internalExecuteWorkItem(workItem);
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItemManager in project kogito-runtimes by kiegroup.
the class DynamicUtils method executeWorkItem.
private static void executeWorkItem(StatefulKnowledgeSessionImpl ksession, KogitoWorkItemImpl workItem, WorkItemNodeInstance workItemNodeInstance) {
KogitoProcessRuntime kruntime = asKogitoProcessRuntime(ksession);
KogitoProcessEventSupport eventSupport = kruntime.getProcessEventSupport();
eventSupport.fireBeforeNodeTriggered(workItemNodeInstance, ksession);
((InternalKogitoWorkItemManager) kruntime.getKogitoWorkItemManager()).internalExecuteWorkItem(workItem);
workItemNodeInstance.internalSetWorkItemId(workItem.getStringId());
eventSupport.fireAfterNodeTriggered(workItemNodeInstance, ksession);
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItemManager in project kogito-runtimes by kiegroup.
the class WorkItemNodeInstance method cancel.
@Override
public void cancel() {
InternalKogitoWorkItem item = getWorkItem();
if (item != null && item.getState() != COMPLETED && item.getState() != ABORTED) {
try {
((InternalKogitoWorkItemManager) getProcessInstance().getKnowledgeRuntime().getWorkItemManager()).internalAbortWorkItem(item.getStringId());
} catch (WorkItemHandlerNotFoundException wihnfe) {
getProcessInstance().setState(STATE_ABORTED);
throw wihnfe;
}
}
if (exceptionHandlingProcessInstanceId != null) {
KogitoProcessRuntime kruntime = getKieRuntimeForSubprocess();
ProcessInstance processInstance = (ProcessInstance) kruntime.getProcessInstance(exceptionHandlingProcessInstanceId);
if (processInstance != null) {
processInstance.setState(STATE_ABORTED);
}
}
super.cancel();
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItemManager in project kogito-runtimes by kiegroup.
the class WorkItemNodeInstance method exceptionHandlingCompleted.
private void exceptionHandlingCompleted(WorkflowProcessInstance processInstance, ProcessWorkItemHandlerException handlerException) {
Object errorVariable = processInstance.getVariable("Error");
// allow child override
if (errorVariable instanceof ProcessWorkItemHandlerException) {
handlerException = (ProcessWorkItemHandlerException) errorVariable;
}
InternalKogitoWorkItemManager kogitoWorkItemManager = (InternalKogitoWorkItemManager) InternalProcessRuntime.asKogitoProcessRuntime(getProcessInstance().getKnowledgeRuntime()).getKogitoWorkItemManager();
switch(handlerException.getStrategy()) {
case ABORT:
kogitoWorkItemManager.abortWorkItem(getWorkItem().getStringId());
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());
}
KogitoProcessContextImpl context = new KogitoProcessContextImpl(this.getProcessInstance().getKnowledgeRuntime());
context.setProcessInstance(this.getProcessInstance());
context.setNodeInstance(this);
context.getContextData().put("Exception", handlerException.getCause());
exceptionScopeInstance.handleException(exceptionName, context);
break;
case RETRY:
Map<String, Object> parameters = new HashMap<>(getWorkItem().getParameters());
parameters.putAll(processInstance.getVariables());
processWorkItemHandler(() -> kogitoWorkItemManager.retryWorkItem(getWorkItem().getStringId(), parameters));
break;
case COMPLETE:
kogitoWorkItemManager.completeWorkItem(getWorkItem().getStringId(), processInstance.getVariables());
break;
}
}
Aggregations