Search in sources :

Example 1 with KogitoProcessRuntime

use of org.kie.kogito.internal.process.runtime.KogitoProcessRuntime 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 2 with KogitoProcessRuntime

use of org.kie.kogito.internal.process.runtime.KogitoProcessRuntime in project kogito-runtimes by kiegroup.

the class DynamicUtils method internalAddDynamicSubProcess.

public static String internalAddDynamicSubProcess(final WorkflowProcessInstance processInstance, final DynamicNodeInstance dynamicContext, KieRuntime ksession, final String processId, final Map<String, Object> parameters) {
    final SubProcessNodeInstance subProcessNodeInstance = new SubProcessNodeInstance();
    subProcessNodeInstance.setNodeInstanceContainer(dynamicContext == null ? processInstance : dynamicContext);
    subProcessNodeInstance.setProcessInstance(processInstance);
    subProcessNodeInstance.setMetaData("NodeType", "SubProcessNode");
    if (ksession instanceof StatefulKnowledgeSessionImpl) {
        return executeSubProcess((StatefulKnowledgeSessionImpl) ksession, processId, parameters, processInstance, subProcessNodeInstance);
    } else if (ksession instanceof CommandBasedStatefulKnowledgeSession) {
        ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
        return commandService.execute(new ExecutableCommand<String>() {

            private static final long serialVersionUID = 5L;

            public String execute(Context context) {
                StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
                KogitoProcessRuntime kruntime = asKogitoProcessRuntime(ksession);
                WorkflowProcessInstance realProcessInstance = (WorkflowProcessInstance) kruntime.getProcessInstance(processInstance.getStringId());
                subProcessNodeInstance.setProcessInstance(realProcessInstance);
                if (dynamicContext == null) {
                    subProcessNodeInstance.setNodeInstanceContainer(realProcessInstance);
                } else {
                    DynamicNodeInstance realDynamicContext = findDynamicContext(realProcessInstance, dynamicContext.getUniqueId());
                    subProcessNodeInstance.setNodeInstanceContainer(realDynamicContext);
                }
                return executeSubProcess((StatefulKnowledgeSessionImpl) ksession, processId, parameters, processInstance, subProcessNodeInstance);
            }
        });
    } else {
        throw new IllegalArgumentException("Unsupported ksession: " + (ksession == null ? "null" : ksession.getClass().getName()));
    }
}
Also used : RegistryContext(org.kie.internal.command.RegistryContext) Context(org.kie.api.runtime.Context) RuleUnitStatefulKnowledgeSessionImpl(org.drools.ruleunits.impl.sessions.RuleUnitStatefulKnowledgeSessionImpl) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) InternalProcessRuntime.asKogitoProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime.asKogitoProcessRuntime) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ExecutableCommand(org.kie.api.command.ExecutableCommand) KieSession(org.kie.api.runtime.KieSession) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) ExecutableRunner(org.kie.api.runtime.ExecutableRunner) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance)

Example 3 with KogitoProcessRuntime

use of org.kie.kogito.internal.process.runtime.KogitoProcessRuntime 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 4 with KogitoProcessRuntime

use of org.kie.kogito.internal.process.runtime.KogitoProcessRuntime in project kogito-runtimes by kiegroup.

the class LambdaSubProcessNodeInstance method cancel.

@Override
public void cancel() {
    super.cancel();
    if (getSubProcessNode() == null || !getSubProcessNode().isIndependent()) {
        ProcessInstance processInstance = null;
        KogitoProcessRuntime kruntime = (KogitoProcessRuntime) ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime();
        processInstance = (ProcessInstance) kruntime.getProcessInstance(processInstanceId);
        if (processInstance != null) {
            processInstance.setState(ProcessInstance.STATE_ABORTED);
        }
    }
}
Also used : KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance)

Example 5 with KogitoProcessRuntime

use of org.kie.kogito.internal.process.runtime.KogitoProcessRuntime in project kogito-runtimes by kiegroup.

the class ForEachTest method test.

@Test
public void test() {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("ParentProcess");
    factory.variable("x", new ObjectDataType("java.lang.String"));
    factory.variable("y", new ObjectDataType("java.lang.String"));
    factory.variable("list", new ObjectDataType("java.util.List"));
    factory.variable("listOut", new ObjectDataType("java.util.List"));
    factory.name("Parent Process");
    factory.packageName("org.drools.bpmn2");
    factory.dynamic(false);
    factory.version("1.0");
    factory.visibility("Private");
    factory.metaData("TargetNamespace", "http://www.example.org/MinimalExample");
    org.jbpm.ruleflow.core.factory.StartNodeFactory startNode1 = factory.startNode(1);
    startNode1.name("StartProcess");
    startNode1.done();
    org.jbpm.ruleflow.core.factory.ForEachNodeFactory forEachNode2 = factory.forEachNode(2);
    forEachNode2.metaData("UniqueId", "_2");
    forEachNode2.metaData("MICollectionOutput", "_2_listOutOutput");
    forEachNode2.metaData("x", 96);
    forEachNode2.metaData("width", 110);
    forEachNode2.metaData("y", 16);
    forEachNode2.metaData("MICollectionInput", "_2_input");
    forEachNode2.metaData("height", 48);
    forEachNode2.collectionExpression("list");
    forEachNode2.variable("x", new ObjectDataType("java.lang.String"));
    forEachNode2.outputCollectionExpression("listOut");
    forEachNode2.outputVariable("y", new ObjectDataType("java.lang.String"));
    forEachNode2.actionNode(5).action((kcontext) -> System.out.println(kcontext.getVariable("x"))).done();
    forEachNode2.linkIncomingConnections(5);
    forEachNode2.linkOutgoingConnections(5);
    forEachNode2.done();
    org.jbpm.ruleflow.core.factory.EndNodeFactory endNode3 = factory.endNode(3);
    endNode3.name("EndProcess");
    endNode3.terminate(true);
    endNode3.done();
    factory.connection(1, 2, "_1-_2");
    factory.connection(2, 3, "_2-_3");
    factory.validate();
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "oldValue");
    parameters.put("list", list);
    parameters.put("listOut", listOut);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime(factory.getProcess());
    kruntime.startProcess("ParentProcess", parameters);
}
Also used : Test(org.junit.jupiter.api.Test) List(java.util.List) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) Map(java.util.Map) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) ArrayList(java.util.ArrayList) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)121 Test (org.junit.jupiter.api.Test)105 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)102 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)82 StringReader (java.io.StringReader)71 ArrayList (java.util.ArrayList)68 Reader (java.io.Reader)59 ReaderResource (org.drools.core.io.impl.ReaderResource)50 HashMap (java.util.HashMap)34 Person (org.jbpm.integrationtests.test.Person)16 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)16 Disabled (org.junit.jupiter.api.Disabled)15 TestWorkItemHandler (org.jbpm.integrationtests.handler.TestWorkItemHandler)14 List (java.util.List)9 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)9 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)8 EndNode (org.jbpm.workflow.core.node.EndNode)8 StartNode (org.jbpm.workflow.core.node.StartNode)8 KieSession (org.kie.api.runtime.KieSession)8 LoggerFactory (org.slf4j.LoggerFactory)8