Thanks for your reply. Yes, I believe I am implementing equals and hashCode property in the StatusProperty class:
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StatusProperty that = (StatusProperty) o;
if (!value.equals(that.value)) return false;
return true;
}
@Override
public int hashCode() {
int result = name.hashCode();
result ^= value.hashCode();
return result;
}
Yes, I am adding to the properties list before inserting the TrainingStatus object into the session.
Also, I tried changing from update to modify and it broke the rule. I'm using Drool 5.0.1, has that method been deprecated?
Thanks again for your help,
Mike
On Jan 24, 2010, at 6:36 AM, Edson Tirelli wrote:
The rule looks fine, so the problem is somewhere else:
* Are you properly implementing the equals()/hashcode() methods in the StatusProperty class? or are you checking for the exact same instance (in which case the defaul equals()/hashcode() would work)
* are you adding the properties to the TrainingStatus.properties collection before inserting TrainingStatus into the session? or are you calling update/modify after inserting it?
Also, not related to the problem at all, but we recommend you to use modify() instead of update() in your rules consequence:
modify( t ) {
setNextSection( "section_b" ),
setPreviousSection( "section_overview" )
}
[]s
Edson
2010/1/24 Mike Dougherty
<mjdougherty@gmail.com>
Hello all,
I've been getting more and more into using Drools Expert, but I certainly still have a lot to learn. I have almost a complete rules file ready to go. But I am having an issue with the LHS checking that a collection contains a certain object value. The rule currently looks like this:
rule "Rule Name"
no-loop true
when
property : StatusProperty( name == "propertyName", value == "valueA" )
t : TrainingStatus( currentSection == "section_a", properties contains property )
then
t.setNextSection( "section_b" );
t.setPreviousSection( "section_overview" );
update( t );
end
The TrainingStatus object has the following fields:
public class TrainingStatus implements Serializable {
private String currentSection;
private String nextSection;
private String previousSection;
private Set<StatusProperty> properties = new TreeSet<StatusProperty>();
}
And the StatusProperty object has the following:
public class StatusProperty implements Serializable {
private String name;
private String value;
}
I'm inserting a TrainingStatus object that should match this rule. But the resulting object does not have the nextSection and previousSection fields set to the values they should.
Can anyone advise on how to get this rule working as expected?
Thanks for your help!
Mike
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users