0

I am new to Drools. As per my usecase, I want to dynamically create the rules. I have considered using the following rule template:

 template header

 rule
 eventType

 package org.ossandme;

 global org.ossandme.AlertDecision alertDecision;

 template "alert"

 rule "alert_@{row.rowNumber}"

 when
      @{eventType}(@{rule})
 then
      alertDecision.setDoAlert(Boolean.TRUE);
 end

 end template

But the problem with this template is that it fixes the number of conditions and actions (1 in this case). According to my use case, I might have different number of conditions and actions in different rules. Is it possible to create a generic template which can create rules, with different number of conditions and different number of actions in each rule?

2 Answers2

0

Drools templates is just a fancy name for a String template mechanism. You can use whatever template framework you want to create your rules.

Some of the frameworks I've used in the past are:

Hope it helps,

Esteban Aliverti
  • 6,259
  • 2
  • 19
  • 31
0

The other answer suggesting any String template framework is correct; alternatively, if you want a pure Java-based solution, you may want to consider writing your rule dynamically with code using the Executable Model DSL.

You can reference this blog post which has link to references and examples how to use it.

tarilabs
  • 2,178
  • 2
  • 15
  • 23