-
Notifications
You must be signed in to change notification settings - Fork 0
Built in functions
This page lists all the existing Function implementations we ship with the app.
Each function does one simple thing, generate an output vale by applying the function to an input value.
To implement this, we can use some configuration parameters affecting the function behavior. These parameters are listed
under the configuration map of that belongs to the function under the params
object defined for the rule which will
use the function during the transformation.
Each function has a version when it was added to the app, a class implementing them, a name they are registered with, an input type, an output type, a parameter list defining how they can be configured, a description stating what they are supposed to do, and we will show an example configuration as well.
Name: changeCase
Class: ChangeCaseFunction
Since version: 1.1.0
Input type: String
Output type: String
Parameters
Name | Type | Description |
---|---|---|
to |
CaseChange |
Defines what is the desired case change operation we want to do. |
Description
This function takes the input value and changes the case as defined by the "to" parameter.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "add"
path: "$.accounts[*]"
params:
key: # this is the node defining the first supplier
name: "staticString"
value: "address"
value: # this is the node defining the converting supplier
name: "converting"
stringSource: # this supplier would return a lowercase value
name: "staticString"
value: "missing"
converter: # then this function will turn it into Capital
name: "changeCase"
to: "CAPITALIZED"
On this input
{
"accounts": [
{
"id": 1,
"name": "John Doe"
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
Produces this output
{
"accounts": [
{
"id": 1,
"name": "John Doe",
"address": "Missing"
},
{
"id": 2,
"name": "Jane Doe",
"address": "Missing"
}
]
}
This example shows that the inserted "Missing" value is capitalized with this function.
Name: cloneKey
Class: CloneKeyFunction
Since version: 1.1.0
Input type: Map
< String
, Object
>
Output type: Map
< String
, Object
>
Parameters
Name | Type | Description |
---|---|---|
from |
String |
The name of the key we need to duplicate. |
to |
String |
The name of the destination key. |
Description
This function takes the input value as a Map and puts the value assigned to the "from" key using the "to" key.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "replaceMap"
path: "$.accounts[*]"
params:
predicate:
name: "containsKey"
key: "billingAddress"
mapFunction:
name: "cloneKey"
from: "billingAddress"
to: "shippingAddress"
On this input
{
"accounts": [
{
"billingAddress": "123 Main street, SomeCity",
"id": 1,
"name": "John Doe"
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
Produces this output
{
"accounts": [
{
"billingAddress": "123 Main street, SomeCity",
"id": 1,
"name": "John Doe",
"shippingAddress": "123 Main street, SomeCity"
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
This example clones "billingAddress" to "shippingAddress" thanks to this function.
Name: add
Class: DecimalAddFunction
Since version: 1.1.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
operand |
BigDecimal |
Second operand of the calculation. |
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function adds the value provided as "operand" to the input value then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.posts[*].views"
params:
predicate: # this is the node defining the predicate
name: "notNull"
numberFunction: # this is the node defining the numerical calculation
name: "add"
operand: 1
scale: 0
On this input
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 30,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
Produces this output
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 30,
"views": 21
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 6
}
]
}
In this example we have increased the number of views using this function.
Name: absoluteValue
Class: AbsoluteValueFunction
Since version: 1.4.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function replaces the input value with it's absolute value, then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.pointPairs[*].distance"
params:
predicate: # this is the node defining the predicate
name: "notNull"
numberFunction: # this is the node defining the numerical calculation
name: "absoluteValue"
scale: 1
On this input
{
"pointPairs": [
{
"distance": -6.5,
"point_1": 10,
"point_2": 3.5
},
{
"distance": 5.90,
"point_1": "10.00",
"point_2": "15.91"
}
]
}
Produces this output
{
"pointPairs": [
{
"distance": 6.5,
"point_1": 10,
"point_2": 3.5
},
{
"distance": 5.9,
"point_1": "10.00",
"point_2": "15.91"
}
]
}
In this example we have replaced the distance values with their absolute values.
Name: divide
Class: DecimalDivideFunction
Since version: 1.1.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
operand |
BigDecimal |
Second operand of the calculation. |
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function divides the input value with the value provided as "operand", then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.posts[*].likes"
params:
predicate: # this is the node defining the predicate
name: "notNull"
numberFunction: # this is the node defining the numerical calculation
name: "divide"
operand: 5
scale: 1
On this input
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 30,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
Produces this output
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 6.0,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0.0,
"views": 5
}
]
}
In this example we have divided the number of likes by 5.
Name: dividend
Class: DecimalDividendFunction
Since version: 1.4.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
operand |
BigDecimal |
First operand of the calculation. |
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function divides the value provided as "operand" with the input value, then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.posts[0].likes"
params:
predicate: # this is the node defining the predicate
name: "notNull"
numberFunction: # this is the node defining the numerical calculation
name: "dividend"
operand: 600
scale: 2
On this input
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 30,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
Produces this output
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 20.00,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
In this example we have divided 600 by the number of likes.
Name: multiply
Class: DecimalMultiplyFunction
Since version: 1.1.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
operand |
BigDecimal |
Second operand of the calculation. |
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function multiplies the input value with the value provided as "operand", then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.posts[*].likes"
params:
predicate: # this is the node defining the predicate
name: "notNull"
numberFunction: # this is the node defining the numerical calculation
name: "multiply"
operand: 2
scale: 0
On this input
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 30,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
Produces this output
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 60,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
In this example we have doubled the number of likes using this function.
Name: subtract
Class: DecimalSubtractFunction
Since version: 1.1.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
operand |
BigDecimal |
Second operand of the calculation. |
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function subtracts the value provided as "operand" from the input value then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.posts[*].likes"
params:
predicate: # this is the node defining the predicate
name: "SpEL"
expression: "(#root instanceof T(java.math.BigDecimal)) && #root.longValue() > 3"
numberFunction: # this is the node defining the numerical calculation
name: "subtract"
operand: 3
scale: 0
On this input
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 30,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
Produces this output
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 27,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
In this example we have decreased the number of likes by 3 using this function.
Name: subtractFrom
Class: DecimalSubtractFromFunction
Since version: 1.4.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
operand |
BigDecimal |
First operand of the calculation. |
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function subtracts input value from the value provided as "operand" then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.posts[*].likes"
params:
predicate: # this is the node defining the predicate
name: "SpEL"
expression: "(#root instanceof T(java.math.BigDecimal)) && #root.longValue() > 0"
numberFunction: # this is the node defining the numerical calculation
name: "subtractFrom"
operand: 100
scale: 0
On this input
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 30,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
Produces this output
{
"posts": [
{
"id": 1,
"title": "Post title 1",
"likes": 70,
"views": 20
},
{
"id": 2,
"title": "Post title 2",
"likes": 0,
"views": 5
}
]
}
In this example we subtracted the previous value from 100 using this function.
Name: roundDecimal
Class: RoundDecimalFunction
Since version: 1.4.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
scale |
Integer |
The number of digits we want to keep right of the decimal point. |
Description
This function parses the input value, then adjusts the "scale" as defined.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.pointPairs[*].*"
params:
predicate: # this is the node defining the predicate
name: "notNull"
numberFunction: # this is the node defining the numerical calculation
name: "roundDecimal"
scale: 0
On this input
{
"pointPairs": [
{
"distance": -6.5,
"point_1": 10,
"point_2": 3.5
},
{
"distance": 5.90,
"point_1": "10.00",
"point_2": "15.91"
}
]
}
Produces this output
{
"pointPairs": [
{
"distance": -7,
"point_1": 10,
"point_2": 4
},
{
"distance": 6,
"point_1": 10,
"point_2": 16
}
]
}
In this example we have replaced all numbers with their rounded values.
Name: epochMillisDateAdd
Class: EpochMilliDateAddFunction
Since version: 1.1.0
Input type: BigDecimal
Output type: BigDecimal
Parameters
Name | Type | Description |
---|---|---|
amount |
Integer |
The amount of time units we need to add to the date time. |
unit |
ChronoUnit |
The time unit we want to use to interpret the amount. |
Description
This function parses the input value as a date time using the assumption that the number is representing an instant using the epoch millis approach, then adds the necessary "amount" of time "unit"s before converting it back the same way.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "calculate"
path: "$.accounts..expiresOn"
params:
numberFunction: # this is the node defining our function
name: "epochMillisDateAdd"
amount: 1
unit: "HOURS"
predicate: # we want to match anything
name: "notNull"
On this input
{
"accounts": [
{
"id": 1,
"name": "John Doe",
"expiresOn": 1594405286000
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
Produces this output
{
"accounts": [
{
"id": 1,
"name": "John Doe",
"expiresOn": 1594408886000
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
In this example we have changed the expiration date of an account by adding 1 hour.
Name: httpResourceByUri
Class: HttpResourceContentFunction
Since version: 1.2.0
Input type: String
Output type: String
Parameters
Name | Type | Description |
---|---|---|
uriFunction |
Function < String , String > |
The function that is calculating the request URI based on the input map. |
uri |
String |
The default request URI as a fallback. |
httpMethod |
HttpMethod |
The default request method as a fallback. Defaults to GET. |
httpHeaders |
Map < String , String > |
The default request headers as a fallback. |
charset |
Charset |
The charset used to read the response. Defaults to UTF-8. |
Description
This function is providing a highly flexible HTTP download opportunity. It can operate in with only providing the bare minimum of some base values (an URI, a HTTP method, some headers if needed) as well as it offers the opportunity to use a function to find the URI based on the JSON/Supplier. provided values.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules: # this is where our rule is defined
- name: "add"
path: "$"
params:
key: # we will add the content under the example node
name: "staticString"
value: "example"
value:
name: "converting"
stringSource:
name: "staticString" # this is the supplier defining what to download
value: "example.json"
converter: # this converter changes the supplied value to have the full URI
name: "httpResourceByUri"
uriFunction:
name: "regex"
pattern: (?<value>.+)
replacement: "https://raw.githubusercontent.com/nagyesta/yippee-ki-json/main/src/test/resources/json/${value}"
On this input
{
"uri": "example.json",
"method": "GET"
}
Produces this output
{
"uri": "example.json",
"method": "GET",
"example": "{\n \"accounts\": [\n {\n \"id\": 1,\n \"name\": \"John Doe\",\n \"email\": \"[email protected]\"\n },\n {\n \"id\": 2,\n \"name\": \"Peter Parker\",\n \"email\": \"[email protected]\"\n },\n {\n \"id\": 3,\n \"name\": \"Jane Doe\",\n \"email\": \"[email protected]\"\n },\n {\n \"id\": 4,\n \"name\": \"John Smith\",\n \"email\": \"[email protected]\"\n }\n ]\n}"
}
In this example we have used a supplier to provide input.
Name: httpResource
Class: HttpResourceContentMapFunction
Since version: 1.2.0
Input type: Map
< String
, Object
>
Output type: String
Parameters
Name | Type | Description |
---|---|---|
uriFunction |
Function < Map < String , Object > , String > |
The function that is calculating the request URI based on the input map. |
methodFunction |
Function < Map < String , Object > , String > |
The function that is calculating the request method based on the input map. |
headerFunction |
Function < Map < String , Object > , Map < String , String > > |
The function that is calculating the request headers based on the input map. |
uri |
String |
The default request URI as a fallback. |
httpMethod |
HttpMethod |
The default request method as a fallback. Defaults to GET. |
httpHeaders |
Map < String , String > |
The default request headers as a fallback. |
charset |
Charset |
The charset used to read the response. Defaults to UTF-8. |
Description
This function allows fully dynamic calculation of all component of the HTTP request while it let's us define fallback values in case overrides are not possible or not desired for any aspects.
This function offers more flexibility than what the rest of the components could fully utilize. Please expect more updates unleashing the full potential of this component.
Name: jsonParse
Class: JsonParseFunction
Since version: 1.2.0
Input type: String
Output type: Object
Parameters: < NONE >
Description
This function parses the input JSON String and returns an object.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "add"
path: "$.accounts[*]"
params:
key: # this is the node defining the first supplier
name: "staticString"
value: "address"
value: # this is the node defining the second supplier
name: "converting"
stringSource: # we are starting with a static string
name: "staticString"
value: '{"home":"123 Main street, SomeCity"}'
converter: # then we are parsing it as JSON
name: "jsonParse"
On this input
{
"accounts": [
{
"id": 1,
"name": "John Doe"
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
Produces this output
{
"accounts": [
{
"id": 1,
"name": "John Doe",
"address": {
"home": "123 Main street, SomeCity"
}
},
{
"id": 2,
"name": "Jane Doe",
"address": {
"home": "123 Main street, SomeCity"
}
}
]
}
In this example we have parsed the string and inserted an object instead.
Name: replace
Class: LiteralReplaceFunction
Since version: 1.1.0
Input type: String
Output type: String
Parameters
Name | Type | Description |
---|---|---|
find |
String |
A literal we need to find in the input String. |
replace |
String |
The replacement we need to use. |
Description
This function takes the input value, attempts to replace all occurrences of the "find" value with the "replace" value.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "replace"
path: "$.accounts..lastName"
params:
stringFunction: # this is where we define our regex based replace
name: "regex"
pattern: (?<firstName>[A-Za-z\-]+) (?<lastName>[A-Za-z\-]+)
replacement: "${lastName}"
predicate: # doing it for all Strings
name: "anyString"
- name: "replace"
path: "$.accounts..firstName"
params:
stringFunction: # this is where we define our literal based replace
name: "replace"
find: " Doe"
replace: ""
predicate: # we will do it only for non-null values
name: "notNull"
On this input
{
"accounts": [
{
"accountId": 1,
"firstName": "John Doe",
"lastName": "John Doe"
},
{
"accountId": 2,
"firstName": "Jane Doe",
"lastName": "Jane Doe"
}
]
}
Produces this output
{
"accounts": [
{
"accountId": 1,
"firstName": "John",
"lastName": "Doe"
},
{
"accountId": 2,
"firstName": "Jane",
"lastName": "Doe"
}
]
}
In this example, our replace function removed the " Doe" part from both "firstName" fields.
Name: regex
Class: RegexReplaceFunction
Since version: 1.0.0
Input type: String
Output type: String
Parameters
Name | Type | Description |
---|---|---|
pattern |
String |
A regex pattern that will be matched against the input, capturing certain named groups for later use. |
replacement |
String |
Defines how the captured groups should be used to piece together the output value using EL-like syntax. |
Description
This function takes the input value, attempts to match the pre-defined pattern and capture the values of the named capturing groups. Then using the replacement format it tries to resolve all EL-like placeholders using the captured values form the previous step and returns the result.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "replace"
path: "$.accounts..lastName"
params:
stringFunction: # this is where we define our regex based replace
name: "regex"
pattern: (?<firstName>[A-Za-z\-]+) (?<lastName>[A-Za-z\-]+)
replacement: "${lastName}"
predicate: # doing it for all Strings
name: "anyString"
- name: "replace"
path: "$.accounts..firstName"
params:
stringFunction: # this is where we define our literal based replace
name: "replace"
find: " Doe"
replace: ""
predicate: # we will do it only for non-null values
name: "notNull"
On this input
{
"accounts": [
{
"accountId": 1,
"firstName": "John Doe",
"lastName": "John Doe"
},
{
"accountId": 2,
"firstName": "Jane Doe",
"lastName": "Jane Doe"
}
]
}
Produces this output
{
"accounts": [
{
"accountId": 1,
"firstName": "John",
"lastName": "Doe"
},
{
"accountId": 2,
"firstName": "Jane",
"lastName": "Doe"
}
]
}
In this example, our regex replace function matches against two "words" using only letters and dashes, separated by a single space. The replacement format tells the function to keep only the second word and throw away the first. We applied this to both "lastName" fields.
Name: stringDateAdd
Class: StringDateAddFunction
Since version: 1.1.0
Input type: String
Output type: String
Parameters
Name | Type | Description |
---|---|---|
formatter |
String |
The format String we need to use for date time parsing. See |
amount |
Integer |
The amount of time units we need to add to the date time. |
unit |
ChronoUnit |
The time unit we want to use to interpret the amount. |
Description
This function parses the input value using the "formatter" pattern, then adds the necessary "amount" of time "unit"s before formatting it using the same pattern.
Example configuration
Applying this configuration
actions:
- name: "demo"
rules:
- name: "replace"
path: "$.accounts..expiresOn"
params:
stringFunction: # this is the node defining our function
name: "stringDateAdd"
formatter: "yyyy-MM-dd"
amount: 6
unit: "MONTHS"
predicate: # we want to match any String
name: "anyString"
On this input
{
"accounts": [
{
"id": 1,
"name": "John Doe",
"expiresOn": "2020-03-14"
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
Produces this output
{
"accounts": [
{
"id": 1,
"name": "John Doe",
"expiresOn": "2020-09-14"
},
{
"id": 2,
"name": "Jane Doe"
}
]
}
In this example we have changed the expiration date of an account by adding 6 months.