Adding to this so maybe someone can help. Below is the drl and my test code. Based on the code and the facts, I expect rule 11 then rule 10 to fire. However rule 11 fires and rule 10 is never fired. If you set the object mm to have a value of A in the java code then rule 10 will fire.
DRL File:
rule "RULES_10"
when
prod : Product(sku != "1")
$txt1 : TextOption(sku == "mm", value == "A")
then
prod.setOptionEnabled( "to2", false, "Not available rule 10" );
end
rule "RULES_11"
no-loop true
when
prod : Product(sku != "1")
$opt1 : TextChoiceOption(sku == "mt")
exists (OptionValue(optionValueValue in ("val1")) from $opt1.value)
$txt1 : TextOption(sku == "mm")
then
$txt1.setValue("A"); update($txt1);
end
Java Code:
Product p = new Product();
p.setSku("mysku");
TextChoiceOption mt = new TextChoiceOption();
mt.setSku("mt");
mt.setName("mt");
mt.setEnabled(true);
OptionValue ov1 = new OptionValue();
ov1.setSku("val1");
ov1.setValue("val1");
ov1.setName("val1");
ov1.setEnabled(true);
mt.setValue(ov1);
p.addOption(mt);
TextChoiceOption to2 = new TextChoiceOption();
to2.setSku("to2");
to2.setName("to2");
to2.setEnabled(true);
p.addOption(to2);
TextOption mm = new TextOption();
mm.setSku("mm");
mm.setName("mm");
mm.setEnabled(true);
p.addOption(mm);
try {
KieContainer kieContainer = null;
System.setProperty("kie.maven.settings.custom", "<PATH_TO_MY_SETTINGS_FILE>");
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("<GROUP>", "<ARTIFACT>", "<VERSION>");
KieBaseConfiguration conf = ks.newKieBaseConfiguration();
conf.setOption(SequentialOption.NO);
conf.setOption(SequentialAgendaOption.DYNAMIC);
kieContainer = ks.newKieContainer(releaseId);
KieBase base = kieContainer.newKieBase(conf);
KieSessionConfiguration sessionconf = ks.newKieSessionConfiguration();
KieSession session1 = base.newKieSession();
session1.addEventListener( new DefaultAgendaEventListener() {
@Override
public void afterMatchFired(AfterMatchFiredEvent event) {
super.afterMatchFired(event);
System.out.println("Rule fired: " + event.getMatch().getRule().getName());
}
});
System.out.println("Object Defined as: " + p.getInternalConfiguredDescription());
System.out.println("Object State: " + p.getProductOptionState());
List<FactHandle> facts = new ArrayList<FactHandle>();
facts.add(session1.insert(p));
for (Option o : p.getAllOptions(false)) {
facts.add(session1.insert(o));
}
session1.fireAllRules();
System.out.println("Object Defined as: " + p.getInternalConfiguredDescription());
System.out.println("Object State: " + p.getProductOptionState());
session1.dispose();
} catch (Exception e) {
System.out.println("EXCEPTION: " + e.getMessage());
}