Search in sources :

Example 6 with ActionDescr

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);
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionDescr(org.drools.compiler.lang.descr.ActionDescr) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect)

Example 7 with ActionDescr

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());
                }
            }
        }
    }
}
Also used : Context(org.jbpm.process.core.Context) ProcessBuildContext(org.jbpm.process.builder.ProcessBuildContext) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) ExceptionHandler(org.jbpm.process.core.context.exception.ExceptionHandler) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionDescr(org.drools.compiler.lang.descr.ActionDescr) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 8 with ActionDescr

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));
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) MVELActionBuilder(org.jbpm.process.builder.dialect.mvel.MVELActionBuilder) MVELAction(org.jbpm.process.instance.impl.MVELAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DroolsAction(org.jbpm.workflow.core.DroolsAction) Action(org.jbpm.process.instance.impl.Action) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) ActionDescr(org.drools.compiler.lang.descr.ActionDescr) ActionNode(org.jbpm.workflow.core.node.ActionNode) ArrayList(java.util.ArrayList) MVELDialect(org.drools.compiler.rule.builder.dialect.mvel.MVELDialect) ProcessContext(org.drools.core.spi.ProcessContext) MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) PackageBuildContext(org.drools.compiler.rule.builder.PackageBuildContext) MVELAction(org.jbpm.process.instance.impl.MVELAction) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

ActionDescr (org.drools.compiler.lang.descr.ActionDescr)8 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)8 ProcessDialect (org.jbpm.process.builder.dialect.ProcessDialect)6 ActionNode (org.jbpm.workflow.core.node.ActionNode)6 StringReader (java.io.StringReader)4 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 ProcessContext (org.drools.core.spi.ProcessContext)4 Action (org.jbpm.process.instance.impl.Action)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 DroolsAction (org.jbpm.workflow.core.DroolsAction)4 Test (org.junit.Test)4 KieSession (org.kie.api.runtime.KieSession)4 ArrayList (java.util.ArrayList)3 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)3 ProcessDescr (org.drools.compiler.lang.descr.ProcessDescr)2 PackageBuildContext (org.drools.compiler.rule.builder.PackageBuildContext)2 MVELDialect (org.drools.compiler.rule.builder.dialect.mvel.MVELDialect)2