Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drools Rule Language from Java API

Tags:

java

drools

Platform that I use requires Drools Rule Language (DRL), but for me more convenient thing is to create rules in Java API.

Is there any way to create rules in Java API, and then convert/transfer it to DRL?

Thx for answer.

like image 730
BartoBarto Avatar asked Sep 02 '15 09:09

BartoBarto


People also ask

How do you write rules in Drools?

Rule Definition − It consists of the Rule Name, the condition, and the Consequence. Drools keywords are rule, when, then, and end. In the above example, the rule names are “Hello World” and “GoodBye”. The when part is the condition in both the rules and the then part is the consequence.

How does Drools work in Java?

Drools is an open-source Business Rules Management Software (BRMS) written in Java that provides users with a variety of features like Business Rule Engine, Web authoring, Rules Management Application, and runtime support for Decision Model and Notation models.

What is DRL in Java?

A DRL file can contain one or more rules that define at minimum the rule conditions ( when ) and actions ( then ). The DRL designer in Decision Central provides syntax highlighting for Java, DRL, and XML. All data objects related to a DRL rule must be in the same project package as the DRL rule in Decision Central.


1 Answers

Drools does have a fluent API for building rules as Geoffrey mentioned, but it is not in the public API. You can use and it has been stable for several years now, but you need to be aware that there might be changes over time due to features being added to the engine.

The API is used by the Drools parser itself. Here are some unit tests that you can use as examples:

https://github.com/droolsjbpm/drools/blob/6.3.x/drools-compiler/src/test/java/org/drools/compiler/lang/api/DescrBuilderTest.java#L451-L465

like image 117
Edson Tirelli Avatar answered Oct 03 '22 04:10

Edson Tirelli