Warm tip: This article is reproduced from serverfault.com, please click

Is there a Dataweave operator for Boolean validation of number falling between a given Range

发布于 2020-12-18 05:43:35

I have a flow which calls two sub-flows using flow-refs and a choice conditional flow router.

The first condition in the when section is #[payload.num > 1000]. When True this calls sub-flow-A.

when false, the NEXT when condition to check is #[(payload.num < 1000) and (payload.num > 0)]. When True, this calls sub-flow-B, else default.

Is there a way (any operator) to replace the usage #[(payload.num < 1000) and (payload.num > 0)] to something clean, short and simple ?

Questioner
Thinker-101
Viewed
0
Shoki 2020-12-23 06:42:03

There's no built-in operator for that, your best option is to create a dw module in your classpath with that funtion. It's just a dwl file with that function and others if you want and no body.

// src/main/resources/MyModule.dwl
%dw 2.0

fun isBetween(numToCheck: Number, low: Number, high: Number) = do {
  (numToCheck > low) and (numToCheck < high)
}

and then you can just call it like:

#[MyModule::isBetween(payload.num, 0, 1000)]