[rules-users] Drools: Compound Value Restriction in Decision Table

David Smith mail at davesmith.me.uk
Fri Feb 4 18:47:30 EST 2011


Hi,
I managed to get something working for Compound Value Restrictions
using in using my own code, but I'd still rather not do it in code so
that it is easier for the business to write.

I added a function:
    function boolean isIn(String value, String values) {
        System.out.println("value:" + value + " values:" + values);
        String[] parts = values.split(",");
        List<String> partsList = new ArrayList();
        for(String part : parts) {
            partsList.add(part.trim());
        }
        return partsList.contains(value);
    }

then in the rule table script part i did an eval:

eval(isIn($risk.getCoverType(), "$param"))

The above worked for me but I'd rather write

covertype in

and not have to write a function and eval statement.

Thanks
David

On 5 February 2011 09:05, David Smith <mail at davesmith.me.uk> wrote:
>
> Hi,
> I am pocing/learning drools and I am trying to implements Compound Value Restrictions using 'In' in a decision table.
> I can do this in a rule like
> rule "CoverType Example"
> when
>     $risk : Data( coverType in ("A","B", "C", "D"))
> then
>     result.add("CoverType was one of A, B C or D");
> end
> I can also implement this in a decision table in a long winded fashion
> Condition, Action
> Data,        result
> coverType, add("$param")
> A,              CoverType was one of A, B C or D
> B,              CoverType was one of A, B C or D
> C,              CoverType was one of A, B C or D
> D,              CoverType was one of A, B C or D
> Is there a compact way to do this using a Compound Value Restriction using in?
> Something like:
> Condition, Action
> Data,        result
> coverType in, add("$param")
> "A,B,C,D",              CoverType was one of A, B C or D
> What goes in the script part "coverType in"?
> The number of items in the list can be variable, so don't want to write something that has $1, $2, $3, $4
> Thanks
> David




More information about the rules-users mailing list