I am new to drools and have defined two rules :
package com.mgaudin.sandbox.drools.rules;
import com.mgaudin.sandbox.drools.models.Lead;
rule "rule1"
when
l: Object()
then
System.out.println(l.getClass().getCanonicalName());
end
And
package com.mgaudin.sandbox.drools.rules;
import com.mgaudin.sandbox.drools.models.Lead;
rule "rule2"
when
Lead()
then
System.out.println("It's a match !");
end
When I insert a new com.mgaudin.sandbox.drools.models.Lead fact, the output is the following :
com.mgaudin.sandbox.drools.models.Lead
Therefore we can deduce that :
The rules compiles properly
The rules are executed
The first rule matches with a fact of type "com.mgaudin.sandbox.drools.models.Lead"
So why is the rule "rule2" not matching ?
Thanks !
OK I found the answer and it's not related to Drools, it's related to Spring-boot-devtools !
I don't know the exact mechanism but to enable fast hot reload (even if a method signature changes), spring-boot-devtools must mess with the JVM and proxify some objects, in my case, the fact. Because of this and the way Drools matches fact, the rule did not triggered.
All I had to do was remove the maven dependency to spring-boot-devtools.
Rules are not matching since your fact (Lead) is loaded with different ClassLoader so Drools don't see it. This is done by devtools as described here:
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-spring-boot-restart-vs-reload
But it's not necessary to disable devtools, just add the following lines to META-INF/spring-devtools.properties as was hinted here:
restart.include.drools=/drools-[\\s\\S]+\.jar
restart.include.kie=/kie-[\\s\\S]+\.jar
So Drools is loaded with Restart Classloader - the same as your Classes.
I had a problem that inserted facts are never recognized inside rules, but had no problem with globals.
Removing
spring-boot-devtools
dependency made my life easier.
Related
I have now run out of ideas on how to get a RuleTable in Excel to define the #Watch annotation.
All the Drools documentation shows you how to define the #Watch with individual files, but no mention on how to add this to RuleTables.
My RuleTable is generating 100% at the moment and works fine for a primitive test case, but I need to have the #Watch on a more complex rule.
When I use the test compiler, I can edit the .drl files by hand and upload them to the engine. My rules are firing correctly then.
Some help on how to define this in Excel will be greatly appreciated.
This is the current Excel RuleTable I have defined:
This is the target .drl I'm aiming for(I have left out the other two rules generated):
rule "TestWatch One"
no-loop
when
$payCommResponseDTO: PaymentCommissionResponseDTO(commissionStructure == CommissionStructure.ADJUSTED) #Watch(commissionStructure)
then
System.out.println("watch one");
end
I am testing infinite loops using Modify keyword.
But it is not re triggering the rule.
Rule 1:
rule "Entitle for promotion"
when
$i: EmployeeFinancialFact(rating==Rating.ONE.getRating())
then
PromotionFact $promotion=new PromotionFact($i.getEmpID(),$i.getEmpName());
insert($promotion);
end
Rule 2:
rule "Print EmployeeFinancialFact name entitled for promotion"
when
$p: PromotionFact()
then
modify($p) {setSentForApproval(true);}
end
I am expecting RHS of rule 2 will re-trigger the rule 2 again but it is getting fired only once.
Can anyone please tell me the reason.
The first obvious question would be if you are sure your rules are indeed getting executed (sounds like a silly question, but it has solved many many issues here in SO).
Some other relevant questions are:
which version of Drools are you using?
Is PromotionFact a java class? or a defined declaration in your DRL?
Do you know if Property Reactive is enabled in your kbase? It used to be disabled in versions < 7, but since version 7 is enabled by default.
Hope it helps,
Disable property reactive in Kmodule.xml in Drools 7 by adding following lines:
<configuration>
<property key="drools.propertySpecific" value="ALLOWED"/>
</configuration>
I've read some documentation and downloaded samples but I still got a question.
In most sample, the GIN module uses something like :
bind(MainActivityMapper.class);
bind(VerticalMasterActivityMapper.class);
I don't understand what it does? If I remove it from the sample code, everything works perfectly.
Thanks for any answer.
Someone pointed me to the GUICE page : http://google-guice.googlecode.com/git/javadoc/com/google/inject/Binder.html
There is no reason for it to be different in Gin.
Here is what it says for this particular case :
This statement does essentially nothing; it "binds the
class to itself" and does not change Guice's default behavior. You may
still want to use this if you prefer your Module class to serve as an
explicit manifest for the services it provides. Also, in rare cases,
Guice may be unable to validate a binding at injector creation time
unless it is given explicitly.
Note: I'm not sure wether or not I should Accept my own answer, so I'll leave it as is.
I'm facing an issue where I have App1.ClassA Importing App2.ClassB which itself needs to import App2.ClassC in a property. App1 and App2 are 2 different xaps
App1.ClassA invokes ComponentInitializer.SatisfyImports(this) in its initializing code. However this chain of satisfying imports does not seem to cascade down across assemblies.
I cannot specify ComponentInitializer on ClassB, since it is exporting itself (and MEF throws an error).However, ClassC is not being imported into the property of ClassB without this invocation.
Is this the expected behaviour or am i seeing some other bug due to which ClassC is not getting loaded ?
I went through this post -http://forums.silverlight.net/forums/t/202811.aspx, but the difference may be that i am crossing over Xaps in my scenario
Thanks in advance
i am crossing over Xaps in my scenario
By default, ComponentInitializer will find only parts in the current XAP. You can override this default host configuration by calling CompositionHost.Initialize.
The chain of resolving imports was being respected even when crossing over xap boundries. I'm guessing that xap boundries are not even an issue for xap, as it works at assembly level and as long as the assembly is available, it will resolve all the imports in the dependency chain.
The mistake i made was not realizing that the imports are not resolved during class instantiation( so the resolved elements are not available in the constructor). I had to hook up for the IPartInitialized Notification, and take action when this event is raised.
I'm marking this as the correct answer not to boost standings but to guide anyone facing the same issue.
I have two workflow foundation (.NET 3.5 SP 1) application which compiles fine. It has two declarative rule conditions in it. Both are very simple, examples:
- !this.Shutdown
- this.Runtime == null
The project builds correctly without error or warning, however when I run the application it fails with the exception: error 1342: Activity 'whileNotShutdown' validation failed: Can not find the condition "Shutdown not requested".
In the other application I am using a more complex ruleset in policy which generates the following exception: error 1398: Activity 'Defaults' validation failed: Can not find the rule set "Rule Set1". Check if rule set is defined in the rules file.
I have tried removing the .rules file and recreating it by recreating the two rules and that did not help.
The question is: What is wrong that is causing this error?
Some things I have tried:
Placing the workflow rules in the larger workflow makes no difference to the issue.
The issue is effecting all workflows in the solution now (even those that used to work).
Using a code rule condition doesn't have the same problem - the issue is related to the rules file somehow.
Rebuilding workflow didn't help
Declarative workflow rules are not checked by the compiler so there is no help there. When you reference 'this' in rule it means the workflow. So your properties Shutdown and Runtime must be declared at the workflow level. I presume the Runtime refers to the WorkflowRuntime and that is kind of unusual, and not recommended, to have inside of your workflow so there may be a design issue here.
Eventually found the cause - it was caused by spaces in the class name, which causes the rules file to have spaces in it, which seems to cause the issue.
For example this will cause the error:
alt text http://img512.imageshack.us/img512/661/clipboard01wdu.png
However this will not:
alt text http://img140.imageshack.us/img140/9366/clipboard02t.png