Quantcast

Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

laune
Why do you think that you should have a third fact when there are no
insert() calls except the two in your Java code?
-W

On 16/07/2012, Ravikiran <[hidden email]> wrote:

> 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-not-being-fired-Please-help-tp4018701.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

Esteban
The problem is that you are inserting the fact type definition instead of the facts themselves. 

instead of insert appType and incomeType you should insert application and income.

Best Regards,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Blog @ http://ilesteban.wordpress.com


On Mon, Jul 16, 2012 at 3:20 PM, Wolfgang Laun <[hidden email]> wrote:
Why do you think that you should have a third fact when there are no
insert() calls except the two in your Java code?
-W

On 16/07/2012, Ravikiran <[hidden email]> wrote:
> 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-not-being-fired-Please-help-tp4018701.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

Ravikiran
ooops. I'll try tomorrow in office and will reply...thanks a lot

On Mon, Jul 16, 2012 at 9:59 PM, Esteban Aliverti <[hidden email]> wrote:
The problem is that you are inserting the fact type definition instead of the facts themselves. 

instead of insert appType and incomeType you should insert application and income.

Best Regards,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Blog @ http://ilesteban.wordpress.com


On Mon, Jul 16, 2012 at 3:20 PM, Wolfgang Laun <[hidden email]> wrote:
Why do you think that you should have a third fact when there are no
insert() calls except the two in your Java code?
-W

On 16/07/2012, Ravikiran <[hidden email]> wrote:
> 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-not-being-fired-Please-help-tp4018701.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

Ravikiran
In reply to this post by Esteban
Thanks Esteban. It works fine after inserting the Fact instead of FactType...!!!

But still i have one basic question in mind...if there are many rules defined in my package, How would i know that which is rule has got fired when i call fireAllRules() method whithout passing AgendaFilter. Also i know that fireAllRules() gives me how many rules have got fired like int x = session.fireAllRules()

I have defined specific set of rules defined in a package for one biz. logic and deployed drools war seperately. From the Application integration perspective, I should be able to know whether my rules is fired or not. Based on the success or failure i'll have to do some biz. processing....

Little confusing here...i know that i am almost there...but i need some light here to understand better for the integration purpose.

Please help!!!

Thanks a lot in Advance...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

Davide Sottara
You could add an AgendaEventListener to your session (see also the manual for listeners),
letting you execute callback code whenever a rule is activated/fires/etc...

The listener is actually an interface, I think there is at least one default implementation which
just logs debug code. Notice that a possibility for a listener is to insert the callback events into
a (separate) session and use rules to process them ;)

Best
Davide
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Drools Guvnor-Decison Tables - Rule is not being fired!!! Please help

Ravikiran
Hi Davide,

I can write the listener to know what is happening underneath that will be printed in a log, but when it comes to my biz. scenario i should have a simple way that i can derive it from my java code. Because i have multiple biz.flows based on certain biz.policies...those policies have to be derived from the execution of specific rules within my package...

Can you please thorow little more light on this....

thanks
Loading...