Details
-
Feature Request
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
None
-
None
Description
When an object has an immutable list of mutable object using setter on this list is useless. But in such case with only the getter the corresponding attributes are not seen as an attributes.
see the code below:
Concept.java
package fr.cea.ig.drools; import org.kie.api.definition.type.PropertyReactive; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.List; @PropertyReactive public class Concept { private final String name; private final List<Concept> concepts; private int value; @NotNull public String getName() { return name; } @NotNull public List<Concept> getConcepts() { return concepts; } public void setConcepts(@NotNull List<Concept> c) { throw new UnsupportedOperationException(); } public int getValue() { return value; } public void setValue(int value) { this.value = value; } public Concept(final String name, final List<Concept> concepts) { this.name = name; this.concepts = (concepts == null)? new ArrayList<Concept>() : concepts ; value = 0; } @Override public String toString(){ return String.format("NAME(%s) VALUE(%d)", name, value); } }
And following rules
rules.drl
package fr.cea.ig.drools; import fr.cea.ig.drools.Concept; import java.util.List; dialect "mvel" rule "All child concept has a value greater to 0" when $c : Concept( value == 0 ) @watch( concepts ) $cl : List(size > 0) from collect( Concept( $c memberOf concepts) ) forall( Concept( value > 0 ) from $cl ) then modify($c){ value = 1 } end rule "Concept c1" when $c : Concept( name == "c1", value == 0 ) then modify($c){ value = 2 } end rule "Concept c2" when $c : Concept( name == "c2", value == 0 ) then modify($c){ value = 3 } end
if the setter setConcepts is removed this error is raised:
Unknown property concepts in @Watch annotation : [Rule name='All child concept has a value greater to 0']
In my model I use interface instead of class to spread a generic vocabulary through various data type. Put a setter which should throw an Exception will confusing some people.
Regards