I have a list and an map in json format and before passing the those to template in order to generate the rules I convert them into the java and then compile them using the ObjectDataCompiler in order to generate the rules.
JSON
{
"tags": [
"ABC",
"XYZ"
],
"namedTags": {
"key1": "value1",
"key2": "value2"
},
"type": [
"",
""
],
}
I have tried 2 methods to get the values in the when condition part of the rule while designing the template.
1. As it is mentioned in the example I found while the official docs as tag[] link --> https://docs.drools.org/7.73.0.Final/drools-docs/html_single/index.html#decision-examples-pricing-ref_drools-examples
Template
template header
tag[]
namedTags[]
type
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.template.FactNew;
template "list template"
rule "listone"
no-loop true
dialect "java"
when
review:FactNew(
"@{tag0}" == "XYZ"
)
then
System.out.println("Setting the value for the list ");
modify(review){setName("NameList")}
end
end template
Generated DRL after compilation using the objectDataCompiler
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.template.FactNew;
rule "listone"
no-loop true
dialect "java"
when
review:FactNew(
"[XYZ" == "XYZ"
)
then
System.out.println("Setting the value for the list ");
modify(review){setCampaignNamePattern("NameList")}
end
Can you help as I am getting the this square brackets "[","]" appended to the first and last element respectively? Same in case of the map I getting key and value along with these braces "{","}" respectively for first and last element.
2. Reading them as the other variables are read like string but that is not feasible as In order to validate them I need to write a function.
I would like to seek your assistance in order to understand the mistake I am doing and ho can I correct my mistake in order to implement list and map using the template in the drools correctly.
P.S.-> Example will be really helpful;