[rules-users] Drools Flow Fluent API Help

Dan Nathanson dan at ddnconsulting.com
Mon Dec 27 14:35:36 EST 2010


I figured it out.

I was missing the buildProcess() call which actually turns all the nodes
into Rules:

        PackageBuilder packageBuilder = new PackageBuilder();
        ProcessBuilder processBuilder = new ProcessBuilder(packageBuilder);
        processBuilder.buildProcess(process, null);
I found it by grepping through the JUnit test cases in a test case that had
nothing to do with the Fluent API, but was just using it to create a process
as part of the set up for another test.

Now, I have another question: When using the Fluent API to create a Process
that has a WorkItemNode, do I have to define the work parameter definitions,
or can I just set parameters directly, without defining their types first?
Are the type definitions just needed for the UI process builders (which I
will not be using)?  I didn't see any code in the WorkItemImpl which checks
that the value passed to setParameter matches the defined types.

Regards,

Dan Nathanson



2010/12/27 Mauricio Salatino <salaboy at gmail.com>

> I'm working with 5.2.0.SNAPSHOT.. I will try to test your code and let you
> know my results..
> Greetings.
>
> 2010/12/27 Daniel Nathanson <dan at ddnconsulting.com>
>
>  Hi Mauricio,
>>
>> Were you ever able to figure out what I am doing wrong?
>>
>>  Regards,
>>
>> Dan Nathanson
>>
>>  On Dec 23, 2010, at 3:10 AM, Mauricio Salatino wrote:
>>
>>   Hi There..
>> What version of Drools are you using?
>> I can help you to figure out what is happening..
>>
>> 2010/12/23 Dan Nathanson <dan at ddnconsulting.com>
>>
>>> Hi,
>>>
>>> I've been banging my head against this for days and just can't get it
>>> to work.  At this point I'd like to just get the example code working.
>>>  I've got a simple class that is currently being driven by a JUnit
>>> test case.  I just want to create a Process flow and execute it.  I
>>> don't care what it does at this point.  Hello world level stuff.
>>>
>>> My method under test:
>>>
>>>        public String runFlow() throws Exception {
>>>
>>>        RuleFlowProcessFactory factory
>>> = RuleFlowProcessFactory.createProcess("org.drools.process");
>>>        factory
>>>                // header
>>>                .name("My process").packageName("org.drools")
>>>                // nodes
>>>                .startNode(1).name("Start").done()
>>>                .actionNode(2).name("Action")
>>>                .action("java", "System.out.println(\"Hello
>>> World\");").done()
>>>                .endNode(3).name("End").done()
>>>                // connections
>>>                .connection(1, 2)
>>>                .connection(2, 3);
>>>
>>>        RuleFlowProcess process = factory.validate().getProcess();
>>>
>>>        KnowledgeBase knowledgeBase =
>>> KnowledgeBaseFactory.newKnowledgeBase();
>>>        KnowledgeBuilder builder =
>>> KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBase);
>>>
>>>        Package pkg = new Package("package1");
>>>        pkg.addProcess(process);
>>>        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
>>>        ruleBase.addPackage(pkg);
>>>
>>>        Collection<KnowledgePackage> kpackages =
>>> builder.getKnowledgePackages();
>>>        KnowledgePackage kpackage = new KnowledgePackageImp(pkg);
>>>        kpackages.add(kpackage);
>>>        knowledgeBase.addKnowledgePackages(kpackages);
>>>
>>>        StatefulKnowledgeSession ksession =
>>> knowledgeBase.newStatefulKnowledgeSession();
>>>
>>>        KnowledgeRuntimeLogger logger =
>>> KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
>>>
>>>        ksession.startProcess("org.drools.process");
>>>
>>>        return "foo";
>>>    }
>>>
>>> When I run this process, I get an exception when the Action node is
>>> run.  It is a NPE and it happens because the metaData map in the
>>> underlying ActionNode does not contain a KVP for "Action".  It looks
>>> like that KVP is added in in the DroolsAction class when the public
>>> void wire(Object object) method is called.  Unfortunately, I can't
>>> figure out what causes that method to be called.  I'm pretty sure my
>>> problem is with the set up of my knowledge base (the call to new
>>> KnowledgePackageImp() is suspect), but I can't figure out how to set
>>> up the knowledge base when building a RuleFlowProcess using the
>>> RuleFlowProcessFactory.  None of the examples I can find show how to
>>> do this.
>>>
>>> Note that if I take out the Action node and just have Start and End
>>> nodes, it works fine.
>>>
>>> I am using Drools 5.1.0, but it doesn't work with Drools 5.0.1 either.
>>>
>>> Any help would be appreciated.  The flat spot on my forehead is
>>> getting flatter every day I continue to bang my head against the wall.
>>>
>>> Here's the output (including KnowledgeRuntimeLogger output):
>>>
>>> BEFORE RULEFLOW STARTED process:My process[id=org.drools.process]
>>> BEFORE RULEFLOW NODE TRIGGERED node:Start[id=1] process:My
>>> process[id=org.drools.process]
>>> null process:My process[id=org.drools.process]
>>> BEFORE RULEFLOW NODE TRIGGERED node:Action[id=2] process:My
>>> process[id=org.drools.process]
>>>
>>> java.lang.RuntimeException: unable to execute Action
>>>        at
>>> org.drools.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:56)
>>>        at
>>> org.drools.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:117)
>>>        at
>>> org.drools.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:178)
>>>        at
>>> org.drools.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:144)
>>>        at
>>> org.drools.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
>>>        at
>>> org.drools.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
>>>        at
>>> org.drools.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:117)
>>>        at
>>> org.drools.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:32)
>>>        at
>>> org.drools.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:192)
>>>        at
>>> org.drools.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:309)
>>>        at
>>> org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1644)
>>>        at
>>> org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1622)
>>>        at
>>> org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:301)
>>>        at
>>> com.proferi.epm.process.DroolsFlowManager.runFlow(DroolsFlowManager.java:75)
>>>        at
>>> com.proferi.epm.process.DroolsFlowManagerTest.testRunFlow(DroolsFlowManagerTest.java:33)
>>>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>        at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>        at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>        at
>>> org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
>>>        at
>>> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
>>>        at
>>> org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
>>>        at
>>> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
>>>        at
>>> org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
>>>        at
>>> org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
>>>        at
>>> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
>>>        at
>>> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
>>>        at
>>> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
>>>        at
>>> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>>>        at
>>> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>>>        at
>>> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
>>>        at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
>>>        at
>>> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
>>> Caused by: java.lang.NullPointerException
>>>        at
>>> org.drools.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:54)
>>>        ... 34 more
>>>
>>> Regards,
>>>
>>> Dan Nathanson
>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>>
>> --
>>  - CTO @ http://www.plugtree.com
>>  - MyJourney @ http://salaboy.wordpress.com
>>  - Co-Founder @ http://www.jbug.com.ar
>>
>>  - Salatino "Salaboy" Mauricio -
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
>  - CTO @ http://www.plugtree.com
>  - MyJourney @ http://salaboy.wordpress.com
>  - Co-Founder @ http://www.jbug.com.ar
>
>  - Salatino "Salaboy" Mauricio -
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101227/067197b1/attachment.html 


More information about the rules-users mailing list