use of org.jbpm.process.instance.KogitoProcessContextImpl in project kogito-runtimes by kiegroup.
the class MVELDecisionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("list.add( 'hello world' )");
builder = new KnowledgeBuilderImpl(pkg, new SemanticKnowledgeBuilderConfigurationImpl());
PackageRegistry pkgReg = builder.getPackageRegistry(pkg.getName());
MVELDialect mvelDialect = (MVELDialect) pkgReg.getDialectCompiletimeRegistry().getDialect("mvel");
PackageBuildContext context = new PackageBuildContext();
context.init(builder, pkg, null, pkgReg.getDialectCompiletimeRegistry(), mvelDialect, null);
builder.addPackageFromDrl(new StringReader("package pkg1;\nglobal java.util.List list;\n"));
ActionNode actionNode = new ActionNode();
DroolsAction action = new DroolsConsequenceAction("java", null);
actionNode.setAction(action);
final MVELActionBuilder actionBuilder = new MVELActionBuilder();
actionBuilder.build(context, action, actionDescr, actionNode);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
List<String> list = new ArrayList<String>();
kruntime.getKieSession().setGlobal("list", list);
MVELDialectRuntimeData data = (MVELDialectRuntimeData) builder.getPackage("pkg1").getDialectRuntimeRegistry().getDialectData("mvel");
KogitoProcessContext processContext = new KogitoProcessContextImpl(kruntime.getKieSession());
((MVELAction) actionNode.getAction().getMetaData("Action")).compile(data);
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("hello world", list.get(0));
}
use of org.jbpm.process.instance.KogitoProcessContextImpl in project kogito-runtimes by kiegroup.
the class JavaActionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("list.add( \"hello world\" );");
builder = new KnowledgeBuilderImpl(pkg, new SemanticKnowledgeBuilderConfigurationImpl());
DialectCompiletimeRegistry dialectRegistry = builder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
JavaDialect javaDialect = (JavaDialect) dialectRegistry.getDialect("java");
ProcessDescr processDescr = new ProcessDescr();
processDescr.setClassName("Process1");
processDescr.setName("Process1");
WorkflowProcessImpl process = new WorkflowProcessImpl();
process.setName("Process1");
process.setPackageName("pkg1");
ProcessBuildContext context = new ProcessBuildContext(builder, builder.getPackage("pkg1"), null, processDescr, dialectRegistry, javaDialect);
context.init(builder, pkg, null, dialectRegistry, javaDialect, null);
builder.addPackageFromDrl(new StringReader("package pkg1;\nglobal java.util.List list;\n"));
ActionNode actionNode = new ActionNode();
DroolsAction action = new DroolsConsequenceAction("java", null);
actionNode.setAction(action);
ProcessDialect dialect = ProcessDialectRegistry.getDialect("java");
dialect.getActionBuilder().build(context, action, actionDescr, actionNode);
dialect.addProcess(context);
javaDialect.compileAll();
assertEquals(0, javaDialect.getResults().size());
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
List<String> list = new ArrayList<String>();
kruntime.getKieSession().setGlobal("list", list);
KogitoProcessContext processContext = new KogitoProcessContextImpl(kruntime.getKieRuntime());
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("hello world", list.get(0));
}
use of org.jbpm.process.instance.KogitoProcessContextImpl in project kogito-runtimes by kiegroup.
the class MVELActionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("list.add( 'hello world' )");
builder = new KnowledgeBuilderImpl(pkg, new SemanticKnowledgeBuilderConfigurationImpl());
DialectCompiletimeRegistry dialectRegistry = builder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
MVELDialect mvelDialect = (MVELDialect) dialectRegistry.getDialect("mvel");
PackageBuildContext context = new PackageBuildContext();
context.init(builder, pkg, null, dialectRegistry, mvelDialect, null);
builder.addPackageFromDrl(new StringReader("package pkg1;\nglobal java.util.List list;\n"));
ActionNode actionNode = new ActionNode();
DroolsAction action = new DroolsConsequenceAction("mvel", null);
actionNode.setAction(action);
final MVELActionBuilder actionBuilder = new MVELActionBuilder();
actionBuilder.build(context, action, actionDescr, actionNode);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
List<String> list = new ArrayList<String>();
kruntime.getKieSession().setGlobal("list", list);
MVELDialectRuntimeData data = (MVELDialectRuntimeData) builder.getPackage("pkg1").getDialectRuntimeRegistry().getDialectData("mvel");
((MVELAction) actionNode.getAction().getMetaData("Action")).compile(data);
KogitoProcessContext processContext = new KogitoProcessContextImpl(kruntime.getKieRuntime());
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("hello world", list.get(0));
}
use of org.jbpm.process.instance.KogitoProcessContextImpl in project kogito-runtimes by kiegroup.
the class ActionNodeInstance method internalTrigger.
@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
triggerTime = new Date();
if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("An ActionNode only accepts default incoming connections!");
}
Map<String, Object> data = NodeIoHelper.processInputs(this, key -> getVariable(key));
Action action = (Action) getActionNode().getAction().getMetaData("Action");
try {
KogitoProcessContextImpl context = ContextFactory.fromNode(this);
context.setContextData(data);
executeAction(action, context);
} catch (WorkflowRuntimeException wre) {
throw wre;
} catch (Exception e) {
// - or context.setNodeInstance(this)
throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
}
triggerCompleted();
}
use of org.jbpm.process.instance.KogitoProcessContextImpl in project kogito-runtimes by kiegroup.
the class LambdaSubProcessNodeInstance method processInstanceCompleted.
public void processInstanceCompleted(ProcessInstance processInstance) {
removeEventListeners();
handleOutMappings(processInstance);
if (processInstance.getState() == ProcessInstance.STATE_ABORTED) {
String faultName = processInstance.getOutcome() == null ? "" : processInstance.getOutcome();
// handle exception as sub process failed with error code
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, faultName);
if (exceptionScopeInstance != null) {
KogitoProcessContextImpl context = new KogitoProcessContextImpl(this.getProcessInstance().getKnowledgeRuntime());
context.setProcessInstance(this.getProcessInstance());
context.setNodeInstance(this);
context.getContextData().put("Exception", processInstance.getFaultData());
exceptionScopeInstance.handleException(faultName, context);
if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
cancel();
}
return;
} else if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
getProcessInstance().setState(ProcessInstance.STATE_ABORTED, faultName);
return;
}
}
// handle dynamic subprocess
if (getNode() == null) {
setMetaData("NodeType", "SubProcessNode");
}
// if there were no exception proceed normally
triggerCompleted();
}
Aggregations