Reputation: 28
I am trying to create rules in java by using the Fluent Api. Actually I have successfully created rules in a way I like, however I could not find a way to create a rule without adding a package name.
Java Code:
PackageDescr pkg = DescrFactory.newPackage()
.name("org.drools.example")
.newRule().name("Xyz")
.attribute("ruleflow-grou","bla")
.lhs()
.and()
.pattern("Foo").id( "$foo", false ).constraint("bar==baz").constraint("x>y").end()
.not().pattern("Bar").constraint("a+b==c").end().end()
.end()
.end()
.rhs( "System.out.println();" ).end()
.getDescr();
DrlDumper dumper = new DrlDumper();
String drl = dumper.dump(pkg);
DRL File:
package org.drools.example ---> I do not want this to be included
rule "Xyz"
ruleflow-grou bla
when
(
$foo : Foo( bar==baz, x>y ) and
not(
Bar( a+b==c ) ) )
then
System.out.println();
end
Thanks in advance.
Note: I am using Drools 7.3.0 which was installed default by eclipse
Upvotes: 1
Views: 895
Reputation: 6322
What you can do is to reuse the same PackageDescrBuilder
for all your rules. After you are done with one rule, just call end().newRule()
to start with your other rule:
PackageDescr pkg = DescrFactory.newPackage()
.name("org.drools.example")
.newRule().name("Rule 1")
.attribute("ruleflow-grou","bla")
.lhs()
.and()
.pattern("Foo").id( "$foo", false).constraint("bar==baz").constraint("x>y")
.end()
.not().pattern("Bar").constraint("a+b==c")
.end().end()
.end()
.end()
.rhs( "System.out.println();" ).end()
.newRule().name("Rule 2") // <--- Here starts the new rule
.lhs()...end()
.rhs()...end()
.getDescr();
Hope it helps,
Upvotes: 0