fire rules from rest api or java client api

1,263 views
Skip to first unread message

jagan reddy

unread,
May 25, 2018, 2:36:04 AM5/25/18
to Drools Usage
HI,

I have a small doubt.
I am using kie  workbench and kie server 6.5.0.Final version in tomcat 8

i uploaded a jar file which contains models (Pojo classes).
i uploaded a drools excel file and converted into guided decision tables . i used data object which it refers from jar file. which i uploaded.

build is success
now i want to fire rule by using rest spi (using post man ). or using kie server client api .

url : http://localhost:8080/kie-server/services/rest/server/containers/instances/{container id }
how to be request data to fire rules

Please send me sample request data . please, consider data object are from jar file which i uploaded (i didn't created any data object in kie workbench .)

i need to show demo to the client.
Please, help me

Thanks,
Jagan

Alexandre Ramos

unread,
May 29, 2018, 10:04:07 AM5/29/18
to Drools Usage
Hello Jagan Reddy,

     I'm using Rest Server (Execution Server) with JSON.
     
     -The first step is to create the project and one Data Object to your PoC;
     -Done this, develop some rules to view execution. Example:
             rule "test 1"
             when 
             then System.out.println(´Result of Rule #1');
             end 
      
    - Build&Deploy;

    And done! If no errors founded on your project, your container is created.

    To consume rules, I attached JPG files of the Postman. Of course, adapt to your application.

Best regards and sorry for my poor english.

Alexandre R. Silva
Authorization.JPG
Body.JPG
Headers.JPG

jagan reddy

unread,
Jun 1, 2018, 2:58:45 AM6/1/18
to Drools Usage
HI Alexandre Ramos,

Thanks for reply,

If the poc contains jaxb annotations. how post data, headers will be.

Thanks,
Jagan

Alexandre Ramos

unread,
Jun 1, 2018, 12:51:14 PM6/1/18
to drools...@googlegroups.com
I don't know Jagan.

Do you ser the docs?

--
You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/QmgnKp3wRB0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/d75bbd90-a387-425c-9abd-d927f6978b7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jagan reddy

unread,
Jun 2, 2018, 4:06:36 AM6/2/18
to Drools Usage
HI Alexandre Ramos,

Thanks for reply,

Thanks,
Jagan

Abhijit Humbe

unread,
Jun 3, 2018, 10:08:21 PM6/3/18
to drools...@googlegroups.com
Are you expecting updated facts after rule execution in REST API response ? Am I correct ?

Abhijit Humbe

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

jagan reddy

unread,
Jun 4, 2018, 4:38:59 AM6/4/18
to Drools Usage

Hi Abhijit Humbe,
Thanks for reply
yes, i am expecting updated facts after rue execution in REST API response.
one more issues., in guided decision table , one of the action i  have given system print out statement, when all conditions matched it prints statement.

when i fire rules from REST API first time it print statement
         with the same condition    second time it print same statement 3 times.
         with the same condition    third time it print same statement 5 times. it is increasing +2 times. it happens when i fire rules

but in guided decision table conditions matches only one row.
how to fix it.

Thanks,
Jagan
--

Abhijit Humbe

unread,
Jun 4, 2018, 8:49:15 AM6/4/18
to drools...@googlegroups.com

Please find answers inline.
Abhijit Humbe

On Mon, Jun 4, 2018 at 2:08 PM, jagan reddy <cjmre...@gmail.com> wrote:

Hi Abhijit Humbe,
Thanks for reply
yes, i am expecting updated facts after rue execution in REST API response.
>> Call get-object method to print updated objects in response, like as:
 {
         "get-objects":{ "identifier":"f2",
            "out-identifier":"result"
         }}
one more issues., in guided decision table , one of the action i  have given system print out statement, when all conditions matched it prints statement.

when i fire rules from REST API first time it print statement
         with the same condition    second time it print same statement 3 times.
         with the same condition    third time it print same statement 5 times. it is increasing +2 times. it happens when i fire rules

but in guided decision table conditions matches only one row.
how to fix it.

Facts available in working memory are getting reevaluated after sending REST requests to execute rules. In this situation you have two workarounds:
   1. Retract fact from working memory in rules, like as:

         rule retractInitialFact
            when
                  $pojo:MyPojo
             then
                   retract($pojo)
             end
  2. Define maximum number of rules to be executed in  fire-all-rule command:
 {
            "fire-all-rules":{"max":"1","out-identifier":"firedActivations"}
         }
  This approach is not suitable if you have multiple rules to execute.
Thanks,
Jagan
--

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.

jagan reddy

unread,
Jun 5, 2018, 1:44:38 AM6/5/18
to Drools Usage
Hi Abhijit Humbe,

Thanks for reply

Please, explain about retract($pojo) 
how to use it.
Thanks,
 Jagan

Abhijit Humbe

unread,
Jun 5, 2018, 11:29:15 PM6/5/18
to drools...@googlegroups.com
To remove fact from memory you just need to call pre-defined function 'retract' in the 'then' part of the rule. You just need to pass object reference which you want to remove from memory.

Abhijit Humbe

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.

jagan reddy

unread,
Jun 5, 2018, 11:49:41 PM6/5/18
to Drools Usage
Hi Abhijit Humbe,

Thanks for reply and clear explanation.


Thanks,
 Jagan

jagan reddy

unread,
Jun 6, 2018, 3:56:09 AM6/6/18
to Drools Usage
Hi Abhijit Humbe,

I added retract(Object obj) method. it fixed my issues.

Thank you once again.

Thanks,
 Jagan

ajay chavan

unread,
Jul 27, 2018, 9:31:23 AM7/27/18
to Drools Usage
Hi Jagan,

Can you please provide some sample on this. I need retract example.

Thanks
Ajay

jagan reddy

unread,
Jul 28, 2018, 12:47:40 AM7/28/18
to Drools Usage
hi


conditions
$loan : com.bayview.mortgage.LOAN($loan.getLoanID() !="@{param1}" &&
($loan.getLoanext().getSystemOfRecord().equalsIgnoreCase("@{param2}")) &&
($loan.getLoanext().getCompanyCode()!= null && $loan.getLoanext().getCompanyCode().startsWith("@{param3}") ) &&
($loan.getLoanext().getSalesStatus()!= null && $loan.getLoanext().getSalesStatus().equalsIgnoreCase("@{param4}")) ) && $LoanHelper:com.bayview.mortgage.utils.LoanHelper($LoanHelper.getHelperLoanId() !="@{param5}")

actions
$loan.getLoanext().setServicingType("@{param6}");
$LoanHelper.setLoanGroup($loan,"@{param7}");
$LoanHelper.setClientName($loan,"@{param8}");
System.out.println("Rule Based Loan Type: @{param9}");
retract($loan);

thanks,
jagan


ajay chavan

unread,
Jul 30, 2018, 6:12:30 AM7/30/18
to Drools Usage
Thanks Jagan for this.
Reply all
Reply to author
Forward
0 new messages