Rule does not fire after 'Modify/Update' of a fact - Drools 5.1.1 !
by groovenarula
Hello all,
For some reason I have a rule that does not fire after a Modify/Update.
I have 2 facts - Product and Option. The relationship between them is that a
'Product' can have 0 - N 'Option'(s).
Based on that, I added a 'product' field to the 'Option' object. I'm
creating and inserting my facts
using the following code :
Product prod = new Product ("001","002", "A");
prod.setPrice(new BigDecimal("300.00"));
Option opt = new Option ("H1","",prod);
ksession.insert(prod);
ksession.insert(opt);
Now in my .DLR, I have the following rule :
rule "Set Options price"
salience 50
when
$prod : Product ( price != null )
$option : Option ( product == $prod )
then
System.out.println( "Getting Options " + $prod );
end
This gives me the correct output in the console :
Getting Options Product [category=001, grade=A, price=300.00, style=002]
The rule fired successfully.
I start running into problems when I try to update the 'price' field using a
rule, instead of through code.
So for example, if I have the following rule also defined in the same drl
file :
rule "Set price"
salience 500
when
$prod : Product ( category == "001", price == null )
then
$prod.setPrice ( new BigDecimal ( "300.00" ) );
update( $prod );
System.out.println( $prod );
end
And then change my code as follows (remove the setPrice call) :
Product prod = new Product ("001","002", "A");
Option opt = new Option ("H1","",prod);
ksession.insert(prod);
ksession.insert(opt);
I only get the following output :
Product [category=001, grade=A, price=300.00, style=002]
What am I missing here ? I thought the rule 'Set Price' should update the
product fact with
the new price and the rules would get re-evaluated. After the re-evaluation,
the LHS of 'Set Options Price' should now be true and it should have fired.
But it does not.
Am I mis-understanding something about activation here ? If I am, can
someone please help explain what the gap is and how to re-write the rules so
that I can achieve the above objective ?
Any help will be appreciated. I've spend several hours trying different
permutations and combinations and got no where.
Thanks
Gurvinder
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Rule-does-not-fire-af...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 8 months
Map Accessor not allowing using a $parameter, gets field extractor error
by AberAber
Using Drools 5.1.1
Is there anything I can do except to make a method/property in my original
class to do the .get into map for me? According to drools specs this should
work.
This gets the error:
rule "Find Lowest Score"
salience 100
when
$aobject : DataObject($index: extracted.indexString)
$node : Information($classScore : adjustedScores[$index])
then
System.out.println(" Class score " + $classScore);
end
Description Resource Path Location Type
BuildError: Unable to create Field Extractor for 'adjustedScores[$index]'
droolsLocal.drl /src/main/resources line 30 Drools Error
This works:
rule "Find Lowest Score"
salience 100
when
$aobject : DataObject($index: extracted.indexString)
$node : Information($classScore : adjustedScores["ASTRING"])
then
System.out.println(" Class score " + $classScore);
end
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Map-Accessor-not-allo...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 8 months
Speed up inserting of rules into knowledge base
by Piotr Jedrychowski
Hello.
I'm loading a big amount of rules during starting of JBoss (20000
rules). All rules (in string format) are available before JBoss startup
- they are stored into database. Rules are loaded one by one and it
takes about 90 minutes. I want to speed up this process. Is there
something like "bulk load" for inserting rules into knowledge base or
another smart way to fast loading a big amount of rules?
I'm using:
1) Drools 5.1
2) JBoss 4.2.3
My source code looks like this:
String rule = ...
Resource resource = ResourceFactory.newReaderResource(new
StringReader(rule));
KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
knowledgeBuilder.add(resource, ResourceType.DRL);
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
Regards,
Piotr
13 years, 8 months
Spring + Drools + Console Application
by Anderson Neves
Hi everybody.
I am having a problem to instantiate a console application with Drools and
Sping. With Spring, I am able to instanciate a bean and print its value to
console, but with Spring + Drools I get this error:
Exception in thread "main"
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'kbase': Invocation of init method failed; nested exception is
java.lang.RuntimeException: Unable to parser Reader
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.test.Test.main(Test.java:10)
Caused by: java.lang.RuntimeException: Unable to parser Reader
at org.drools.compiler.DrlParser.getParser(DrlParser.java:313)
at org.drools.compiler.DrlParser.parse(DrlParser.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:147)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:263)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:458)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:519)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
at
org.drools.container.spring.beans.KnowledgeBaseBeanFactory.afterPropertiesSet(KnowledgeBaseBeanFactory.java:103)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 15 more
Caused by: java.lang.NullPointerException
at java.io.FilterInputStream.close(Unknown Source)
at
sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream.close(Unknown
Source)
at sun.nio.cs.StreamDecoder.implClose(Unknown Source)
at sun.nio.cs.StreamDecoder.close(Unknown Source)
at java.io.InputStreamReader.close(Unknown Source)
at
org.antlr.runtime.ANTLRReaderStream.load(ANTLRReaderStream.java:92)
at
org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:68)
at
org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:52)
at
org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:48)
at
org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:40)
at org.drools.compiler.DrlParser.getParser(DrlParser.java:308)
... 24 more
I use eclipse, and running from the IDE Spring + Drools in a console
application works fine. This problem happens when I generate an executable
jar and try the "java -jar" command.
My main method is below
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("appConfig.xml");
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession)
context.getBean("ksession");
System.out.println(ksession);
}
And my applicationContext.xml is below
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:drools="http://drools.org/schema/drools-spring"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://drools.org/schema/drools-spring
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-containe...
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<drools:kbase id="kbase">
<drools:resources>
<drools:resource source="classpath:knowledgebase-config.xml"
type="CHANGE_SET" />
</drools:resources>
</drools:kbase>
<drools:ksession id="ksession" type="stateful" kbase="kbase" />
</beans>
Any clue of what is cousing the problem? Thank you very much.
Regards,
Anderson
13 years, 8 months
Import repository in Guvnor
by Sébastien Raickman
Hi guys,
do someone have an example how to call the "org.drools.guvnor.Guvnor/backup"
(RepositoryBackupServlet) servlet for uploading a repository_export.xml?
Thanks in advance!
Seb
13 years, 8 months
Rule architecture question - avoiding condition duplications
by Hezi Stern
Hi all,
I have a general question regarding best practice or perhaps better put as
right architecture design.
We are using Drools (Expert in particularly) to model and execute the
behavior aspects of our service, which revolves around meeting scheduling
between various users.
My main challenge is how to properly structure the rules so that they
provide the desired flexibility to both modify and control over time.
Following is a small example which illustrates my question:
I need to determine a specific execution time and it is based on many
conditions and in general about 15 scenarios where I create a rule per
scenario. I find that there is a wide set of conditions that are common to
all scenarios.
So for example a rule would look like:
when
a1 == X1
a2 == X2
a3 == X3
a4 == X4
b1 == Y1
Then
Something .
Another rule would be
when
a1 == X1
a2 == X2
a3 == X3
a4 == X4
b2 == Y2
Then
Something else .
As you can see I am duplicating the a' conditions which are the common
conditions and the b' is a new unique condition. It seems to me like a
poorer code maintainability and possibly performance reduction (but I may be
wrong, perhaps this is how rules should be written).
I assume this is a common case in rules so my question is what would be the
best way (architecturally wise) to implement such cases (e.g. insert a new
class that indicates that conditions a' are set and base the rules on the
existence of such a class)
Thanks
Hezi
13 years, 8 months
subscription
by Qi Zhao
subscription
-------------------------------------------
Qi Zhao
Sent to My MacBook Pro's Mail
13 years, 8 months
New in Drools, java.lang.NullPointerException at org.drools.reteoo.AccumulateNode.getFirstMatch(AccumulateNode.java:967)
by Manuel Ortiz
Hello all!
I am new in Drools but day by day, test by test, I think I get a bit more
knowledge of how the rule engine works from user point of view. I've been
adding rules to an alarm system, increasing the complexity and functionality
in several steps. Unfortunately in the last step I found the following
NullPointerException inside the rule engine...
java.lang.NullPointerException
at org.drools.reteoo.AccumulateNode.getFirstMatch(AccumulateNode.java:967)
at org.drools.reteoo.AccumulateNode.modifyLeftTuple(AccumulateNode.java:329)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:239)
at
org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode.java:640)
at org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:270)
at org.drools.reteoo.BetaNode.modifyObject(BetaNode.java:312)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:460)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:428)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:160)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:460)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:428)
at org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:263)
at org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:172)
at
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1442)
at
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1349)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:183)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:196)
at
es.simcasva.alarmas.rules.Rule_Test_Negativo_Alarma_Acceso_Portal_Ubicacion_UM_0.defaultConsequence(Rule_Test_Negativo_Alarma_Acceso_Portal_Ubicacion_UM_0.java:18)
at
es.simcasva.alarmas.rules.Rule_Test_Negativo_Alarma_Acceso_Portal_Ubicacion_UM_0DefaultConsequenceInvoker.evaluate(Rule_Test_Negativo_Alarma_Acceso_Portal_Ubicacion_UM_0DefaultConsequenceInvoker.java:44)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:917)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:856)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1071)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:785)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:751)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
I've been trying to find the problem, and found a strange interaction
between three rules that makes the null pointer to appear. The alarm system
has many rules now and it is difficult to simplify the scenario, so I just
would like to know what is the funcion of AccumulateNode object in order to
have an idea of the NullPointerException possible cause.
Can anyone help me?
Thank you in advance for your time.
Regards,
Manuel Ortiz.
13 years, 8 months