Business Rules Templates
Rule Templates are used as specifications to gain inputs from users through dynamically generated fields, for creating business rules. A template group is a business domain level grouping. The definition of a template looks as follows.
{ "templateGroup" : { "name" : "<Name of the template group>", "uuid":"<UUID for the template group>", "description" : "<(Optional) description for the template group>", "ruleTemplates" : [ { "name" : "<Name of the rule template>" , "uuid" : "<UUID for the rule template>", "type" : "template", "instanceCount" : "one <or> many", "description" : "<(Optional) description for the rule template>", "script" : "<(Optional) Javascript with reference to the properties>", "templates" : [ { "type" : "siddhiApp", "content" : "<SiddhiApp_1 with ${templatedProperty_x}>" }, { "type" : "siddhiApp", "content" : "<SiddhiApp_n with ${templatedProperty_y}>" } ], "properties" : { "templatedProperty_x" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>"}, "templatedProperty_y" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>", "options" : ["<option_1>", "<option_n>"]} } }, { "name" : "<Name of the rule template>", "uuid" : "<UUID for the rule template>", "type" : "input", "instanceCount" : "one <or> many", "description" : "<(Optional) description for the rule template>", "script" : "<(Optional) Javascript with reference to the properties>", "templates" : [ { "type" : "siddhiApp", "content" : "<SiddhiApp with ${templatedProperty_x}>", "exposedStreamDefinition" :"<Exposed stream definition>" } ], "properties" : { "templatedProperty_x" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>", "options" : ["<option_1>", "<option_n>"]} } }, { "name" : "<Name of the rule template>", "uuid" : "<UUID for the rule template>", "type" : "output", "instanceCount" : "one <or> many", "description" : "<(Optional) description for the rule template>", "script" : "<(Optional) Javascript with reference to the properties>", "templates" : [ { "type" : "siddhiApp", "content" : "<SiddhiApp with ${templatedProperty_x}>", "exposedStreamDefinition" :"<Exposed stream definition>" } ], "properties" : { "templatedProperty_x" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>", "options" : ["<option_1>", "<option_n>"]} } } ] } }
The following parameters are configured:
Template Group basic data
The following parameters are configured under templateGroup
.
Parameter | Description | Required/Optional |
---|---|---|
name | A name for the template group | Required |
uuid | A uniquely identifiable id for the template group | Required |
description | A description for the template. | Optional |
Rule Template details
Multiple rule templates can be defined under a templateGroup
. For each ruleTemplate
, the following set of parameters need to be configured:
Parameter | Description | Required/Optional |
---|---|---|
name | A name for the rule template | Required |
uuid | A uniquely identifiable id for the rule template | Required |
type | The type of the rule template. Possible values are as follows:
| Required |
instanceCount | This specifies whether the business rules derived from the template can be deployed only on one node, or whether they can be deployed on many nodes. Possible values are as follows:
| Required |
script | The Java script to be executed on the templated fields. Developers can use this script for:
Each templated element that is going to be derived from entered parameters, has to be mentioned as a variable in the global scope of the javascript. The entered parameters should be templated in the script itself, and will be later replaced with their respective entered values. Consider the following script /* * Validates a number and returns after adding 10 to it * @throws Error when a non number is entered */ function deriveValue(value){ if( !isNan(value) ) { return value + 10; } throw "A number is required"; } var derivedValue = deriveValue(${enteredValue});
The derived value stored in | Optional |
description | A brief description of the rule template. | Optional |
templates | These are the artifacts (i.e SiddhiApps) with templated parameters, that will be instantiated with replaced values when a business rule is created. | Required |
properties | You can add a field name, description, default value and possible values (optional) | Required |
Save the template group you created as aÂ
.json
 file in theÂ<SP_HOME>/wso2/dashboard/resources/businessRules/templates
 directory.In theÂ
BusinessRules
section of theÂ<SP_HOME>/conf/dashboard/deployment.yaml
file, add a configuration for the template you created as shown below.wso2.business.rules.manager: datasource: <datasourceName> - nodeURL1: - ruleTemplateUUID1 - ruleTemplateUUID2 nodeURL2: - ruleTemplateUUID1 - ruleTemplateUUID2
If you add this configuration, the business rules template is deployed only in the specified nodes when you run the worker and dashboard servers of your SP setup. If you do not add this configuration, the template is deployed in all the worker nodes of your SP set up.