dimanche 22 novembre 2020

Design pattern to evaluate conditions represented in JSON object structure

I have a group of conditions with AND or OR keys. I have to evaluate those conditions. Along with these conditions, I will be provided with a JSON object, which has data or values for the keys specified in "field" of conditions.

For example, in below conditions I have "field":"email", so I will receive the following JSON object as input:

{
"email":"abc@xyz.com"
}

If operator is EMPTY, it means I have to fetch value based on the "field" value in JSON and check if it is empty or not.

JSONObject conditions = {
    "conditions": [{
        "OR": [{
                "field": "email",
                "operator": "VALID_DOMAINS"
            },
            {
                "field": "email",
                "operator": "EMPTY"
            }
        ]
    }]
}

Only "AND" and "OR" operators will be present and conditions are dynamic, meaning those needs to be fetched from the database.

Note: the conditions will be boolean expressions only and it will be complex and nested conditions.

Aucun commentaire:

Enregistrer un commentaire