Re: [rules-users] Object Referencing Error
by Fnu Mahalakshmi
Hi,
I tried what you said but program goes into an infinite loop.
It does not break out of the when loop only.
I did exactly as you mentioned.
In the test information I put in a.type = "Prod"
And a.bObject(new B());
Any idea whats wrong??
Thanks,
M
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of rules-users-request(a)lists.jboss.org
Sent: Thursday, June 03, 2010 4:52 PM
To: rules-users(a)lists.jboss.org
Subject: rules-users Digest, Vol 43, Issue 15
Send rules-users mailing list submissions to
rules-users(a)lists.jboss.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.jboss.org/mailman/listinfo/rules-users
or, via email, send a message with subject or body 'help' to
rules-users-request(a)lists.jboss.org
You can reach the person managing the list at
rules-users-owner(a)lists.jboss.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of rules-users digest..."
Today's Topics:
1. Re: Object Referencing error: (Esteban Aliverti)
----------------------------------------------------------------------
Message: 1
Date: Thu, 3 Jun 2010 17:51:10 -0300
From: Esteban Aliverti <esteban.aliverti(a)gmail.com>
Subject: Re: [rules-users] Object Referencing error:
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID:
<AANLkTimeZIJ5VfMTBESLFJIWoc_4MEZSXbKMIXAvJRiC(a)mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
You can't modify bobject, becuase it doesn't exist inside the session. You
just created it a few lines above. Maybe you need an insert() or maybe you
need the bobject reference from the LHS. Something like this:
*rule* "prod"
*when*
$a :A(Type == "Prod" , objectB != "")
*then*
B bobject = *new* B();
$a.getObjectB().setType( "Prod" );
$a.getObjectB().setId($a.getNumber().getId());
*update*($a);
* end*
Note that you need to update $a and not B, because A is the inserted Fact in
your session.
Best,
2010/6/3 Fnu Mahalakshmi <FMahalakshmi(a)nyx.com>
> Hi,
>
>
>
> I am getting the following error when I try to do complex object
> referencing in drools:
>
> My class:
>
> A{
>
> String Type;
>
> B objectb;
>
> //getters and setters for above
>
> }
>
>
>
> My rules:
>
>
>
> *rule* "prod"
>
>
>
> *when*
>
> $a :A(Type == "Prod" , objectB != "")
>
> *then*
>
> B bobject = *new* B();
>
> bobject.setType( "Prod" );
>
> bobject.setId($a.getNumber().getId());
>
> *update*(bobject);
>
>
>
> *end*
>
> * *
>
> *I want to basically output a file which has updated values of B (type,
> Id)
>
> *
>
> * *
>
> *Error:*
>
> *org.drools.spi.ConsequenceException*: *org.drools.FactException*: Update
> error: handle not found for object: com.org.Ip@f42ad0. Is it in the
> working memory?
>
> at
> org.drools.base.DefaultConsequenceExceptionHandler.handleException(*
> DefaultConsequenceExceptionHandler.java:13*)
>
> at org.drools.common.DefaultAgenda.fireActivation(*
> DefaultAgenda.java:558*)
>
> at org.drools.common.DefaultAgenda.fireNextItem(*
> DefaultAgenda.java:518*)
>
> at org.drools.common.AbstractWorkingMemory.fireAllRules(*
> AbstractWorkingMemory.java:475*)
>
> at org.drools.common.AbstractWorkingMemory.fireAllRules(*
> AbstractWorkingMemory.java:439*)
>
> at com.org.DroolsTest.main(*DroolsTest.java:30*)
>
> Caused by: *org.drools.FactException*: Update error: handle not found for
> object: com.org.Ip@f42ad0. Is it in the working memory?
>
> at org.drools.base.DefaultKnowledgeHelper.update(*
> DefaultKnowledgeHelper.java:100*)
>
> at com.org.Rule_Prod_Ip_0.consequence(*Rule_Prod_Ip_0.java:10*)
>
> at com.org.Rule_Prod_Ip_0ConsequenceInvoker.evaluate(*
> Rule_Prod_Ip_0ConsequenceInvoker.java:22*)
>
> at org.drools.common.DefaultAgenda.fireActivation(*
> DefaultAgenda.java:554*)
>
> ... 4 more
>
>
>
> Please help! I am very new to drools! Not able to figure out why this
> error:
>
>
>
> I am using eclipse and working on Windows machine. Error above was
> generated on eclipse console.
>
>
>
> Thank you.
>
>
>
> M
>
> ------------------------------
>
> *Please consider the environment before printing this email.*
>
> *Visit our website at http://www.nyse.com
> *****************************************************************************
>
> Note: The information contained in this message and any attachment to it is
> privileged, confidential and protected from disclosure. If the reader of
> this message is not the intended recipient, or an employee or agent
> responsible for delivering this message to the intended recipient, you are
> hereby notified that any dissemination, distribution or copying of this
> communication is strictly prohibited. If you have received this
> communication in error, please notify the sender immediately by replying to
> the message, and please delete it from your system. Thank you. NYSE
> Euronext. *
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
14 years, 5 months
Using the ForEach component in RuleFlow
by Darshan
I am trying to use ForEach component in the process flow. I need to call a
set of rules in loop. I have this subFlow created inside ForEach component.
The collection set in the working memory becomes available to the ForEach
component and infact even in subFlow the OnEntryAction and OnExitAction can
access the integerObject from the collection. But when it comes to executing
the rules, looks like the integerObject is not available to the rule and
none of the rules are executed. If I add a dummy rule without any condition
it does get executed but only once. Have anybody tried similar kind of
scenario. If yes please send me some example, as I am really stuch out here
trying to call rules in a loop.
I am attaching the souce code along with this post. Please have a look.
Here is how the ForEach flow looks like
http://drools-java-rules-engine.46999.n3.nabble.com/file/n870012/ForEachF...
Here is my SubFlow layout
http://drools-java-rules-engine.46999.n3.nabble.com/file/n870012/subProce...
Here is the output of Java Program
Setting numberList
Entry 1
Entry 2
Exit 1
Entry 3
Exit 2
Entry 4
Exit 3
Entry 5
Exit 4
Entry 6
Exit 5
Entry 7
Exit 6
Entry 8
Exit 7
Entry 9
Exit 8
Entry 10
Exit 9
Entry 11
Exit 10
Entry 12
Exit 11
Entry 13
Exit 12
Entry 14
Exit 13
Entry 15
Exit 14
Entry 16
Exit 15
Entry 17
Exit 16
Entry 18
Exit 17
Entry 19
Exit 18
Exit 19
Rules executed
testSubFlowForEach.rf looks like this
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process
drools-processes-5.0.xsd"
type="RuleFlow" name="testForEach" id="processForEach"
package-name="com.sample" >
<header>
<imports>
<import name="java.util.ArrayList" />
<import name="com.sample.IntegerObject" />
</imports>
<variables>
<variable name="numberList" >
<type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="java.util.ArrayList" />
</variable>
<variable name="integerObject" >
<type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="com.sample.IntegerObject" />
</variable>
</variables>
</header>
<nodes>
<start id="1" name="Start" x="224" y="15" width="80" height="40" />
<forEach id="2" name="processForEach" x="163" y="111" width="203"
height="268" variableName="integerObject" collectionExpression="numberList"
>
<nodes>
<subProcess id="13" name="SubProcess" x="55" y="110" width="80"
height="40" processId="testSubFlow" independent="false" >
<mapping type="in" from="integerObject" to="integerObject" />
<onEntry>
<action type="expression" dialect="java" >System.out.println("Entry
" + ((IntegerObject) integerObject).getIntVal());</action>
</onEntry>
<onExit>
<action type="expression" dialect="java" >System.out.println("Exit "
+ ((IntegerObject) integerObject).getIntVal());</action>
</onExit>
</subProcess>
</nodes>
<connections>
</connections>
<in-ports>
<in-port type="DROOLS_DEFAULT" nodeId="13"
nodeInType="DROOLS_DEFAULT" />
</in-ports>
<out-ports>
<out-port type="DROOLS_DEFAULT" nodeId="13"
nodeOutType="DROOLS_DEFAULT" />
</out-ports>
</forEach>
<end id="5" name="End" x="230" y="456" width="80" height="40" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="5" />
</connections>
</process>
http://drools-java-rules-engine.46999.n3.nabble.com/file/n870012/testForE...
testForEach.zip
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Using-the-ForEach-com...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 5 months
Use Drools-Guvnor .pkg
by Josua
Hi,
I’m new to drools, just started evaluating Drools-Guvnor for a project. To
take advantage of Java-enums I’m using the current 5.1.0 Milestone 2.
I created a decision table (web-guided) in drools-guvnor and deployed the
package snapshot, which is downloadable and returns a .pkg-File. This File
is in some Binary format (non plaintext). When I try to load that package in
code using a KnowledgeAgent it fails on the following code line:
knowledgeAgent.applyChangeSet(resource);
with an Exception: “java.lang.RuntimeException: Unable to parse ChangeSet …
Caused by: org.xml.sax.SAXParseException: Content is not allowed in
prolog.”.
I debugged it, and it seems to try to parse XML content from this binary
file..
Can anyone tell me the proper way to load a package from a remote Guvnor
installation?
Thx!
Complete code:
KnowledgeAgent knowledgeAgent =
KnowledgeAgentFactory.newKnowledgeAgent("testAgent");
UrlResource resource = (UrlResource) ResourceFactory.newUrlResource(url);
resource.setBasicAuthentication("enabled");
resource.setUsername("whatever");
resource.setPassword("");
knowledgeAgent.applyChangeSet(resource);
KnowledgeBase knowledgeBase = knowledgeAgent.getKnowledgeBase();
Stacktrace:
java.lang.RuntimeException: Unable to parse ChangeSet
at
org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:323)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:130)
at
com.efgfp.hermes.drools.test.DroolsTest.testDroolsDecisionTable(DroolsTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:644)
at
org.testng.internal.MethodHelper$1.runTestMethod(MethodHelper.java:762)
at
org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.testng.internal.MethodHelper.invokeHookable(MethodHelper.java:770)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:539)
at
org.testng.internal.Invoker.invokeTestMethod(Invoker.java:700)
at
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1002)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:137)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:121)
at org.testng.TestRunner.runWorkers(TestRunner.java:908)
at org.testng.TestRunner.privateRun(TestRunner.java:617)
at org.testng.TestRunner.run(TestRunner.java:498)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:329)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:324)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:296)
at org.testng.SuiteRunner.run(SuiteRunner.java:201)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:915)
at org.testng.TestNG.runSuitesLocally(TestNG.java:879)
at org.testng.TestNG.run(TestNG.java:787)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:75)
at
org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1411)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1038)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at
org.drools.xml.ExtensibleXmlParser.read(ExtensibleXmlParser.java:295)
at
org.drools.xml.ExtensibleXmlParser.read(ExtensibleXmlParser.java:174)
at
org.drools.xml.XmlChangeSetReader.read(XmlChangeSetReader.java:49)
at
org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:320)
... 36 more
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Use-Drools-Guvnor-pkg...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 5 months
Object Referencing error:
by Fnu Mahalakshmi
Hi,
I am getting the following error when I try to do complex object referencing in drools:
My class:
A{
String Type;
B objectb;
//getters and setters for above
}
My rules:
rule "prod"
when
$a :A(Type == "Prod" , objectB != "")
then
B bobject = new B();
bobject.setType( "Prod" );
bobject.setId($a.getNumber().getId());
update(bobject);
end
I want to basically output a file which has updated values of B (type, Id)
Error:
org.drools.spi.ConsequenceException: org.drools.FactException: Update error: handle not found for object: com.org.Ip@f42ad0. Is it in the working memory?
at org.drools.base.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:13)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:558)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:475)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:439)
at com.org.DroolsTest.main(DroolsTest.java:30)
Caused by: org.drools.FactException: Update error: handle not found for object: com.org.Ip@f42ad0. Is it in the working memory?
at org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:100)
at com.org.Rule_Prod_Ip_0.consequence(Rule_Prod_Ip_0.java:10)
at com.org.Rule_Prod_Ip_0ConsequenceInvoker.evaluate(Rule_Prod_Ip_0ConsequenceInvoker.java:22)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
... 4 more
Please help! I am very new to drools! Not able to figure out why this error:
I am using eclipse and working on Windows machine. Error above was generated on eclipse console.
Thank you.
M
</pre>
<P><hr size=1></P>
<P><STRONG><font color=green>Please consider the environment before printing this email.</font></STRONG></P>
<P><STRONG>Visit our website at <a href="http://www.nyse.com">http://www.nyse.com</a> <br>
*****************************************************************************
<br>
Note: The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system. Thank you. NYSE Euronext.
</STRONG></P><pre>
14 years, 5 months
Ordering of collected elements
by sjoo822
Hi,
I have a rule with the condition that looks like below:
when
item : Item()
list : ArrayList(size > 0) from collect ( SubItem( type == "X" ) from
item.getSubItemList())
When I execute this rule, it seems to me that the order of elements in the
collected list is not the same as they were in the subItemList of the item.
Is there a simple way to ensure the same ordering in both original list and
the collected list without using accumulate or sorted list?
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Ordering-of-collected...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 6 months
Accepted idiom for binding variable to restriction?
by Laird Nelson
I have a fact that is inserted into my rule base. It is a Response.
A Response has a Question that it is a response to. At the moment,
the Question itself is not separately inserted into the knowledge
base. I would ideally like to keep it this way.
What's the best approach for binding variables to both the Response
and its associated Question?
That is, if the Question were inserted, it would be relatively easy:
when
$question : Question( )
$response : Response( question == $question )
...but I'm finding myself somewhat confused how to "extract" a
Question out of a Response, particularly when, say, I want to "select"
only Responses whose associated Question IDs are "XYZ":
when
$response : Response( $question : question.ID == "XYZ" ) // boy
howdy does this seem wrong
Is the easiest thing to do here to add a second rule that just inserts
the questions:
when
$response : Response
then
insert($response.getQuestion())
end
...? I would love to stay away from this if I could.
Thanks,
Laird
14 years, 6 months
Re: [rules-users] Firing a rule if at least its two conditions are satified
by Greg Barton
This will not work. Rules will not predictably react to changes in global variables. Use an object in working memory.
GreG
On Jun 3, 2010, at 7:15, "PAYET, Manuel" <manuel.payet(a)capgemini.com> wrote:
If I were you, I'd use something like
Global java.lang.Integer cnt;
Rule "before everything"
Salience 10
When
Eval(true)
Then
Cnt=0
End
Rule "condition A"
When
condition A
Then
cnt=cnt+1;
End
Rule "condition B"
When
condition B
Then
cnt=cnt+1;
End
Rule "condition C"
When
condition B
Then
cnt=cnt+1;
End
Rule "action 1, after everything"
Salience -10
When
eval(cnt>=2)
Then
execute action 1
End
Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable
-----Message d'origine-----
De : rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] De la part de skasab2s
Envoyé : jeudi 3 juin 2010 14:04
À : rules-users(a)lists.jboss.org
Objet : [rules-users] Firing a rule if at least its two conditions are satified
Hello,
we are using Drools in our company. We have a rule with three conditions in this format:
when
Condition A
Condition B
Condition C
then
execute Action 1
Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints?
Many thanks and regards!
skasab2s.
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-l...
Sent from the Drools - User mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is
intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to
read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message
in error, please notify the sender immediately and delete all copies of this message.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
14 years, 6 months