[rules-users] Setting date during execution of rules.

Scott Reed sreed at avacoda.com
Thu Mar 6 09:30:08 EST 2008


I am probably still misunderstanding, but it seems that the effective 
and expires dates are constants that can be used in the left hand side 
of the rules:
rule "Commission Calculation 07-08"
          when
                   $agent: Agent( promotedDate >= "01-Apr-2007",
                                          promotedDate <= "30-Mar-2008")
                   $sale: Sale( agent = $agent, $amount: amount  )
                   ....
          then
                  $agent.addCommission( $sale, $amount, .09); // .09 is 
the commission rate for this rule
                   ....
end


Now for the next financial year we define a new rule as follows

rule "Commission Calculation 08-09"
          when
                   $agent: Agent( promotedDate >= "01-Apr-2008",
                                          promotedDate <= "30-Mar-2009")
                   $sale: Sale( agent = $agent, $amount: amount  )
                  ....
          then
                  $agent.addCommission( $sale, $amount, .06); // .06 is 
the commission rate for this rule
end

Nimesh Muley's message received 3/6/2008 1:00 AM:
>
> I was not able to portray the right picture L. Here's another shot at 
> clarifying my situation.
>
>  
>
> Let's say we have a commission rule as follows
>
> rule "Commission Calculation *07-08*"
>
>           *date-effective "01-Apr-2007"*
>
>           *date-expires "30-Mar-2008"*
>
>           when
>
>                    ....
>
>           then
>
>                    ....
>
> end
>
>  
>
> Now for the next financial year we define a new rule as follows
>
> rule "Commission Calculation *08-09*"
>
>           *date-effective "01-Apr-2008"*
>
>           *date-expires "30-Mar-2009"*
>
>           when
>
>                    ....
>
>           then
>
>                    ....
>
> end
>
>  
>
> Now let's say /_today's date is 15^th April 2008_/. An agent is 
> promoted today with /_effective date as 1^st March 2008_/. Hence his 
> commission needs to be recalculated as per the "Commission Calculation 
> *07-08*" rule and *_not_* the effective rule as on today i.e. 
> "Commission Calculation *08-09*". For rest of the agents commission 
> would be calculated based on the rule effective today i.e. 15^th April 
> 2008. Hence a need to pass a date during execution of rule based on 
> which the right rule would be chosen.
>
>  
>
> Basically there is no legacy code as part of my example but a need to 
> fire the rules that are effective on a date other than the system date 
> always.
>
>  
>
> I have seen similar functionality in other rules engines too. Can this 
> be done in JBoss Rules? If yes, is TimeMachine the right way of doing it?
>
>  
>
> Regards,
>
> - Nimesh
>
>  
>
> ------------------------------------------------------------------------
>
> *From:* rules-users-bounces at lists.jboss.org 
> [mailto:rules-users-bounces at lists.jboss.org] *On Behalf Of *Scott Reed
> *Sent:* Wednesday, March 05, 2008 8:40 PM
> *To:* Rules Users List
> *Subject:* Re: [rules-users] Setting date during execution of rules.
>
>  
>
> As I understand it, the problem is that you have legacy code that uses 
> the system date in it's calculations and you cannot fix that so it 
> will take a date parameter, right? If so, then my recommendation is to 
> fix the legacy software if possible since messing with the system date 
> gives me the willies. If you can't fix it, then anything that can be 
> called from Java to set the system date 
> (e.g.Runtime.exec(...).waitfor()?) should be callable from the 'then' 
> part of a rule. Make that call, call your legacy code, then make the 
> call to set the date back. But that is so ugly, please don't tell 
> anyone I had anything to do with it.
>
> Nimesh Muley's message received 3/5/2008 1:25 AM:
>
> Hi,
>
>  
>
> Is there a way to set the date while executing the rules? The 
> effective dates would be checked against this date instead of today's 
> date. By default the effective dates would be checked with System 
> date. But in some cases we would need to execute the rules in a 
> 'back-dated' mode.
>
>  
>
> Use case.
>
> Let's say in insurance industry there are commission calculation rules 
> for an agent. On these rules the effective dates are appropriate (as 
> per their needs). Now when an agent is promoted and his/her promotion 
> date is couple of months back then we would want to calculate the 
> commission once again with the date as 2 months back.
>
>  
>
> The nearest I could see is TimeMachine, as this is being used during 
> execution of rules. Although I could not find a way to set the 
> TimeMachine in release 4.0.4.
>
>  
>
> Has anyone tried something like this before?
>
>  
>
> Regards,
>
> - Nimesh
>
> "The first 90% of a project takes 90% of the time, the last 10% takes 
> the other 90% of the time" - Murphy's Law
>
> While so very true, this is not Murphy's Law, which I think of as 
> "Whatever can go wrong, probably will." (see 
> http://en.wikipedia.org/wiki/Murphy%27s_law)
> Your rule here is called the 90-90 rule: 
> http://en.wikipedia.org/wiki/Ninety-ninety_rule
>
>  
>
>  
>
>
>
>
> MASTEK LTD.
> Making a valuable difference
> Mastek in NASSCOM's 'India Top 20' Software Service Exporters List.
> In the US, we're called MAJESCOMASTEK
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080306/fa8a295b/attachment.html 


More information about the rules-users mailing list