Creating rules having complex conditions using multiple data objects
Asked Answered
M

1

0

Assume that I have two data objects Person and Address. Person object has the fields name and gender and Address object has the fields city and state. Now I want to take some action based on this condition :

when
    (person.name == 'jayram' && address.city == 'barhiya') || 
    (person.gender == 'M' && address.state == 'bihar')
then
    do something

How to accomplish this in drools rule file?

Massimiliano answered 22/11, 2017 at 8:37 Comment(5)
Have you read the section on DRL (Drools Rule Language) in the Drools manual?Figge
@Figge No, what does it say?Massimiliano
It contains things you need to know.Figge
@Figge I went through the manual, but I couldn't find anything related to my scenario.Massimiliano
You didn't even get the syntax right, so I'm not sure what your "scenario" is. You need to understand what DRL constructs mean: then you won't have any problems implementing a presumably simple scenario.Figge
M
0

Maybe this should be the solution:

package com.sample

dialect "mvel"

import com.sample.Person;
import com.sample.Address;

rule "Hello World"
    when
        person : Person( status == Message.HELLO)
        Address((person.name == 'jayram' && city == 'barhiya') ||
 (person.gender == 'M' && state == 'bihar'))
    then
        // Do something
end
Massimiliano answered 1/12, 2017 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.