We will use DDEV for setting up a local development environment.
- Download DDEV
- Follow the steps to setup DDEV: https://ddev.readthedocs.io/en/stable/
- Open Command Line and go to the folder of the project (e.g. /projects/ruleengine)
- Start DDEV -
ddev start
- Go into the container -
ddev ssh
- Install the needed packages -
composer install
- Create the needed tables in mysql -
./flow doctrine:migrate
If you followed these steps, you should be able to access the site via http://ruleengine.ddev.site.
For setting up a webserver, please contact your administrator. The following content are here to help.
- Install mongodb on your server; lookup https://docs.mongodb.com/drivers/php/
- Don't forget to install the needed packages first:
composer install
- Rename the file in
/Configuration/Production/Settings.yaml.example
to/Configuration/Production/Settings.yaml
- Set your credentials to your database in this file
- If this does not work, try copying the content to
/Configuration/Settings.yaml
- Flow allows you to create all the necessary tables using one single command
- Using the command line go to the folder where the project is based
- Call this command:
./flow doctrine:migrate
(if this does not work try setting the context:FLOW_CONTEXT=Production ./flow doctrine:migrate
)
Returns the data after applying the rules.
To use this function the following path needs to be called:
/api/apply
Pass the following body as POST request:
{
"data":
[
{
"id": 1,
"class": "node",
"type": "A"
},
{
"id": 2,
"class": "node",
"type": "B"
},
{
"id": 3,
"class": "node",
"type": "B"
},
{
"id": 4,
"class": "edge",
"type": "B"
}
],
"rules":
[
{
"modify": [
{"var":""},
"type",
"B"
]
}
],
"maxRecursive": 10,
"runRecursive": false
}
data
- (Required, Array) Data that the rules are applied to
rules
- (Required, Array) Rules to be applied
maxRecursive
- (Optional, Integer) Limit of max recursive executions
runRecursive
- (Optional, Boolean) If
false
, then the rules will be applied once only, default is set totrue
Adds a ruleset to the database, returns response if successful.
To use this function the following path needs to be called:
/api/add
Pass the following body as POST request:
{
"name": "My API Rule"
"description": "This is my description"
"rules":
[
{
"modify": [
{"var":""},
"type",
"B"
]
}
]
}
name
- (Required, String) Name of the ruleset
description
- (Required, String) Description of the ruleset
rules
- (Required, Array) Rules of the ruleset
There are new added functions to JSON Logic and there are also some modifications to existing functions.
Create a cartesian product out of two sources.
[
{"id": 1},
{"id": 2}
]
{
"cartesian": [
{"var":""},
{"var":""}
]
}
[
[
{"id": 1},
{"id": 1}
],
[
{"id": 1},
{"id": 2}
],
[
{"id": 2},
{"id": 1}
],
[
{"id": 2},
{"id": 2}
]
]
Modify existing or create a new attribute.
Parameter 1: data to modify
Parameter 2: attribute key
Parameter 3: attribute value
[
{
"id": 1,
"class": "node",
"type": "A"
}
]
{
"modify": [
{"var":""},
"type",
"B"
]
}
[
{
"id": 1,
"class": "node",
"type": "B"
}
]
Remove an attribute.
Parameter 1: data
Parameter 2: attribute key
[
{
"id": 1,
"class": "node",
"type": "A"
}
]
{
"remove": [
{"var":""},
"type"
]
}
[
{
"id": 1,
"class": "node"
}
]
Groups given data using given name.
Parameter 1: data
Parameter 2: name
[
{
"id": 1,
"class": "node",
"type": "A"
},
{
"id": 2,
"class": "node",
"type": "B"
}
]
{
"group": [
{"var":""},
"mygroupname"
]
}
{
"mygroupname": [
{
"id": 1,
"class": "node",
"type": "A"
},
{
"id": 2,
"class": "node",
"type": "B"
}
]
}
Joins two sources together.
Parameter 1: data
Parameter 2: data
[
{
"id": 1,
"class": "node",
"type": "A"
}
]
{
"join": [
{"var":""},
{"var":""}
]
}
[
{
"id": 1,
"class": "node",
"type": "A"
},
{
"id": 1,
"class": "node",
"type": "A"
}
]
Square root of the given number.
Parameter 1: number
Parameter 2: rounding precision after coma
2
[
{
"sqrt": [{"var":""}, 2]
}
]
1.41
Create a new object. Infinite parameters can be given, where first parameter is the data.
[
{
"id": 1,
"class": "node",
"type": "A"
}
]
[
{
"create":[
{"var":""},
["attribute1", "value 1"],
["attribute2", "value 2"]
]
}
]
[
{
"id": 1,
"class": "node",
"type": "A"
},
{
"attribute1": "value 1",
"attribute2": "value 2"
}
]
Delete objects from the data.
Parameter 1: data
Parameter 2: key to filter
Parameter 3: value to filter
[
{
"id": 1,
"class": "node",
"type": "A"
},
{
"id": 2,
"class": "node",
"type": "B"
}
]
[
{
"delete":[
{"var":""},
"type",
"A"
]
}
]
[
{
"id": 1,
"class": "node",
"type": "A"
}
]
Count the objects of the given data.
[
{
"id": 1
},
{
"id": 2
}
]
[
{
"count":[
{"var":""}
]
}
]
2
Slice the given array.
Parameter 1: array
Parameter 2: offset
Parameter 3: length
[
{
"id": 1
},
{
"id": 2
}
]
[
{
"slice":[
{"var":""},
1,
1
]
}
]
[
{
"id": 2
}
]
The var-function is modified to be able to use the original given datasource or a given source in the 4th parameter.
[
{
"var":[
"",
null,
true
]
}
]
If the 4th parameter is set, the 3rd parameter will be ignored.
[
{
"var":[
"",
null,
true,
{"var":"myNewDataSource"}
]
}
]