Expressions

Introduction

The JSLEE uses a custom expression engine for the selection of specific outcomes based on incoming data. An expression is a logical “one-line” term that will, based on input data, provide an output value (normally a boolean value). The expression engine will:

  1. Determine which route should be used for the Diameter Agent’s relay functionality.
  2. Determine whether a notification event received by the notification service matches to a template handled by the notification service.

An expression may be as simple as true, which evaluates in all cases to true, or more complex, such as:

notification.type == \"expiry_3d\" || notification.type == \"expiry_2d\" 

which compares an incoming notification type against expiry_3d and expiry_2d and returns true when the notification type is one of either of these values.

(In)Equality

Two terms may be tested for equality within an expression using double-equals, ==. For example: context == 1 will compare the value of the field context (whose value and source will be determined by where the expression is being used) with the integer value 1. If the left and right value of the == equal, the expression returns true.

!= may be used to compare for inequality.

Boolean Operators

An expression may consist of one or more sub-expressions combined with logical operators. The following logical operators are valid in expressions:

Parenthesis can be used to group sub-expressions, and parenthesis are required to determine the correct order of evaluation. The expression engine does not have an implicit rank for evaluation across boolean operators. Instead, expressions will evaluate left to right.

Strings

Static strings are defined within an expression by using double-quotes around the string. For example, context == "450" will compare the string value of context against the string 450. Note that single quotes cannot be used.

Many expressions are defined within JSON. The enclosing quotes must be escaped to do this:

{
  "condition": "context == \"450\""
}

Numbers

Integer numeric values are defined using an unquoted string of digits 0-9:

{
  "condition": "context == 450"
}

will compare the value of context against the numeric value 450.

Regex

Regular expressions are defined within an expression by using a forward-slash at the start and end of the regular expression:

{
  "condition": "context == /^642[0-9]+$/"
}

will complete a regex match of the string value of context against the regex expression ^642[0-9]+$.

Note: Only Java’s Pattern regex is supported by the expression engine.

Identifiers

Identifiers within an expression are unquoted strings consisting of the following character ranges:

Identifiers must begin with a character a-z (or A-Z). For example 9hello is not a valid identifier, whereas hello9 is.

Expressions may not assign values to identifiers, only use identifiers to retrieve dynamic information from the running JSLEE for the situation being evaluated. What identifiers are available will be wholly determined by the way the expression is being used.

All dynamic data is provided to expressions within a structured JSON hierarchy. To access subfields within dynamic data provided, use a dot. For example, notification.type within an expression for the interaction service will access the type field of the incoming notification.

Lists

A list of values are defined using square brackets:

context in [450, 500, 506]

The list of values may be a combination of strings, integers or more complex expressions (including identifiers). The in operator will iterate over the list and return true if the left-hand value exists in the right-hand list.

Ternary Operator

The standard C ternary operator may also be used:

notification.type == 450 ? notification.subtype : "default"

Method calls:

Methods are called within expressions using the following method call syntax:

mymethod()

A method may take a single argument:

mymethod(notification.type)

and methods may be within a structure accessed using the dot operator:

context.mymethod()

As with identifiers, expressions available are determined by the context in which the expression is called. The interaction manager provides different methods to the Diameter Agent.