"factorize" rules
by John Dujon
Hello,
I am trying to make my rules more readable and wonder wether or not we can
factorize rules for a particular ruleflow-group. As an example, I would
like to convert this:
// begin rules
rule "Rule 1"
ruleflow-group "work"
when
condition 0
condition1
then
doSomething();
rule "Rule 2"
ruleflow-group "work"
when
condition0
condition2
then
doSomethingElse();
// end rules
to the following
// begin rules
pre_conditions_for_rules
ruleflow-group "work"
condition0
rule "Rule 1"
ruleflow-group "work"
when
condition1
then
doSomething();
end
rule "Rule 2"
ruleflow-group "work"
when
condition2
then
doSomethingElse();
end
// end rules
Thank you for your time. I apologize in advance if that does not make
sense, as I am new to drools
John
13 years, 10 months
Deserialzation Error running test example
by richard
I get this error running either with Netbeans or Eclispe.
I downloaded source from github.
Lastest Guvnor too.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.
java.lang.RuntimeException: KnowledgeAgent exception while trying to
deserialize KnowledgeDefinitionsPackage
at
org.drools.agent.impl.KnowledgeAgentImpl.createPackageFromResource(KnowledgeAgentImpl.java:787)
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1094)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:835)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:675)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:206)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:185)
at
org.drools.guvnor.examples.mortgage.client.MortgageClientExample.readKnowledgeBase(MortgageClientExample.java:92)
at
org.drools.guvnor.examples.mortgage.client.MortgageClientExample.main(MortgageClientExample.java:49)
at
org.drools.guvnor.examples.GuvnorExamplesApp$1.actionPerformed(GuvnorExamplesApp.java:50)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.FileNotFoundException:
http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/packages/mor...
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source)
at org.drools.io.impl.UrlResource.grabStream(UrlResource.java:210)
at org.drools.io.impl.UrlResource.getInputStream(UrlResource.java:146)
at
org.drools.agent.impl.KnowledgeAgentImpl.createPackageFromResource(KnowledgeAgentImpl.java:750)
... 44 more
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.AbstractCollection.addAll(Unknown Source)
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1100)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:835)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:675)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:206)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:185)
at
org.drools.guvnor.examples.mortgage.client.MortgageClientExample.readKnowledgeBase(MortgageClientExample.java:92)
at
org.drools.guvnor.examples.mortgage.client.MortgageClientExample.main(MortgageClientExample.java:49)
at
org.drools.guvnor.examples.GuvnorExamplesApp$1.actionPerformed(GuvnorExamplesApp.java:50)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
--
View this message in context: http://drools.46999.n3.nabble.com/Deserialzation-Error-running-test-examp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Which proper way to test for Event expiration in Drools Fusion?
by tari-manga
Ciao, I've used successfully Drools Expert in past project, now I'm
experimenting with Drools Fusion but I can't seem to grasp correctly how
Event expiration works.
I do understand from the documentation: you must have the knowledge base
setup as STREAM, that you must inject Events in chronological order, and
then for the engine to correctly compute the expiration correctly you must
have defined temporal constraints between Events in the LHS of the rules.
Now let's suppose that for a specific Event there is only 1 rule, and this 1
rule picks the Event from a window of length 1, I would have assumed the
engine would automatically expire all the past Events, with the exception of
not expiring only the last one inserted?
For example:
I have some simple coding by having modified the "Hello World" code
generated by Drools IDE, I have 5.4.0.Final, and documented fully in a
http://stackoverflow.com/questions/12338385/test-event-expiration-in-droo...
StackOverflow question . The Message is declared as Event, I inject 2 of
them and even if I advance the pseudo clock to the far future, neither of
the Message Event by inspecting the EventHandle seems to be expired==true?
I was expecting the EventHandle for the very first Message Event inserted,
to have expired==true but that is not the case, all the EventHandle have
expired==false and I'm seriously puzzled why?
I was wondering if somebody have a simple example to share where he was
successfully able to inspect all the EventHandle for expiration, or if
anybody can see what I'm doing wrong, please?
Thank you very much in advance.
--
View this message in context: http://drools.46999.n3.nabble.com/Which-proper-way-to-test-for-Event-expi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Capturing DDLs from Guvnor
by dme1
Hi,
I have configured Guvnor to work with Oracle. With this configuration I can
see that Guvnor uses my Oracle Database as the datastore, and creates the
necessary tables in the Oracle database. I want to capture the Oracle "DDLs"
that Guvnor (Jackrabbit) builds to create the table in the Oracle Database,
this is required to facilitate application and installs in different
environments in the organization.
I can go to the database and create the DDLs from there, but am wondering if
there is an easier way to achieve the same.
Thanks,
dme
--
View this message in context: http://drools.46999.n3.nabble.com/Capturing-DDLs-from-Guvnor-tp4019855.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Issue serializing KnowledgePackage with hibernate
by gqmulligan
I am using drools 5.3.1.
I have a case where I need to recompile and update many knowledge packages
within a single hibernate session. The problem I am facing is that with
each subsequent select I do to get the next knowledge package, an extra
update is done for every knowledge package updated so far.
I dug into the code and think I found the issue. Hibernate returns a new
knowledge package that it puts in its cache after updating. When hibernate
later does a check to see if this object has changed since it was last saved
it always thinks there was a change for the following reasons:
1.) The knowledge package does not reference the same object.
2.) The internal package is not the same reference (it does an identity
check in the equals method of the KnowledgePackageImpl)
3.) The serialized bytes are compared and are for some reason different even
though no changes were made to the knowledge package.
Somehow it seems I need to get hibernate to know that the knowledge package
did not change since the last update. Is there an easy way to do this? It
seems like number 2 or 3 from above should work but fail for the reasons
given.
Otherwise the only workaround I can think of would be too load all knowledge
packages that will need to be updated first, recompile them all, and then
update them all at once. This is not the simplest thing to do with the way
things currently work so it would be great if hibernate could handle this
for me.
Thanks.
--
View this message in context: http://drools.46999.n3.nabble.com/Issue-serializing-KnowledgePackage-with...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
rules file character encoding and spring
by Joachim Van der Auwera
I have a rules description like this:
<drools:kbase id="bodKBase">
<drools:resources>
<drools:resource type="DRL"
source="classpath:be/vlaanderen/awv/dc/bod/rule/Dienstbevel.drl"/>
<drools:resource type="DRL"
source="classpath:be/vlaanderen/awv/dc/bod/rule/Kostenberekening.drl"/>
</drools:resources>
</drools:kbase>
How can I specify the character encoding for this?
It is working fine on linux (everything is UTF-8), but gives a problem on
Windows machine where it complains about the character set.
Thanks for the help.
Kind regards,
Joachim
13 years, 10 months
problem when upgrading to 5.4.0.Final, got UnsupportedOperationException on an update call
by Michal Bali
Hi all,
I am upgrading an application from 5.3.0.Final to 5.4.0.Final and I am
getting the following exception:
Exception executing consequence for rule "ruleThatFails" in
indexingproblem.remove.me.anditworks:
java.lang.UnsupportedOperationException
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1212)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1446)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at com.mycompany.app.IndexingProblemMain.main(IndexingProblemMain.java:36)
Caused by: java.lang.UnsupportedOperationException
at org.drools.reteoo.BaseLeftTuple.getPrevious(BaseLeftTuple.java:480)
at org.drools.core.util.index.LeftTupleList.remove(LeftTupleList.java:114)
at org.drools.core.util.index.LeftTupleList.removeAdd(LeftTupleList.java:68)
at org.drools.reteoo.JoinNode.modifyLeftTuple(JoinNode.java:310)
at
org.drools.reteoo.LeftTupleSource.doModifyLeftTuple(LeftTupleSource.java:304)
at
org.drools.reteoo.LeftTupleSource.modifyLeftTuple(LeftTupleSource.java:278)
at org.drools.reteoo.JoinNode.modifyLeftTuple(JoinNode.java:437)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateModifyLeftTuple(SingleLeftTupleSinkAdapter.java:205)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyObject(SingleLeftTupleSinkAdapter.java:235)
at
org.drools.reteoo.LeftInputAdapterNode.modifyObject(LeftInputAdapterNode.java:170)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:421)
at org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:383)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:337)
at
indexingproblem.remove.me.anditworks.Rule_ruleThatFails_b159773c7b1a41a2a93044d2816b96ca.defaultConsequence(Rule_ruleThatFails_b159773c7b1a41a2a93044d2816b96ca.java:9)
at
indexingproblem.remove.me.anditworks.Rule_ruleThatFails_b159773c7b1a41a2a93044d2816b96caDefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
indexingproblem.remove.me.anditworks.Rule_ruleThatFails_b159773c7b1a41a2a93044d2816b96caDefaultConsequenceInvoker.evaluate(Unknown
Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1277)
... 6 more
I have tried to create a minimal test case that recreates this issue, here
it is:
package indexingproblem.remove.me.anditworks;
declare Criteria
processed : boolean
end
declare CheeseCriteria extends Criteria
end
rule setUp
salience 10000
when
then
insert(new CheeseCriteria());
end
rule aaa
when
CheeseCriteria( )
then
end
rule bbb
when
CheeseCriteria( )
then
end
rule ccc
when
CheeseCriteria( )
then
end
rule eeeFalse
when
Criteria( processed == false )
then
end
declare Filter
end
rule fffTrue
when
Criteria( processed == true )
Filter( )
then
end
rule ruleThatFails
when
$criteria : Criteria( processed == false )
then
modify($criteria) {
setProcessed(true)
}
end
I've tried to run it on 5.5.0-SNAPSHOT, but I got the same result. Note
that if you change the rule package to be "package indexingproblem" the
exception is not thrown. The code for building the KnowledgeBase is
standard, I haven't used any additional options. No fact is inserted only
one fireAllRules call.
Please let me know if I should create a new JIRA ticket for this or if I am
doing something wrong.
Thanking you in advance.
Best regards,
Michal
13 years, 10 months
Issue with From Clause - Class Cast Error
by tosmun
Hi All,
I am having a very strange issue with my knowledge base... I have the
following Rule:
...
rule "root_host"
no-loop true
ruleflow-group 'initialize-appliance-definitions'
when
$app:ApplianceType
(
type == ApplianceTypeIdentifier.APPLIANCE_ROOT
);
not( ApplianceTypeObject() from $app.getObjectTypes());
then
//Do something
end;
...
And the ApplianceType class is defined as:
...
public class ApplianceType
{
private ApplianceTypeIdentifier type;
private List<ApplianceTypeObject> objectTypes;
public ApplianceType(ApplianceTypeIdentifier type,
List<ApplianceTypeObject> initialObjectTypes)
{
this.type = type;
if(initialObjectTypes == null)
this.objectTypes = new ArrayList<ApplianceTypeObject>();
else
this.objectTypes = initialObjectTypes;
}
public ApplianceType(ApplianceTypeIdentifier type)
{
this(type, null);
}
public ApplianceTypeIdentifier getType()
{
return type;
}
public List<ApplianceTypeObject> getObjectTypes() {
return objectTypes;
}
}
When attempting to fireAllRules() I receive the following error:
...
Caused by: java.lang.ClassCastException: org.drools.reteoo.FromNode
incompatible with org.drools.reteoo.BetaNode
at org.drools.reteoo.ReteooBuilder.resetMasks(ReteooBuilder.java:303)
at org.drools.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:267)
at org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java:459)
at
org.drools.common.AbstractRuleBase.removeRule(AbstractRuleBase.java:1107)
at
org.drools.common.AbstractRuleBase.mergePackage(AbstractRuleBase.java:851)
at
org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:610)
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)
at
org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:150)
at
com.q1labs.frameworks.drools.DroolsEngine.getKnowledgeBase(DroolsEngine.java:139)
at com.q1labs.frameworks.drools.DroolsEngine.onInit(DroolsEngine.java:50)
at
com.q1labs.frameworks.naming.FrameworksNaming.initializeNewComponent(FrameworksNaming.java:951)
... 3 more
Any thoughts? I have been using from clauses just like this throughout my
project, and have had no issues with it to this point (even those which did
not use generics).
--
View this message in context: http://drools.46999.n3.nabble.com/Issue-with-From-Clause-Class-Cast-Error...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months