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

jarno niemelä jargon at iki.fi
Mon Jun 20 01:38:58 EDT 2011


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



More information about the rules-users mailing list