nested object from accumulate

268 views
Skip to first unread message

vijay yadav

unread,
Aug 30, 2017, 7:21:15 AM8/30/17
to Drools Usage
following is the rule



import java.lang.Integer;
rule "testrule"
    dialect "mvel"
    lock-on-active false
    when
        $app: App(pl==null)
        $acdata: ACData($enq: enquiry)
        $total: Integer() from accumulate(
            Enquiry(
                e_purpose == "pl"
            ) from $enq,
            init(Integer count = 0;),
            action(count +=1;),
            reverse(),
            result(count)
        )
    then
          modify( $app ) {
                setPl( $total )
          }
    end

and following is json request.

{
"insert":{
"object":{
"com.redhat.loandemo.ACData":{
   "enquiry":{
            "e_purpose": "pl"
       }
  }
 }
 }
},

when this rule gets fired, value of pl comes out to be 2. while it should be 1.
Would anyone please help me what's going wrong.


Regards
Vijay

Mario Fusco

unread,
Aug 31, 2017, 2:40:24 AM8/31/17
to Drools Usage
Hi,

I don't know what's going on there (I'd need a complete reproducer to investigate) but my suggestion is to use the count() accumulate function instead of implementing your own count. One of the problem with your implementation is that you're leaving the reverse() function empty where clearly it should be reverse( count -= 1; ).

Regards,
Mario

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/dd2dbf30-a84f-4b91-b770-32024e099185%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

adarsh6...@gmail.com

unread,
Aug 31, 2017, 2:58:08 AM8/31/17
to Drools Usage
Hi Mario,
Is this possible to implement the above drl file in guided decision table on workbench ??
or My Question is simple can we represent any drl file as guided decision table ??
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

Michael Anstis

unread,
Aug 31, 2017, 3:16:43 AM8/31/17
to Drools Usage
You can use any DRL in a Guided Decision Table; although we encourage use of the more guided approaches.

To use any DRL add a BRL Condition (Advanced Column type) and then a Free Form Line.

Entry your DRL text. Place holders for "variables" (cells in the table) can be specified with the "Rule Template" syntax i.e. @{key}.

For example: Person( age > @{age} ) 


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.

vijay yadav

unread,
Aug 31, 2017, 5:15:17 AM8/31/17
to Drools Usage
I have two classes named "ACData" and "Enquiry".

ACData has a field named "enquiry" of type "Enquiry".

Class Enquiry has two fields e_purpose and e_date.

Now I want to get total number of enquiry with e_purpose=="pl".
for example

{
"insert":{
"object":{
"com.redhat.loandemo.ACData":{
   "enquiry":{
            "e_purpose": "pl",
            "e_date": "1990-11-11"
       },

   "enquiry":{
            "e_purpose": "hl",
            "e_date": "1991-11-11"
       },

   "enquiry":{
            "e_purpose": "pl",
            "e_date": "1990-12-21"
       }
  }
 }
 }
},


This should return 2. Would you please tell me how can I write a rule to get this?

Regards
vijay



On Thursday, August 31, 2017 at 12:10:24 PM UTC+5:30, Mario Fusco wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
Message has been deleted

vijay yadav

unread,
Sep 4, 2017, 4:56:49 AM9/4/17
to Drools Usage
Sorry, I was doing something wrong.

following is json request.

{"com.redhat.loandemo.ACData":{
  "enquiry" : [ 
{ "e_date" : null, "e_purpose" : "pl", },
{ "e_date" : null, "e_purpose" : "pl", },
{ "e_date" : null, "e_purpose" : "al", }
]
}}

I need to get total number of entries in list "enquiry" where e_purpose=="pl".
would anyone please tell me how can I do it using guided rule?

Regards
Reply all
Reply to author
Forward
0 new messages