I've been trying to execute a set of rules on a request object on the basis of some set of configuration value. Below is the example on what I am trying to do:
Configuration: config.json
{
"company1": {
"site1": {
"maxWeeklyWorkingHours": 40,
"rule2": [1, 3, 4],
},
"site2": {
"maxWeeklyWorkingHours": 40,
"rule2": [1, 3, 4],
}
},
"company2": {
"site1": {
"maxWeeklyWorkingHours": 40,
"rule2": [1, 3, 4],
},
"site2": {
"maxWeeklyWorkingHours": 40,
"rule2": [1, 3, 4],
}
}
}
Request Class Object: policyDataToBeVerified
PolicyDataToBeVerified(company=company1, site=site1, workerWeeklyWorkingHours=39, isRequestValid=0)
I converted the config.json into a JsonNode object:configJson and passed both policyDataToBeVerified and configJson to drools working memory. Below are the approaches I tried to take to frame the rule but failed anyways:
APPROACH 1: drools.drl
rule "maxWorkingHours"
when
$configJson: JsonNode()
$policyData: PolicyDataToBeVerified(maximumWeeklyWorkingHours <= $configJson.get(company).get(site).get("workerWeeklyWorkingHours"))
then
$policyData.setIsRequestValid(true)
end
Issue: I am getting null pointer exception at $configJson.get(company).get(site).get("workerWeeklyWorkingHours")
APPROACH 2: I even tried to use configJSON as a global variable but, then drools didn't allow me to use get methods of JsonNode to get the nested fields from JSON
I've been trying to find a solution to my problem for past few days, but nothing worked. I'd be happy to learn even if we can view this problem from a different perspective and solve it in a different way, or if we can debug this, whatever works.