How handle exception thrown while looping in DRL file
by ashwindrool
Hi,
I ran enhanced for loop in .DRL file .Its looping perfectly but after
completion of loop its throwing error mentioned as follows:
*org.drools.runtime.rule.ConsequenceException: rule: Test
Maadiiiiiiiiiiiiiiiii
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:737)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:701)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
at com.sample.DroolsTest.main(DroolsTest.java:156)
Caused by: java.lang.NullPointerException
at
com.sample.Rule_Test_Maadiiiiiiiiiiiiiiiii_0.defaultConsequence(Rule_Test_Maadiiiiiiiiiiiiiiiii_0.java:7)
at
com.sample.Rule_Test_Maadiiiiiiiiiiiiiiiii_0DefaultConsequenceInvoker.evaluate(Rule_Test_Maadiiiiiiiiiiiiiiiii_0DefaultConsequenceInvoker.java:27)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
... 6 more
*
--
View this message in context: http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-loopi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help
by Ravikiran
Hi,
I'm using default Guvnor package "mortgages" decision table as example for
my POC. Below is the rules from the decision table. No rule is being fired
from my JAVA client out of 3 rules given below.
//from row number: 1
rule "Row 3 Pricing loans"
dialect "mvel"
when
application : LoanApplication( amount > "131000" , amount <=
"200000" , lengthYears == "30" , deposit < "20000" )
income : IncomeSource( type == "Asset" )
then
application.setApproved( true );
application.setInsuranceCost( 0 );
application.setApprovedRate( 2 );
end
//from row number: 2
rule "Row 1 Pricing loans"
dialect "mvel"
when
application : LoanApplication( amount > "10000" , amount <= "100000" ,
lengthYears == "20" , deposit < "2000" )
income : IncomeSource( type == "Job" )
then
application.setApproved( true );
application.setInsuranceCost( 0 );
application.setApprovedRate( 4 );
end
//from row number: 3
rule "Row 2 Pricing loans"
dialect "mvel"
when
application : LoanApplication( amount > "100001" , amount <= "130000" ,
lengthYears == "20" , deposit < "3000" )
income : IncomeSource( type == "Job" )
then
application.setApproved( true );
application.setInsuranceCost( 10 );
application.setApprovedRate( 6 );
end
==> My Java client follows
KnowledgeBase knowledgeBase = createKnowledgeBase(); //Successfully creates
knowledgebase
StatefulKnowledgeSession session =
knowledgeBase.newStatefulKnowledgeSession();
FactType appType = knowledgeBase.getFactType( "mortgages",
"LoanApplication" );
FactType incomeType = knowledgeBase.getFactType( "mortgages",
"IncomeSource" );
Object application = appType.newInstance();
Object income = incomeType.newInstance();
appType.set(application, "amount", 100000);
appType.set(application, "deposit", 1500);
appType.set(application, "lengthYears", 20);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 65000);
session.insert(appType);
session.insert(incomeType);
assertTrue(session.getFactCount() == 2);
session.fireAllRules();
assertTrue(session.getFactCount() == 3);
Question: I hope the way i pass the input satisfies "Row 2 Pricing loans"
above. But My assertion is getting failed after calling
fireAllRules()...because the factcount was still 2. Please help what could
be the wrong in above scenario.
thanks a lot.
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-Decison-Tables-Rule-is-no...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Drools Guvnor 5.4.0 - Rules integration with database (Oracle)
by Ravikiran
Hi,
I working on creating a POC by creating set of web based rules within a
package using drools Guvnor and accessing them from my Java client.
Currently, my drools uses Jackrabbit repository (2 foldersrepository and
scripts and 1 file repository.xml) which is created within "bin" folder of
my JBoss AS.
I have gone through the steps given in user guide for database integration,
I am using Oracle as my database and i generated oracle based repository.xml
using the administration in Drools Guvnor and placed it under my bin folder.
I have stopped the server and deleted exsting 2 folders and one xml file. I
have restarted my server with the deployment of drools-guvnor.war. When i
start the guvnor web, it has asked me whether to load the sample packages
for the fisrt time, i said yes.
Now when i go and see in bin directory, i could still see one respository
folder. Also, i could see there were 6-7 tables have been created in oracle
database which were belongs to jboss drools only.
I would need some experts suggestion here,
is it the right way to do the rule integration with the database?
What is right way to promote the same changes to SIT or UAT?
Thanks in advance...
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-5-4-0-Rules-integration-w...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Drools Chance
by Nick
Hi Team,
I was just wondering what is the status of the
development behind Drools Chance? I forked the repository on GitHub and
am quite impressed with the entire module, however I cannot tell how
stable it is.
So, I was wondering if there are any plans for a stable release, or if the module is still being developed.
Thank you,
Nick
13 years, 9 months
Why does it seem like salience is being ignored?
by Ladd
I'm using drools-camel 5.4.0.Final. ksession is stateful, I'm in STREAM
mode, and rules are fired with fireUntilHalt().
My test route is:
from( "direct:test-message" ).to(
"drools://node/ksession1?action=insertMessage" );
I'm sending my objects into the engine like so:
template.sendBody( "direct:test-message", new Person( "Bob" ) );
template.sendBody( "direct:test-message", new Person( "Jim" ) );
I have two rules that I'd like to fire in a specific order (1a followed by
1b).
If I define rule1a first in my drl it fires first as I would expect (with or
without a salience specified). But if I define rule1b first, that fires
first even though rule1a has a higher salience.
Here are my two rules / test cases and the results:
*Scenario 1 (rule1a first first as I want it to):*
rule += "rule rule1a salience 100 \n";
rule += " when \n";
rule += " $m : Message( body.class == Person.class, $body : body ) \n";
rule += " $p : Person() from $body \n";
rule += " then \n";
rule += " System.err.println( \"rule1a: Just found person \" +
$p.getName() ); \n";
rule += "end\n";
rule += "rule rule1b\n";
rule += " when \n";
rule += " $m : Message() \n";
rule += " then \n";
rule += " System.err.println( \"rule1b: Just found message \" +
$m.getBody().toString() ); \n";
rule += "end\n";
*Output:*
rule1a: Just found person Bob
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person@b49448
rule1a: Just found person Jim
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person@f4e9d3
*Scenario 2 (rule1b fires first even through rule1a has a higher salience):*
rule += "rule rule1b\n";
rule += " when \n";
rule += " $m : Message() \n";
rule += " then \n";
rule += " System.err.println( \"rule1b: Just found message \" +
$m.getBody().toString() ); \n";
rule += "end\n";
rule += "rule rule1a salience 100 \n";
rule += " when \n";
rule += " $m : Message( body.class == Person.class, $body : body ) \n";
rule += " $p : Person() from $body \n";
rule += " then \n";
rule += " System.err.println( \"rule1a: Just found person \" +
$p.getName() ); \n";
rule += "end\n";
*Output:*
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person@1133fd6
rule1a: Just found person Bob
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person@ca425c
rule1a: Just found person Jim
Something simple I'm sure. Any pointers to get my salience working?
Thanks for taking the time to help me out!!
- Ladd
--
View this message in context: http://drools.46999.n3.nabble.com/Why-does-it-seem-like-salience-is-being...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Duplicate Rule Invocations
by mark.nowicki@cubrc.org
Hi, I'm getting duplicate rule invocations when a rule is added to the
KnowledgeBase after the facts have been inserted in the
StatefulKnowledgeSession. Very simple example, seems what I'm doing is
consistent with 5.3.0.Final Drools expert documentation. Thanks for the
assistance,
--Mark
*Running code below outputs the following (firing twice for Person A,
Relationship A-C):*
RelationshipRule Fired!
person: Person( id=A, type=parent )
relationship: Relationship( parentId=A, childId=C )
RelationshipRule Fired!
person: Person( id=A, type=parent )
relationship: Relationship( parentId=A, childId=B )
RelationshipRule Fired!
person: Person( id=A, type=parent )
relationship: Relationship( parentId=A, childId=C )
*resources/factTypes.drl:*
package testing.facttypes;
declare Person
id : String
type : String
end
declare Relationship
parentId : String
childId : String
end
*resources/rules.drl:*
package testing.rules;
import java.util.ArrayList;
import testing.facttypes.Person;
import testing.facttypes.Relationship;
rule "RelationshipRule"
no-loop true
when
person : Person(type == "parent")
relationship : Relationship(parentId == person.id)
then
System.out.println("RelationshipRule Fired!");
System.out.println("person: " + person);
System.out.println("relationship: " + relationship + "\n");
end
*public static void main snippet:*
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSession statefulKnowledgeSession =
knowledgeBase.newStatefulKnowledgeSession();
KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBase);
Resource factTypes =
ResourceFactory.newClassPathResource("resources/factTypes.drl");
knowledgeBuilder.add(factTypes, ResourceType.DRL);
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
FactType factType =
knowledgeBase.getFactType("testing.facttypes", "Person");
Object personA = factType.newInstance();
factType.set(personA, "id", "A");
factType.set(personA, "type", "parent");
statefulKnowledgeSession.insert(personA);
factType = knowledgeBase.getFactType("testing.facttypes",
"Person");
Object personB = factType.newInstance();
factType.set(personB, "id", "B");
factType.set(personB, "type", "child");
statefulKnowledgeSession.insert(personB);
factType = knowledgeBase.getFactType("testing.facttypes",
"Relationship");
Object relationshipAB = factType.newInstance();
factType.set(relationshipAB, "parentId", "A");
factType.set(relationshipAB, "childId", "B");
statefulKnowledgeSession.insert(relationshipAB);
factType = knowledgeBase.getFactType("testing.facttypes",
"Person");
Object personC = factType.newInstance();
factType.set(personC, "id", "C");
factType.set(personC, "type", "child");
statefulKnowledgeSession.insert(personC);
factType = knowledgeBase.getFactType("testing.facttypes",
"Relationship");
Object relationshipAC = factType.newInstance();
factType.set(relationshipAC, "parentId", "A");
factType.set(relationshipAC, "childId", "C");
statefulKnowledgeSession.insert(relationshipAC);
knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBase);
Resource rules =
ResourceFactory.newClassPathResource("resources/rules.drl");
knowledgeBuilder.add(rules, ResourceType.DRL);
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
statefulKnowledgeSession.fireAllRules();
--
View this message in context: http://drools.46999.n3.nabble.com/Duplicate-Rule-Invocations-tp4018717.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Setting and extracting different values for the same object using rules
by abhinay_agarwal
suppose i have an object Customer and i insert the object of customer in the
session...
class Customer
{
custID;
//getter and setter
}
Customer customer = new Customer()
ksession.insert(customer)
now i fire a couple of rules on this object..
and within the rules, the custID is set with three different values. Ex -
001,002,003
is there a way by which i can get all the three values ??
if I use a factHandle like
FactHandle fh = ksession.insert(customer)
syso(((Customer)ksession.getObject(fh)).getCustID)
//output is only 003..
i need all the three values..what can be done !!??
--
View this message in context: http://drools.46999.n3.nabble.com/Setting-and-extracting-different-values...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Average over window
by Machiel Groeneveld
Dear Drools users,
I'm new to Drools but loving it so far. I have a question about accumulate
and window:lengt:
What I want: "Display the average order value considering the last 200
orders for one type of product. I want have at least 10 orders for one
product before drawing any conclusions"
How I solved it now, it's not working as I want it:
I now insert product objects to be able to group the orders per product.
The first problem is that the list of products is not unique but every
insert creates a new product object (even though the product object has
already been inserted for that productId), so the second rule is triggered
way too often. I don't actually want to insert this product object, but I
don't know how else to group on product otherwise. Any help on this part is
greatly appreciated.
The second problem is that the window doesn't seem to use all the orders
matching the product, it just limits the rule to use the last 200 orders,
not the last 200 orders for that product. Is there a way to make this
smarter?
(I can't share our source code, so this might not compile)
declare Product
productId : String;
end
delcare Order
@role(event)
productId: String;
price: int;
end
rule "Turn purchase into order"
when
p : Purchase()
then
insert ( new Product(p.productId) )
insert ( new Order(p.productId, p.price)
rule "Count average price"
when
$product : Product ()
accumulate(
Order(productId == $product.productId, $pr : price ) over
window:length(200);
$avg : average( $pr ),
$count: count($pr);
$count > 10, $avg < 10)
then
"The average price for product $product.productId is $avg"
13 years, 9 months
Planner - IntConstraintOccurrence not being retracted
by Garf
I've been building a prototype similar to CloudBalancing.
I've got IntConstraintOccurrence objects being inserted via insertLogical()
through my rules.
For some reason, I don't think these are being retracted as expected -- the
count() of accumulated IntConstraintOccurrence's ramps up to 10x what I
expected to be (and the sum of weights is similarly 10x what I expect).
Also -- I have enabled Drools debugging, but I don't see the Audit Logs.
any ideas?
Jon
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-IntConstraintOccurrence-not-bei...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Simple Global Error !!
by abhinay_agarwal
global java.lang.Integer count
rule "rule1"
agenda-group "1"
when
//smething
then
count=0;
System.out.println(count); // output is 0
count = count +1;
System.out.println(count); // output is 1
drools.setFocus("2");
end
rule "rule2"
agenda-group "2"
when
//smething
then
System.out.println(count); // output is 0
end
in the rule2, the value of the global variable "count" must be 1, why m i
getting it as zero ?
--
View this message in context: http://drools.46999.n3.nabble.com/Simple-Global-Error-tp4018697.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months