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);
}
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()));
}
}
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();
}
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);
}
}
}
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);
}
Aggregations