Reputation: 2038
I've got a simple object construction. The class ContextDroolsObject
has a property of type Map
called objects
. Inside that map there's a key "imageThemes"
with an ArrayList
and this rule here never matches:
import java.util.ArrayList;
import java.util.Map;
import com.my.ContextDroolsObject;
dialect 'java'
rule 'Soccer Image Theme'
salience 100
when
s : ContextDroolsObject()
objectsm : Map() from s.objects
imageThemesList : ArrayList() from outputsm.imageThemes
then
System.out.println("-----------------------soccer");
end
I've also tried with List() with same result.
¿How to match the list declaration?
Upvotes: 2
Views: 5151
Reputation: 267
Hi you can rewrite your rule in this way:
import java.util.ArrayList;
import java.util.Map;
import com.my.ContextDroolsObject;
dialect 'java'
rule 'Soccer Image Theme'
salience 100
when
s : ContextDroolsObject( imageThemesList : objects#Map.get("imageThemes") )
then
System.out.println("-----------------------soccer");
end
Upvotes: 2
Reputation: 31300
Using a hierarchical structure for fact objects is ver frequently a design flaw. You may not be able to reason conveniently over the list elements.
Anyway, this is the way to extract the list within the map from the ContextDroolsObject.
rule 'Soccer Image Theme'
salience 100
when
s: ContextDroolsObject()
imageThemesList: ArrayList() from s.getObjects().get( "imageThemes" )
then
System.out.println("-----------------------soccer");
end
Upvotes: 1