drools magic value when using functions

167 views
Skip to first unread message

David "Borris" Fell

unread,
Sep 10, 2014, 5:32:09 PM9/10/14
to drools...@googlegroups.com
As I understand it, when we use insert or retract etc in a consequence, this is a shorthand for referencing methods of these names from an object called drools, which the documentation says is of type KnowledgeHelper.

I want to do some inserts in a function. I'm guessing I need to reference the drools object, as the insert doesn't work by itself (and I've not seen anything saying this magic drools macro stuff applies to functions). I want to do something like:

function void blah( Thing a )
{
drools.insert( a );
}

but how do I get the drools object? I can't see any obvious references to KnowledgeHelper in the current JavaDocs. Google gives some matches, but all for notably older version (4.x for example). So I guess the documentation hasn't kept track with the codebase (eg renames to Kie for many things with 6.x). Can anyone give me the magic runes that let my methods invoke insert, retract, modify etc as if in a consequence section?

Thanks

Borris

Davide Sottara

unread,
Sep 10, 2014, 7:12:07 PM9/10/14
to drools...@googlegroups.com
The KnowledgeHelper is available in the RHS, so you need something like this:

function void blah( Thing a, KnowledgeHelper kh ) {
  kh.insert( a );
}

rule "my"
when
then
    blah( new Stuff(), drools );
end

The KH itself is here:
https://github.com/droolsjbpm/drools/blob/master/drools-core/src/main/java/org/drools/core/spi/KnowledgeHelper.java
--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/db0ab798-81d2-4e84-b609-33dc094fad36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David "Borris" Fell

unread,
Sep 11, 2014, 1:05:42 PM9/11/14
to drools...@googlegroups.com
In case anyone else is after the same answer, you'll also want

import org.drools.core.spi.KnowledgeHelper;

and then things works.

Thanks Davide! 
Reply all
Reply to author
Forward
0 new messages