Smooks and Drools Pipeline
by Dave Macpherson
Hey guys (Drools newbie here)
I'm *attempting* to use the Drools/Smooks pipeline functionality to insert
facts into my knowledgebase and I'm having a little trouble figuring out
exactly how to do this. I've read the API docs for the 5.0.0.M5 and looked
at the test cases but I guess I'm still not quite getting it, so I'm hoping
someone here can point me in the right direction.
I've got an XML file defined basically like this:
<submission>
<facility>
<faccode>xxx</faccode>
</facility>
<lineitem>
<acctcode>xxxx</acctcode>
<amount>999</amount>
<lineitem>
<lineitem>
<acctcode>xxxx</acctcode>
<amount>999</amount>
<lineitem>
<submission>
Within the XML file, there is 1 and only 1 "facility" node and multiple
"lineitem" nodes. I'd like to use the DroolsSmooks pipleline functionality
to use Smooks to insert 1 "facility" fact and multiple "lineitem" facts into
my knowledgbase.
The code I've written to do this is similar to the following (taken from
sample test code I've seen in the Drools source):
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Action executeResultHandler = PipelineFactory.newExecuteResultHandler();
KnowledgeRuntimeCommand insertStage =
PipelineFactory.newStatefulKnowledgeSessionInsert();
insertStage.setReceiver(executeResultHandler);
Smooks smooks = new Smooks("smooks-config.xml");
Transformer transformer =
PipelineFactory.newSmooksFromSourceTransformer(smooks, "root");
transformer.setReceiver(insertStage);
Pipeline pipeline =
PipelineFactory.newStatefulKnowledgeSessionPipeline(ksession);
pipeline.setReceiver(transformer);
ResultHandlerImpl resultHandler = new ResultHandlerImpl();
pipeline.insert(ResourceFactory.newClassPathResource("submission.xml"),
resultHandler );
While stepping through the above code, the last line returns an NPE. I've
tried playing with the "Transformer transformer - PipeLineFactory." line,
substituting "root" for something else and it goes into an infinite loop.
What is the purpose of the "root" value being set in this line?
Can anyone tell me if I'm even on the right track here, or am I
misunderstanding what the Smooks data loader can do for me?
Regards,
Dave
17 years, 3 months
java.lang.NoClassDefFoundError: org/drools/spi/Consequence
by Ojwang Wilson O
All,
I am getting the error below while passing DroolsAnt build pkg as a
property to RuleAgent. I am using Java 6 update 12.
===================
2009-03-02 16:48:59,363 Stdout ERROR callout.err - RuleAgent(default)
INFO (Mon Mar 02 16:48:59 CST 2009): Configuring package provider :
FileScanner scanning: /home/nxuser/proxy/resource/iaoc/rules/Rules.pkg
java.lang.NoClassDefFoundError: org/drools/spi/Consequence
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at
org.drools.rule.PackageCompilationData$PackageClassLoader.fastFindClass(PackageCompilationData.java:333)
at
org.drools.rule.PackageCompilationData$PackageClassLoader.loadClass(PackageCompilationData.java:353)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at
org.drools.common.DroolsObjectInputStream.resolveClass(DroolsObjectInputStream.java:79)
at
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at
java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
==================
Regards
Wilson
17 years, 3 months
query support in Drools 5
by Michal Bali
Hi,
Is there a way to get the QueryResults from a StatefulKnowledgeSession in
Drools 5.0 ?
The old API has a getQueryResults method but I can't find it in the new API.
Thanks,
Best Regards,
Michal
17 years, 3 months
Ksession inside a executeWorkitem() ?
by Cristiano Gavião
Hi people,
Im trying to create a workitemhandler for use Drools Pipeline and
Smooks to import data inside working memory and process it.
I want to share the working memory that was created for the main
process that is calling the workitem for configure the Drools Pipeline
inside it.
What is the best approach to do that, use Globals to pass the
knowledgesession?
any ideias?
Thanks in advance
_________________________
Cristiano V. Gavião
17 years, 3 months
Re: [rules-users] Creating objects in WHEN clause
by Greg Barton
Ah, I thought the LHS was parsed into mvel by default. OK, my bad.
--- On Sun, 3/1/09, Edson Tirelli <tirelli(a)post.com> wrote:
> From: Edson Tirelli <tirelli(a)post.com>
> Subject: Re: [rules-users] Creating objects in WHEN clause
> To: greg_barton(a)yahoo.com
> Date: Sunday, March 1, 2009, 6:19 PM
> Hold on. :) We are talking about Drools, not java.
>
> When you write a pattern:
>
> SomeClass( foo < $otherFoo )
>
> Drools will use its own implementation of
> "<" to make the comparison. It
> does not delegate that to java and so it must work. If does
> not work, it may
> be a bug, but our tests work for that:
>
> http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-core/src...
>
> Take a look at testObject().
>
> []s
> Edson
>
> 2009/3/1 Greg Barton <greg_barton(a)yahoo.com>
>
> > Oh, you dun thrown down the gauntlet now. :)
> >
> > The following will not compile with java6:
> >
> > public class ComparableFu {
> >
> > static class Foo implements
> Comparable<Foo> {
> >
> > private int foo;
> >
> > public Foo(int foo) {
> > this.foo = foo;
> > }
> >
> > public int compareTo(Foo other) {
> > if(other.foo < foo) {
> > return -1;
> > } else if(other.foo == foo) {
> > return 0;
> > } else {
> > return 1;
> > }
> > }
> > }
> >
> > public static void main(String[] args) {
> > System.out.println(new Foo(1) < new
> Foo(2)); //Baaaaad!
> > }
> > }
> >
> > Methinks the overloading of comparison operators for
> Comparables is an mvel
> > feature.
> >
> > --- On Sun, 3/1/09, Edson Tirelli
> <tirelli(a)post.com> wrote:
> >
> > > From: Edson Tirelli <tirelli(a)post.com>
> > > Subject: Re: [rules-users] Creating objects in
> WHEN clause
> > > To: greg_barton(a)yahoo.com, "Rules Users
> List" <
> > rules-users(a)lists.jboss.org>
> > > Date: Sunday, March 1, 2009, 12:46 PM
> > > Just a comment:
> > >
> > > "There is no operator overloading in java,
> so the
> > > "<" operator must act on a
> > > numerical primitive. (int, double, etc.) "
> > >
> > > This is not true. Comparison operators will
> work on any
> > > "comparable"
> > > type. So if Quantity implements Comparable
> interface, it
> > > must work.
> > > Otherwise it is a bug.
> > >
> > > Although, remember that Drools always makes
> type
> > > coercion from the right
> > > to the left value, so, for that to actually work:
> > >
> > > Person( height < $2m )
> > >
> > > "height" must be comparable to $2m.
> > >
> > > []s
> > > Edson
> > >
> > >
> > > 2009/2/26 Greg Barton
> <greg_barton(a)yahoo.com>
> > >
> > > > The problem is the "Person( height <
> $2m
> > > )" part. There is no operator
> > > > overloading in java, so the "<"
> operator
> > > must act on a numerical primitive.
> > > > (int, double, etc.) $2m is a Quantity. As
> for why
> > > this doesn't error out,
> > > > I'm not sure, but it certainly won't
> execute.
> > > (Unless mvel has some
> > > > capabilities I'm not aware of.)
> > > >
> > > > Try
> > > >
> > > > Person( height < $2m.height )
> > > >
> > > > ...as long as Person.height and
> Quantity.height are
> > > both numerical types.
> > > >
> > > > If you want to specifically call compareTo()
> you
> > > should use an eval block:
> > > >
> > > > WHEN
> > > > $meter:UoM( ) from
> > > UoMs.get("length","m")
> > > > $2m:Quantity() from
> Quantities.get(2,$meter)
> > > > $p: Person()
> > > > eval($p.getHeight().compareTo($2m))
> > > >
> > > > However, even if this works, I hope
> you're not
> > > going to be putting too much
> > > > data through rules like this. The way
> it's
> > > currently constructed it
> > > > completely circumvents all of drools'
> indexing
> > > ability. :) The power of
> > > > rules comes from tracking the changes in a
> set of
> > > objects, and firing rules
> > > > based on only the changes observed. (That
> set is the
> > > working memory.) The
> > > > "from" keyword allows you to have
> rules that
> > > draw objects from outside
> > > > working memory, but you pay for that
> convenience: the
> > > cost is not being able
> > > > to track changes. As a result, objects
> gathered using
> > > "from" must be
> > > > reconsidered even if they haven't
> changed (i.e.
> > > every time the condition is
> > > > encountered) because drools has no way of
> knowing if
> > > they've changed or not.
> > > >
> > > > So, after this long winded spiel, here's
> my
> > > suggestion: get the rule(s) to
> > > > work using "from" but also try
> inserting the
> > > Quantity object in working
> > > > memory. If you're processing enough
> data with the
> > > rules you will notice a
> > > > difference.
> > > >
> > > > --- On Thu, 2/26/09, David Boaz
> > > <davidb(a)dbmotion.com> wrote:
> > > >
> > > > > From: David Boaz
> <davidb(a)dbmotion.com>
> > > > > Subject: Re: [rules-users] Creating
> objects in
> > > WHEN clause
> > > > > To: rules-users(a)lists.jboss.org
> > > > > Date: Thursday, February 26, 2009, 9:13
> AM
> > > > > Thanks for your all help.
> > > > > with your help, my rule looks now as:
> > > > > WHEN $meter:UoM( ) from
> > > > >
> UoMs.get("length","m")
> > > > > $2m:Quantity() from
> > > Quantities.get(2,$meter)
> > > > > Person( height < $2m )
> > > > >
> > > > > My Quantity class implements Comparable
> > > interface. When
> > > > > running the rule on
> > > > > a good dataset (where I expect the rule
> to fire),
> > > the rule
> > > > > fails with no
> > > > > error. in addition, the
> compareTo(Object o)
> > > method is not
> > > > > called (the
> > > > > debugger doesn't stop in this
> method).
> > > > >
> > > > > Can you please help?
> > > > > Thanks, David
> > > >
> > > >
> > > >
> > > >
> _______________________________________________
> > > > rules-users mailing list
> > > > rules-users(a)lists.jboss.org
> > > >
> https://lists.jboss.org/mailman/listinfo/rules-users
> > > >
> > >
> > >
> > >
> > > --
> > > Edson Tirelli
> > > JBoss Drools Core Development
> > > JBoss, a division of Red Hat @ www.jboss.com
> >
> >
> >
> >
>
>
> --
> Edson Tirelli
> JBoss Drools Core Development
> JBoss, a division of Red Hat @ www.jboss.com
17 years, 3 months