[rules-users] Can calendars be defined within .drl ?

Wolfgang Laun wolfgang.laun at gmail.com
Fri Sep 13 15:36:55 EDT 2013


Rules can be annotated with user-defined annotations. You might use
an annotation to define the parameters of a calendar:

rule "my rule"
@cal( "foo", ... )
calendars "foo"
when...

To make this work, code must be written to pass through the knowledge
package prior to session creation, inspecting the annotations on rules
and creating the Quartz calendars accordingly to insert them into the
session.

Needless to say, I've not tried all of this, but getting annotation
data works fine.

-W




On 13/09/2013, Alexander Wolf <mail at alexander-wolf.net> wrote:
> Hey,
>
> I use a lot of quartz calendars in my rules like this:
>
> rule "my rule"
> 	calendars "myCalendar"
> when
>
> But defining them in java is quite verbose. Also I often use the same
> calendar for only one rule. I believe the calendar is part of the logic and
> therefore don't like to initialize it elsewhere but with the logic code in
> the rule.
>
> DailyCalendar myCalendar = new DailyCalendar( 7, 0, 0, 0, 8, 0, 0, 0 );
> myCalendar.setInvertTimeRange( true );
> ksession.getCalendars().set( "myCalendar",
> QuartzHelper.quartzCalendarAdapter( myCalendar ) );
>
> I would rather define calendars directly in the rule files or even exactly
> where I use them, e.g.
>
> rule "my super rule"
> 	calendars DailyCalendar(   7, 0, 0, 0, 8, 0, 0, 0, true );
> when
>
> or defining them in the rule file like this: (example)
>
> declare "myCalendar"
> 	@role(calendar)
> 	@type( daily )
> 	@from (7,0,0)
> 	@until (8, 0, 0)
> 	@invert(true)
> end
>
> and the use them as ever.
>
> I couldnt find anything like this in the documentation, but would not be
> surprised if it is actually already possible somehow.
>
> If not I would like to suggest this as a new feature ;)  (I think I'd prefer
> the second example with declare)
>
> - Alex
>
>


More information about the rules-users mailing list