Is there any API in drools to create the drl files dynamically by just passing values?

前端 未结 6 1743
鱼传尺愫
鱼传尺愫 2021-02-04 12:47

I know how to create DRL files inside KIE workbench by using all the methods. But what my problem is without using the KIE workbench, can we create the .drl fil

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 13:29

    Even i have used the same implementation that @apandey846 suggested. I would just like to add one more thing: If you want to import the required classes, you can do it as follows:

                   PackageDescr pkg = DescrFactory.newPackage()                        
                   .newImport("classname").target().end()
                   .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();
    

    To add multiple conditions in the LHS, you can do:

                   pattern("eval").constraint("condition1").end().
                   pattern("eval").constraint("condition2").end().
                   pattern("eval").constraint("condition3").end().
    

    Hope it helps.. :)

提交回复
热议问题