Setting date range for a single rule (also ON/OFF)

764 views
Skip to first unread message

James Owen

unread,
Jul 14, 2015, 9:43:20 PM7/14/15
to drools...@googlegroups.com
Greetings:

I need to be able to do two things with a rule.  I can do these with ODM or Blaze but I have not found a way to do this with Drools.

1.  I want to be able to dynamically (via a customer configuration file) set a valid date range for a single rule such that it can be valid for June/July of any years or June/July of 2015 only.
2.  I want to be able to dynamically (via a customer configuration file) set a rule ON or OFF. 

James Owen




On Jul 14, 2015, at 1:03 AM, drools...@googlegroups.com wrote:

Ashish Soni <ashish...@gmail.com>: Jul 13 02:20PM -0700

Hi All ,
Please help for the below error
 
I am creating a stateless session as below and packing my JAR using Maven
Shade Plugin which is also including all the jars needed for my application ...more
Ashish Soni <ashish...@gmail.com>: Jul 13 05:01PM -0700

Please help as i do not understand this behaviour when i do not have any
spreadsheet at all.
 
Ashish
 
On Monday, 13 July 2015 17:20:40 UTC-4, Ashish Soni wrote:
...more
James Owen <jco_...@icloud.com>: Jul 13 01:49PM -0400

Has anyone found a good book on Drools 6.x ? There is one on jBPMS 6 by Estaban, Maricio and Mariano. (BTW, the rating on this one was only 1 star out of 5 stars.)
 
I found several on Drools 5, ...more
Mauricio Salatino <sal...@gmail.com>: Jul 13 07:57PM +0100

Hi James,
We are writing one right now with Esteban and Mariano again. The one that
you mention about jBPM 6 is from Mariano, and it was an update of our
previous book about jBPM 5. ...more
Davide Sottara <dso...@gmail.com>: Jul 13 01:59PM -0500

Mauricio, I will surely regret it ;), but I may be interested in reviewing
the book myself
 
On Mon, Jul 13, 2015 at 1:57 PM, Mauricio Salatino <sal...@gmail.com>
wrote:
 
...more
Mauricio Salatino <sal...@gmail.com>: Jul 13 08:28PM +0100

I'm sure that I will regret it :) hehe.. We are trying to have the first 6
chapters draft so they can be reviewed
 
 
 
--
- MyJourney @ http://salaboy.com <http://salaboy.wordpress.com> ...more
Scott Siebers <s.si...@gmail.com>: Jul 13 09:31AM -0700

We recently started evaluating Drools / Workbench for a project I'm working
on, and have been quite impressed with how far the web UI has come since
the 5.X releases. One thing I'm having ...more
techj...@gmail.com: Jul 13 06:27AM -0700

Colleagues,
 
I am working on a big enterprise project, that uses Drools for business
logic validation. We have 500+ drools, the initial Drools version is 5.1.0,
java 1.6.
Currently, we are ...more
Mark Proctor <mdpr...@gmail.com>: Jul 13 04:45PM +0100

There should be no breaking changes between 5.1.0 and 5.5.0. If you are
finding them, it is likely a bug.
 
Mark
 
...more
techj...@gmail.com: Jul 13 08:57AM -0700

Agree, seems like I am facing bugs caused by the lack of a strict
validation. But once again - the goal is to move to 6.1.0 or 6.2.0. So
where is a lot of work ahead and I need some kind of drl ...more
jsf75 <jsf...@gmail.com>: Jul 13 02:37AM -0700

Hi John,
 
I didn't really try yet, but I'm also looking for that kind of feature.
 
I will recommend you to take a look at the AgendaEventListener which
provide a lot of events and some of them ...more
Michael Anstis <michael...@gmail.com>: Jul 13 10:28AM +0100

GWT applications require a recompilation of the "client side" source code
to regenerate the JavaScript.
 
All Workbench related JARs named *-client*.jar are only used during the GWT ...more
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to drools-usage...@googlegroups.com.

Edson Tirelli

unread,
Jul 15, 2015, 3:13:45 PM7/15/15
to drools...@googlegroups.com

   James,

   Drools supports a rule attribute ("enabled") that allows authors to enable/disable rules based on boolean expressions. E.g.:

rule X
   enabled (<boolean expression>)
...

    That expression can be a constant, can use LHS bindings, globals or static classes.

    Drools does not provide out of the box a "configuration file to enable/disable rules", but assuming you create a java class to read your configuration file, then you can use that in the rule:

rule X
   enabled( myConfFile.isThisRuleEnabled( rule. name ) )
...

   For dates, Drools provides "effective-date" and "expiration-date" attributes, but the enabled attribute I mentioned above is more flexible.

   If you prefer to not use the "enabled" attribute, another approach is by using an AgendaFilter. With an agenda filter, you can veto rule executions based on any criteria. 

   Hope it helps.

   Edson


--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/2A3F4FB2-A01E-4177-8C01-A8D23DD72D06%40icloud.com.
For more options, visit https://groups.google.com/d/optout.



--
  Edson Tirelli
  Principal Software Engineer 
  Red Hat Business Systems and Intelligence Group

jco

unread,
Jul 16, 2015, 1:46:47 AM7/16/15
to drools...@googlegroups.com
Edson:

Thanks - I will try that tomorrow (Friday) and let you know how everything works out early next week.  For some reason I did not find that in the manual when I first looked.  Thanks again. 

jco

David Weir

unread,
Jul 18, 2015, 7:39:27 PM7/18/15
to drools...@googlegroups.com
Its hard to find the documentation - only mention I found is in  

Figure 7.10. rule attributes in the 6.2.0 final docs. It's just in the diagram, not the explanation.


So Edison, is it possible to dynamically enable/disable a rule?  If so, how do you do it? Would @enabled(exists(MyObject(name==myRuleEnabler)) do it? So I can insert or delete MyObjects 
to enable/disable the rule?

Mind you, I'm using AgendaFilters to enable/disable groups of rules. 
Would the same technique work if the MyObject name was set to a group name and all the rules in that group shared the same @enabled () statement?

Edson Tirelli

unread,
Jul 20, 2015, 3:54:39 PM7/20/15
to drools...@googlegroups.com

    David,

> So Edison, is it possible to dynamically enable/disable a rule?

   Yes, based on boolean expressions.

Would @enabled(exists(MyObject(name==myRuleEnabler)) do it?

   No, if you want to use full patterns, then you can use that as a condition in the LHS of the rule:

rule X
when
    exists(MyObject(name==myRuleEnabler))
...

   But lets say you have a boolean expression that you want to use to enable/disable rule, then you can use the "enabled" attribute. For instance, if you have a global that you want to query, or an attribute of a bound fact that you want to check, you could do:

rule X
    enabled( someGlobal.isRuleEnabled( rule.name ) )
when
....

   In the above example, "rule.name" is a self reference to the rule name, i.e. "X" in the example. "isRuleEnabled" is a method on the "someGlobal" global.

 I'm using AgendaFilters to enable/disable groups of rules.

   That is fine, although not my own preferred choice.

Would the same technique work if the MyObject name was set to a group name and all the rules in that group shared the same @enabled () statement?

   Yes. You can simply create an annotation to assign a group to each rule and then use the enabled expression to enable/disable groups based on the rule group. I don't remember the exact syntax (been a while), but pseudo code would be like: 

rule X
   @Group( "finance" )
   enabled( myGlobal.isGroupEnabled( rule.metaData["Group"] ) )
when 
   ...

   Here are a few examples:


   Edson



   
   





For more options, visit https://groups.google.com/d/optout.

James Owen

unread,
Jul 21, 2015, 3:54:57 PM7/21/15
to drools...@googlegroups.com
Edson:

I went out and looked at the four examples in the link below.  Where is the metadata file located that would contain the “ON/OFF” switch for such rules?  The example that looked OK was as follows:

rule "Test enabled expression 1"
@ruleID(1234)
// arbitrary expression using a rule metadata
enabled ( rule.metaData["ruleID"] == "1234" )
when
Person(name == "Michael")
then
results.add( "1" );
end


James Owen
RuleBased Decisions Corporation
Senior BRMS Consultant / Architect]
Co-Founder & Speaker:  Rules Fest  
Co-Founder & Group LeadDallas Rules Group
RBDC/KBSC is celebrating 278years in business in 2015




You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/n3O_2_Jgf9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

jco

unread,
Aug 3, 2015, 2:33:17 PM8/3/15
to Drools Usage
Edson:

Created a RuleConfig file (ruleConfig001a) that includes an attribute "String ruleName = new String(); "
After setting the other attributes,

 ksession.insert(ruleConfig01a);

The rule looks for a ruleConfig : RuleConfig ( ruleName == rule.name , ...);

I even included
rule "Pay001-LargeTransaction.1.1.0"
@ruleID(Pay001-LargeTransaction.1.1.0)

However, when running the application and looking for ruleName, I get the following error ONLY when I include the part about a rule.name.  Why is rule.name null?  Did I miss something somewhere?

KBASES: [rules]
rules sessions: [PayWatch]
Exception in thread "main" [Error: null pointer: rule.name]
[Near : {... ruleName == rule.name ....}]
 

Edson Tirelli

unread,
Aug 4, 2015, 3:34:14 PM8/4/15
to drools...@googlegroups.com
Hi James,

As you know, there are many ways to achieve the same results, as we
discussed on this thread. If you want to use a RuleConfig object to
enable/disable rules, you can do it by either setting it as a global
(in case it is immutable) or by inserting it into the working memory
as you said you are doing and using the "enabled()" rule attribute to
do that.

EXAMPLE 1: using a global:

global foo.bar.RuleConfig config

rule R1
enabled( rule.name == config.ruleName )
when
....

EXAMPLE 2: inserting the config object as a fact:

rule R1
enabled( rule.name == $config.ruleName )
when
$config : RuleConfig()
....

Please note that I am using the enabled attribute in order to get
a reference to the rule name using: "rule.name".

Alternatively, if you don't want to use the enabled attribute, you
can hard code the name of the rule:

EXAMPLE 3: not using the enabled attribute:

rule R1
when
RuleConfig( ruleName == "R1" )
...

Now, regarding your question about the "rule" object reference:
"rule" is a special variable that is injected into the rule attributes
that resolve expressions and into the rule consequence during runtime.
It is *not* injected into the rule conditions because as you know,
conditions can be shared between multiple rules, so it would make no
sense to inject it there. This is the reason why it is not possible to
reference the "rule" variable as part of a constraint on the LHS of
rules.

Hope this helps,

Edson
> --
> You received this message because you are subscribed to the Google Groups
> "Drools Usage" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to drools-usage...@googlegroups.com.
> To post to this group, send email to drools...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/drools-usage/f8435062-ee81-469d-91a5-ef0a1bde87b7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages