Search in sources :

Example 1 with InternalKogitoWorkItemManager

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);
    }
}
Also used : KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)

Example 2 with InternalKogitoWorkItemManager

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);
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)

Example 3 with InternalKogitoWorkItemManager

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);
}
Also used : KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) InternalProcessRuntime.asKogitoProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime.asKogitoProcessRuntime) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager)

Example 4 with InternalKogitoWorkItemManager

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();
}
Also used : InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance)

Example 5 with InternalKogitoWorkItemManager

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;
    }
}
Also used : HashMap(java.util.HashMap) KogitoProcessContextImpl(org.jbpm.process.instance.KogitoProcessContextImpl) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) ProcessWorkItemHandlerException(org.kie.api.runtime.process.ProcessWorkItemHandlerException) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) ExceptionScopeInstance(org.jbpm.process.instance.context.exception.ExceptionScopeInstance)

Aggregations

InternalKogitoWorkItemManager (org.kie.kogito.process.workitems.InternalKogitoWorkItemManager)7 HashMap (java.util.HashMap)2 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)2 InvalidLifeCyclePhaseException (org.kie.kogito.process.workitem.InvalidLifeCyclePhaseException)2 LifeCyclePhase (org.kie.kogito.process.workitem.LifeCyclePhase)2 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)2 WorkItemHandlerNotFoundException (org.drools.core.WorkItemHandlerNotFoundException)1 InternalProcessRuntime.asKogitoProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime.asKogitoProcessRuntime)1 KogitoProcessContextImpl (org.jbpm.process.instance.KogitoProcessContextImpl)1 ProcessInstance (org.jbpm.process.instance.ProcessInstance)1 ExceptionScopeInstance (org.jbpm.process.instance.context.exception.ExceptionScopeInstance)1 HumanTaskWorkItemImpl (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl)1 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)1 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)1 NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)1 ProcessWorkItemHandlerException (org.kie.api.runtime.process.ProcessWorkItemHandlerException)1 KogitoProcessEventSupport (org.kie.kogito.internal.process.event.KogitoProcessEventSupport)1 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)1 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)1 AbstractProcessInstance (org.kie.kogito.process.impl.AbstractProcessInstance)1