Convert Java POJO to Drools DRL and vice versa
Asked Answered
T

1

5

I have rule configuration on UI which builds to Java POJO. How could I generate Drools DRL (to be passed to other component which will match facts, etc and returns true or false if rule matches).

Also I receive DRL file from database and in order to show rule on UI, I need to convert back to Java POJO.

Basiclly is there any tool or script that could convert between Java POJO and Drools DRL file? If not, what is the best way available?

Thanks much!

Twirp answered 3/5, 2012 at 15:26 Comment(0)
S
1

I am not sure what are your Java POJOs? Are they representing Rules, Patterns, Constraints, etc?

If so, Drools has an internal canonical model for representing all types of knowledge assets [1]. We do not recommend using it directly though, as it is an internal API and subject to change.

Another option for you is to use the actual rule descriptor builder API [2] to generate your rules dynamically [3].

Finally, if you have a web based UI and you want to allow users to author your rules in there, you have the option to embed guvnor's rule editor into your own application [4].

Hope this helps.

[1] https://github.com/droolsjbpm/drools/tree/master/drools-compiler/src/main/java/org/drools/lang/descr

[2] https://github.com/droolsjbpm/drools/tree/master/drools-compiler/src/main/java/org/drools/lang/api

[3] https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/lang/api/DescrBuilderTest.java

[4] http://www.plugtree.com/guvnor-embed-asset%E2%80%99s-editor-in-your-application/

Shankle answered 4/5, 2012 at 16:17 Comment(3)
Thanks Edson for your response. Java POJO in my case represents rule that includes rulename, "when" and "then" sections of drools rule. Package name and imports are created as required. I will look into links you provided and update here. Thanks for your help!Twirp
Edoson, Link (3) fits my need. I already developed boiler plate code using plain StringBuffer but it would be easy to use this API. Thanks for this valuable information.Twirp
All of these links are offline, would you mind to re-publish them?Kalmia

© 2022 - 2024 — McMap. All rights reserved.