Reputation: 86
I have implemented builder design pattern and I have conditions on the abstract class and want to update the fact that extends the abstract class. Although the rule is fired but it doesn't update the fact why?
DRL
rule "Rule_1"
when
$a : AnotherClas.Builder()
$b : AnotherClas(definitionName = "test") from $a.build
then
$b.setUpdateFact("updated");
end
JAVA CLASS
public abstract class TestClass{
public final String definitionName;
protected TestClass(String definitionName) {
this.definitionName = definitionName;
}
}
ANOTHER JAVA CLASS
public class AnotherClass extends TestClass{
private String updateFact;
private TestClass(String reviewDefinitionName) {
super(reviewDefinitionName);
}
public void setUpdateFact(String updateFact) {
this.updateFact= updateFact;
}
public void getUpdateFact() {
return updateFact;
}
public static class Builder {
private String definitionName;
public TestClass build() {
return new TestClass(definitionName);
}
public Builder definitionName(String definitionName) {
this.definitionName = definitionName;
return this;
}
}
}
Is there anything I am missing? please help me with the correct way to implement this
Upvotes: 1
Views: 343
Reputation: 2398
Your method AnotherClass.Builder.build()
is creating a new instance of an object which is not inserted into the Working Memory or a DataSource. That's the reason why call of modify
does not sort any effect.
First you bind $a
to a static Builder:
$a : AnotherClas.Builder()
then in the from $a.build
the method is invoked:
public ReviewBatchConfig build() {
return new ReviewBatchConfig(definitionName);
}
as the above implementation shows this is not inserted in the WM/DS so missing the API requirements.
You could maybe consider using the builder pattern in the code before invoking the rule engine API, once from the builder pattern all objects are known in your code, you insert those in the WM/DS and invoke rule engine rules.
Upvotes: 1