Here is my attempt at using the Drools 5 API to execute my
dynamically created Process:
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();
org.drools.rule.Package
p = new org.drools.rule.Package("sample");
p.addProcess(createProcess());
KnowledgePackageImp
kpi = new KnowledgePackageImp();
kpi.pkg
= p;
List<KnowledgePackage>
list = new ArrayList<KnowledgePackage>();
list.add(kpi);
kbase.addKnowledgePackages(list);
StatefulKnowledgeSession
ksess = kbase.newStatefulKnowledgeSession();
ksess.startProcess("org.drools.sample.workflow.dynamic");
I still get the same null pointer error. Perhaps the
problem is in my implementation of the Process API? The code under
createProcess is this:
RuleFlowProcessFactory
factory =
RuleFlowProcessFactory.createProcess("com.datacert.workflow.dynamic");
factory
.name("HelloWorldRuleSet")
.version("1.0")
.packageName("org.drools")
.startNode(1).name("Start").done()
.actionNode(2)
.name("Action")
.action("java", "System.out.println(\"Inside Action
1\");").done()
.endNode(3).name("End").done()
.connection(1, 2)
.connection(2, 3);
return
factory.validate().getProcess();
Thanks,
Scott
From:
rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Mauricio
Salatino
Sent: Monday, November 02, 2009 2:14 PM
To: Rules Users List
Subject: Re: [rules-users] How to execute a Process API result?
That are only the fluent api to
create processes. I recommend you the other approach:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource("MyProcess.rf"),
ResourceType.DRF );
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.startProcess("com.sample.MyProcess");
If you need the reference to the process instance you can do:
WorkFlowProcessInstance processInstance = ksession.startProcess(...);
Work
2009/11/2 Scott Stevenson <scott.stevenson@datacert.com>
I read that section but I’m still
not clear how to add my process (created like the section just before) to the
KnowledgeBase. Section 3.2 shows adding an existing .rf file. I have this
code:
RuleFlowProcessFactory
factory =
RuleFlowProcessFactory.createProcess("org.drools.sample.workflow.dynamic");
factory
.name("HelloWorldRuleSet")
.version("1.0")
.packageName("org.drools")
.startNode(1).name("Start").done()
.actionNode(2)
.name("Action")
.action("java",
"System.out.println(\"Inside Action 1\");").done()
.endNode(3).name("End").done()
.connection(1, 2)
.connection(2, 3);
factory.validate().getProcess();
How does the getProcess() result get
added to a KnowledgeBase?
Thanks,
Scott
From: rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Mauricio Salatino
Sent: Monday, November 02, 2009 1:57 PM
To: Rules Users List
Subject: Re: [rules-users] How to execute a Process API result?
Ok,
so you need to start using the Drools 5 APIs.
Please take a look at the Drools 5 documentation:
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-flow/html_single/index.html#d0e1375
In the section 3.2
you will find the correct api's.
Greetings.
2009/11/2
Scott Stevenson <scott.stevenson@datacert.com>
I’m working with Drools 5.
From: rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Mauricio Salatino
Sent: Monday, November 02, 2009 1:45 PM
To: Rules Users List
Subject: Re: [rules-users] How to execute a Process API result?
Are you
working just with the Drools 4 version?
Or you can jump to the Drools 5 version?
On
Mon, Nov 2, 2009 at 5:41 PM, Scott Stevenson <scott.stevenson@datacert.com>
wrote:
I'm
trying to execute the result of the Process API and running into
problems most likely stemming from my ignorance. I'm creating a new
process following the sample code from section 3.1.3.2 of the User
Guide. My sample process consists of:
1. StartNode
2. ActionNode that prints Hello World
3. EndNode
What I don't understand is how to get my new process into a
KnowledgeBase and KnowledgeSession for execution. I've tried the
following (Drools 4 method, I believe) as well:
AbstractRuleBase ruleBase = (AbstractRuleBase)
RuleBaseFactory.newRuleBase();
ruleBase.addProcess(createProcess());
InternalWorkingMemory workingMemory = new
ReteooWorkingMemory(1,
ruleBase);
workingMemory.startProcess("org.drools.sample.workflow.dynamic");
The result of the previous code is a RuntimeException (unable to execute
Action). Inner exception is null pointer from inside the
ActionNodeInstance class. Where am going wrong in implementing the
Process API?
Thank you,
Scott Stevenson
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
- http://salaboy.wordpress.com
- http://www.jbug.com.ar
- Salatino "Salaboy" Mauricio -
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
- http://salaboy.wordpress.com
- http://www.jbug.com.ar
- Salatino "Salaboy" Mauricio -
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
- http://salaboy.wordpress.com
- http://www.jbug.com.ar
- Salatino "Salaboy" Mauricio -