[rules-users] Trouble getting functions to work in Guvnor

Wolfgang Laun wolfgang.laun at gmail.com
Mon Jun 20 03:07:16 EDT 2011


Isn't this a simple coding error:
       releaseDate<= ( (ageInDays(current.releaseDate)<100) )
as is compares a Date with a boolean?

I think that the constraint should just be
   eval( ageInDays(current.releaseDate) < 100 )

-W


On 20 June 2011 07:38, jarno niemelä <jargon at iki.fi> wrote:

> Hello.
>
> I am trying to set up guvnor environment for business users, and I am
> having a bit of trouble in getting functions to work.
>
> What I am trying to do is to make a function that would calculate age
> of product in days as comparison between release date and current
> date.
>
> I have following POJO:
>
> public class Product {
>
>        private String name;
>
>        private Date releaseDate;
>
>        public Date getReleaseDate() {
>                return releaseDate;
>        }
>
>        public void setReleaseDate(Date releaseDate) {
>                this.releaseDate = releaseDate;
>        }
> }
>
> My function:
>
> import java.util.Date;
> import java.util.Calendar;
>
> function int ageInDays(Date beginDate) {
>
> Date today = Calendar.getInstance().getTime();
> long age=today.getTime()-beginDate.getTime();
> return (int)((age/1000)/60/60/24);
> }
>
> My rule:
> 1.      |       rule "test2"
> 2.      |           dialect "mvel"
> 3.      |           when
> 4.      |               current : Product( supported != "supported" ,
> releaseDate
> <= ( (ageInDays(current.releaseDate)<100) ) )
> 5.      |           then
> 6.      |               current.setSupported( "supported" );
> 7.      |               update( current );
> 8.      |       end
>
> I am getting error when running test:
>
> Exception executing ReturnValue constraint
> org.drools.rule.ReturnValueRestriction at 4219ae2e :
> java.lang.IllegalArgumentException: Unable to convert class
> java.lang.Boolean to a Date.
>
> What I am doing wrong here?
>
> Alternative solution would be to create getAge() function in my POJO,
> but are POJOs supposed to have executable code or are they supposed to
> be used only for storing fact values?
>
> Jarno
> _______________________________________________
> 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/20110620/2f53e6de/attachment.html 


More information about the rules-users mailing list