[jboss-jira] [JBoss JIRA] (DROOLS-767) Reactive Property over immutable list
Jonathan MERCIER (JIRA)
issues at jboss.org
Wed Apr 22 09:28:33 EDT 2015
Jonathan MERCIER created DROOLS-767:
---------------------------------------
Summary: Reactive Property over immutable list
Key: DROOLS-767
URL: https://issues.jboss.org/browse/DROOLS-767
Project: Drools
Issue Type: Feature Request
Reporter: Jonathan MERCIER
Assignee: Mark Proctor
Priority: Minor
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:
{code:title=Concept.java|borderStyle=solid}
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);
}
}
{code}
And following rules
{code:title=rules.drl|borderStyle=solid}
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
{code}
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
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
More information about the jboss-jira
mailing list