Creating rules having complex conditions using multiple data objects

467 views
Skip to first unread message

gaurav arya

unread,
Sep 11, 2018, 4:23:54 AM9/11/18
to Drools Usage
Here is my JSON Document

        {
       "location": {
          "details": [
             {
                "country": "India",
                "state": "haryana"
             },
             {
                "country": "America",
                "state": "LA"
             },
             {
                "country": "India",
                "state": "Maharashtra"
             }
          ]
       },
       "organisation": {
          "details": [
             {
                "name": "AON",
                "country": "india"
             },
             {
                "name": "AON",
                "country": "America"
             }
          ]
       }
    }

I have to apply a rule in Below format

   

     If(
            
            (location.details.country=='India' OR 
            location.details.state=='haryana') 
    AND 
            
            organisation.details.name=='AON'
        )

Till now i have researched and know that rules on the fields of the **same class can be applied in nested format like below**.

    // Use this instead
    Person( ( age > 50 && weight > 80 ) || height > 2 )

But i want to apply rules of different pojo class in the same nested condition as below

        If(
                    
                    (location.details.country=='India' OR 
                    location.details.state=='haryana') 
            AND 
                    
                    organisation.details.name=='AON'
          AND 
                   (location.details.country=='India' AND
                    organisation.details.country=='India')
                )
    //any level of nested between different pojo classes can be present

**Is this possible to do in drools?**

**And if possible then how to do it. Can anyone help?**

gordhan rathod

unread,
Oct 4, 2018, 10:13:04 AM10/4/18
to Drools Usage
One of the way can be as below,

When
     $loc:Location()
     $org:Organisation()
     eval(($loc.details.country=='India' OR 
            $loc.details.state=='haryana') 
    AND 
            $org.details.name=='AON'))
then
    .......
Reply all
Reply to author
Forward
0 new messages