[rules-users] Guvnor and drools implementation - questions

ioda100 eddyhautot at gmail.com
Tue Mar 8 10:56:49 EST 2011


Hi Vincent,

Thanks for precisions.

Didn't knew only set/get are used. Get to be careful when i will have 100+
attributes  :-)

Yes i created rueles with guided editor and it's working with my attribute.
is there a way to remove "empty", "entrySet", "keySet", "clone",... herited
from Map. So i would have only the attribute i have defined?

Ok i will do like this for testing eval($m1 != $m2) ... i have put this in
separate line to meke it clearer at the beginning.

I think i will do your first option, rules will be clearer.

i have always used drl file instead of package. If i deploy a  file.pkg, is
there a way to know what's in it? If i deploy something, i just want to be
able later to very that all is well what i think if i have a doubt (easy
with drl file).

When i try to create my session i have problem with pkg. For know with .drl
file i do with that :

KnowledgeBase knowledgeBase = createKnowledgeBase();
StatefulKnowledgeSession session =
knowledgeBase.newStatefulKnowledgeSession();

private static KnowledgeBase createKnowledgeBase() {
        final KnowledgeBuilder builder =
KnowledgeBuilderFactory.newKnowledgeBuilder ();


builder.add(ResourceFactory.newUrlResource("file:///d://basicRule.drl"),
ResourceType.DRL);
        if (builder.hasErrors()) {
            throw new RuntimeException(builder.getErrors()
                    .toString());
        }
        KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());

        return knowledgeBase;
    }

If i replace the line :
builder.add(ResourceFactory.newUrlResource("file:///d://basicRule.drl"),
ResourceType.DRL);
by :
builder.add(ResourceFactory.newUrlResource("file:///d://PackageTest1.pkg"),
ResourceType.PKG);

but it's crashing :
xception in thread "main" org.drools.RuntimeDroolsException: Unable to load
dialect
'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
    at
org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:283)
    at
org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:268)
    at
org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:181)
    at
org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:154)
    at
org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilderConfiguration(KnowledgeBuilderFactoryServiceImpl.java:26)
    at
org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(KnowledgeBuilderFactory.java:86)
    at TestMapPojoPackage.createKnowledgeBase(TestMapPojoPackage.java:86)
    at TestMapPojoPackage.main(TestMapPojoPackage.java:58)
Caused by: java.lang.RuntimeException: The Janino jar is not in the
classpath
    at
org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConfiguration.java:100)
    at
org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:55)
    at
org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:279)
    ... 7 more

Is it something special to do?

Thanks again for your time


On Mon, Mar 7, 2011 at 7:44 PM, Vincent Legendre [via Drools - Java Rules
Engine] <ml-node+2647352-436278430-237284 at n3.nabble.com> wrote:

> <html> <head> </head> <body text="#000000" bgcolor="#ffffff">
>
> I've just created 2 class like you show me with some changes to fit and
> test all (timestamp are long in fact, i have put int, double and string as
> well)
>
> In the second class you don't need the attributes as members, because
> Drools uses get / set methods to deduce them, and anyway you never use them
> as they are stored in the map.
>
> Then i have imported this in Guvnor.
>
> I have made 2 categories. I have put the model (jar) in the 2 categories.
>
> That is non-sense. Jars are not linked to a category but to a package.
>
>  I have created 2 simple rules playing with the attributes id, timestamp...
>
> With Guided editor ?
>
>
>
> 1) For the condition Map $m1 different then Map $m2. I suppose i have to
> use the function define in MapPojo? I have to write it by hand using "free
> from drl" : eval($m1 != $m2) ? or is there a better way?
>
> Its a way.
> You can also test the id directly in conditions (in Guided editor, bind the
> id of the first instance to a var, then compare it in the second condition.
>
>
> The same for testing that $m1 timestamp (Long) is befor $m2. I have to
> write it by hand : eval($m1.isBefore($m2))? So they have to know it exist a
> method isBefore if not said by the gui?
>
> Same. Add the test directly in the condition.
> Another solution is to use a custom operator (search this mailing list for
> samples).
>
>   2) In the code It's written MapTest1(..) instead of Map(...) so i
> suppose drools has to do it with the precompiled package  .pkg to know about
> the MapPojo and MapTest1.. If i take only the .drl, drools won't know about
> class MapTest1.
>
> It is MapTest1, because this is the class used .... and drools knows it
> because it uses it ... You don't use Map directly anymore
>
>
> Yes i can set a category to each of my rule.
>
> Yes you can !
>
>  Do you mean create 4 categories (cat1, cat2, cat3, cat4) and for rules of
> file1.drl, put them it cat1, for file2.drl, put them in cat2... ?
>
> Yes
>
>  Set a first condition in the rules?
>
> Choose between categories and first condition. Don't use both
>
> Am i obliged to create a package per file and filter by category or is it
> possible to make a package with all and filtering when creating the
> knowledgeBase or something like that?
>
> You certainly can filter your KB afterwards, but this is not really an
> out-of-the-box function. To me you have two options. For both options, you
> have only one Guvnor package :*
>
> First option* : categories
> set categories for your rules as you said
> compile by filtering one category, do a snapshot. Redo the same for other
> categories (in other snapshots).
> Use these 4 snapshots in your code
>
> *Second option *: First filtering condition
> create a new POJO having only one field to handle the task asked (or
> category or group or file or whatever you call that) add a condition to all
> your rules testing this fact according to their group (as described in one
> of my previous mail)
> create a single package (or use DRL) for all your rules.
> when calling your rules, insert the suitable POJO according to tehexec you
> want.
>
> The second is my favorite because it is less work to deploy, and your
> number of rules are quite small. The second option can be change to use a
> RuleFlow instead of a control fact.
>
>
> </body> </html>
> _______________________________________________
> rules-users mailing list
> [hidden email]<http://user/SendEmail.jtp?type=node&node=2647352&i=0&by-user=t>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://drools-java-rules-engine.46999.n3.nabble.com/Guvnor-and-drools-implementation-questions-tp2602641p2647352.html
>  To unsubscribe from Guvnor and drools implementation - questions, click
> here<http://drools-java-rules-engine.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=2602641&code=ZWRkeWhhdXRvdEBnbWFpbC5jb218MjYwMjY0MXwtMTEzMzMwMzAxNA==>.
>
>


--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Guvnor-and-drools-implementation-questions-tp2602641p2651282.html
Sent from the Drools - User mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110308/159d676d/attachment.html 


More information about the rules-users mailing list