Searching for an object in a list inside a map
by Steinmetz, Jean-Philippe
Hello,
I have a scenario where I have a rule that is searching for a particular
object inside a list and the list is an entry in a hashmap.
An example of the class structure looks something like this.
class Player {
String name;
}
class TeamRoster {
// Maps team name to players
Map<String, List<Player>> teams;
}
The goal of the rule is to activate when there is a player named John on
the Dodgers team. I have tried writing rules a couple of ways but end up
with errors using either approach. My first approach was the following:
dialect "mvel"
rule
when
$roster : TeamRoster()
$player : Player(name == "John") from $roster.teams["Dodgers"]
then
...
end
However this resulted in the following error:
Unable to Analyse Expression $roster.teams["Dodgers"]:
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast
to java.lang.Class]
So I tried changing it up with the following...
dialect "mvel"
rule
when
$roster : TeamRoster()
$player : Player(name == "John")
eval($roster.teams["Dodgers"] contains $player
then
...
end
This effectively yields the same error:
Expression $roster.teams["Dodgers"] contains $player:
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast
to java.lang.Class]
Note I am using Drools 6.0.1.Final. Is this some sort bug or limitation
with the rules parser? Assuming I cannot change the class structure how can
I achieve what I need?
Thanks in advance,
Jean-Philippe Steinmetz