Drools and Maps

user1182373 picture user1182373 · Feb 1, 2012 · Viewed 14.7k times · Source

I'm beginner in this framework and I'm trying to use a map instead of Java class.

My example looks like that:

Main method:

Map<String, Float> mapa = new HashMap<String, Float>();
mapa.put("Height", (float)1.73);
mapa.put("Weight", (float)79.0);
mapa.put("BMI", mapa.get("Weight") /
                (mapa.get("Height") * mapa.get("Height")));
ksession.insert(mapa);

rule.drl:

rule "Low BMI"
    when
        $map : (Map(values("BMI")) < 18.0)
    then 
        System.out.println("You have a low BMI");
end

I want to compare the value of BMI inside of rule precondition, if this condition is true, so I want to show the message below.

What's it wrong?

Answer

salaboy picture salaboy · Feb 1, 2012

You should write something like:

when
    $map: Map(this["BMI"] < 18)
then

It should work :)