'%s:%s'.format([foo, bar])
MidPoint Expression Language Tips and Recommendations
|
MidPoint Expression Language feature
This page describes configuration of MidPoint Expression Language midPoint feature.
Please see the feature page for more details.
|
MidPoint Expression Language (MEL) is an expression language, designed to support customization of midPoint functionality in an easy-to-use and secure way. This page lists miscellaneous tips and recommendations for writing MEL expressions.
Formatting
Use format() function to format data into strings instead of string concatenation.
I.e. use this:
instead of this:
foo + ':' + bar
String concatenation using the plus (+) operator is quite fragile method to construct strings in Common Expression Language (CEL).
This method is susceptible to problems with various data types, null values and so on.
On the other hand, the format() method handles all such details, making the formatting code much more robust.
When formatting timestamps, use specialized timestamp functions, such as format.strftime():
// Returns formatted time, e.g. `11/02/26 09:32:15`
format.strftime(ts, '%d/%m/%Y %H:%M:%S')
Overall, the format extension of MEL provides may useful functions for string formatting and parsing.
Single-Valued and Multi-Valued Data
CEL and therefore MEL makes a strict distinction between single-valued (scalar) and multi-valued (list/array) data. Functions often require multi-valued (list) arguments. Also, some functions return list values. Therefore, it is often necessary to convert single-valued and multi-valued (list) data.
Correct method to convert list (multi-valued data) to a single value is to use single() function:
single(['foo']) // Returns 'foo'
Primary purpose of single() function is conversion of list to single value.
Moreover, it does the conversion in a safe way.
Error is raised in case that the argument is a list with more than one value.
The single() function returns null value in a robust way, handling all the valid argument values such as empty list, null and empty optional.
On the other hand, other methods (such as x[0]) does not provide such robustness.
Correct method to convert single value to list (multi-valued data) is use of list() function:
list('foo') // Returns ['foo']
list(['foo']) // Returns ['foo']
The list() function always returns list.
If a single-valued (scalar_ argument is provided, it returns a single-element list containing that argument.
If a list is provided as argument, the same list is returned.
Hence, the list() function can be used to make sure that list is provided in context where list arguments are required.