Re: [rules-users] How to integrate Declarative Fact created using Guvnor in Java
Thank you for your response. I was able to follow your instruction and created newInstance of the facts. Quick question: I have 2 facts defined in Guvnor: Conditions Variable: Source (this variable is text/string) Variable: SourceType (this variable is text/string) Transcation Variable: filter (this variable is boolean) I have 2 rules as follows: If source =ABC then filter = true if source =ABC then hasIntegrated = true In my main method I created and inserted new instance of each Source as well as Transcation I set the variables of the source instance so that i can fire above rules. Source = ABC Rule 1 fires fine. I get the expected result However for Rule 2 the value of hasIntegrated is false instead of true. I run the test in Guvnor and it passes. However in my main method it fails/give me unexpected result. Any idea why this is happening??? -- View this message in context: http://drools.46999.n3.nabble.com/How-to-integrate-Declarative-Fact-created-using-Guvnor-in-Java-tp4022625p4022637.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to integrate Declarative Fact created using Guvnor in Java
I was able to fix the problem but now I am with more questions then answers. Here is what i had before defined in my DSL [when] The transcation is zero dollar = trans:Transcation (Indicator == N) [when] System description one field is ABC= $trans1:Filter(Field1 == ABC) [then] Filter out the records = Transcation trans2 = new Transcation(); trans2.setFilterOutRecords( true );insert(trans2) Now in the business rules i created following rules Rule 1: When The transcation is zero dollar Then Filter out the records Rule2: When System description one field is ABC Then Filter out the records Both test cases are passing in guvnor However when i fire these rules using Java, i was not able to get expected results. This is how i fixed it. For each When defined in DSL i have appropriate Then. So the question is can we not have a generic Then statement where i can set a value of the field and then use that with When condition as appropriate. Your help will be appreciated? -- View this message in context: http://drools.46999.n3.nabble.com/How-to-integrate-Declarative-Fact-created-using-Guvnor-in-Java-tp4022625p4022643.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] How to integrate Declarative Fact created using Guvnor in Java
Hi, Basic questions on the facts that are created in Guvnor using New Declaritive Model I have the facts that are created in Guvnor which i dont have java classes defined. I am refering to the tutorial provided on Chapter 5 The Fact Model and in that it shows how to use the declarative facts from Java. I am having hard time following the steps. So i am going to layout below to see if my understanding is correct: Step 1: // get a reference to a knowledge base with a declared type: KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); Step 2:// get the declared FactType FactType personType = kbase.getFactType( PackageName, FactName ); Step 3:// handle the type as necessary: Not sure what this means Step 4:// create instances: Object bob = personType.newInstance(); Step5: // set attributes values personType.set( bob, name, Bob ); Step 6: // insert fact into a session StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); Step 7:ksession.insert( bob ); Step 8:ksession.fireAllRules(); I am able to understand Step 4 thru Step 8. I guess i am having trouble understanding step 1 and Step 3. Can someone please help me clarify or have example for me to refer. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-integrate-Declarative-Fact-created-using-Guvnor-in-Java-tp4022625.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to integrate Declarative Fact created using Guvnor in Java
The KnowledgeBuilder processes the declared types in a DRL file, creating the bytecode on the fly. When the knowledge package is added to a knowledge base, the newly created class descriptor (the FactType and its related components) become part of the KB and the actual class is (re)loaded by the KB's classloader. Since the dynamic class is not available until runtime, the Type descriptors give you a reflection-like API to manipulate the instances. This said: Step 1: I'd actually get **the** KB which is being used to spawn sessions, to make sure you are using the same classes, as loaded by the same classloader. Step 2: The FactType also holds a reference to the loaded class, you can get it using FactType.getDefinedClass(), if needed Step 3: it's not really a step: it means that the next two steps (4+5) are just an example of what you can do now that you have the Type reference. Best, Davide On 02/27/2013 03:36 PM, IPatel wrote: Hi, Basic questions on the facts that are created in Guvnor using New Declaritive Model I have the facts that are created in Guvnor which i dont have java classes defined. I am refering to the tutorial provided on Chapter 5 The Fact Model and in that it shows how to use the declarative facts from Java. I am having hard time following the steps. So i am going to layout below to see if my understanding is correct: Step 1: // get a reference to a knowledge base with a declared type: KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); Step 2:// get the declared FactType FactType personType = kbase.getFactType( PackageName, FactName ); Step 3:// handle the type as necessary: Not sure what this means Step 4:// create instances: Object bob = personType.newInstance(); Step5: // set attributes values personType.set( bob, name, Bob ); Step 6: // insert fact into a session StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); Step 7:ksession.insert( bob ); Step 8:ksession.fireAllRules(); I am able to understand Step 4 thru Step 8. I guess i am having trouble understanding step 1 and Step 3. Can someone please help me clarify or have example for me to refer. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-integrate-Declarative-Fact-created-using-Guvnor-in-Java-tp4022625.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users