use of org.drools.compiler.lang.descr.ActionDescr in project jbpm by kiegroup.
the class ExtendedNodeBuilder method buildAction.
protected void buildAction(DroolsAction droolsAction, ProcessBuildContext context, NodeImpl node) {
DroolsConsequenceAction action = (DroolsConsequenceAction) droolsAction;
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText(action.getConsequence());
actionDescr.setResource(context.getProcessDescr().getResource());
ProcessDialect dialect = ProcessDialectRegistry.getDialect(action.getDialect());
dialect.getActionBuilder().build(context, action, actionDescr, node);
}
use of org.drools.compiler.lang.descr.ActionDescr in project jbpm by kiegroup.
the class ProcessBuilderImpl method buildContexts.
public void buildContexts(ContextContainer contextContainer, ProcessBuildContext buildContext) {
List<Context> exceptionScopes = contextContainer.getContexts(ExceptionScope.EXCEPTION_SCOPE);
if (exceptionScopes != null) {
for (Context context : exceptionScopes) {
// TODO: OCRAM: add compensation scope to process builder????
ExceptionScope exceptionScope = (ExceptionScope) context;
for (ExceptionHandler exceptionHandler : exceptionScope.getExceptionHandlers().values()) {
if (exceptionHandler instanceof ActionExceptionHandler) {
DroolsConsequenceAction action = (DroolsConsequenceAction) ((ActionExceptionHandler) exceptionHandler).getAction();
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText(action.getConsequence());
actionDescr.setResource(buildContext.getProcessDescr().getResource());
ProcessDialect dialect = ProcessDialectRegistry.getDialect(action.getDialect());
dialect.getActionBuilder().build(buildContext, action, actionDescr, (ProcessImpl) buildContext.getProcess());
}
}
}
}
}
use of org.drools.compiler.lang.descr.ActionDescr in project jbpm by kiegroup.
the class MVELActionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("list.add( 'hello world' )");
KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg);
DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
MVELDialect mvelDialect = (MVELDialect) dialectRegistry.getDialect("mvel");
PackageBuildContext context = new PackageBuildContext();
context.init(pkgBuilder, pkg, null, dialectRegistry, mvelDialect, null);
pkgBuilder.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 builder = new MVELActionBuilder();
builder.build(context, action, actionDescr, actionNode);
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Arrays.asList(pkgBuilder.getPackages()));
final KieSession wm = kbase.newKieSession();
List<String> list = new ArrayList<String>();
wm.setGlobal("list", list);
MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkgBuilder.getPackage("pkg1").getDialectRuntimeRegistry().getDialectData("mvel");
((MVELAction) actionNode.getAction().getMetaData("Action")).compile(data);
ProcessContext processContext = new ProcessContext(((InternalWorkingMemory) wm).getKnowledgeRuntime());
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("hello world", list.get(0));
}
Aggregations