or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

data-providers.mdexpressions.mdform-management.mdindex.mdintegration-extensions.mdmodels-services.mdsecurity-validation.mdstorage-io.mdtemplates.md

expressions.mddocs/

0

# Expression Engine

1

2

Rule evaluation system with support for complex conditional expressions, calculations, and form field interactions.

3

4

## Capabilities

5

6

### Expression Evaluation

7

8

Core expression evaluation interfaces for processing mathematical and logical expressions.

9

10

```java { .api }

11

interface Expression<T> {

12

/**

13

* Evaluates the expression and returns the result

14

*/

15

T evaluate() throws ExpressionEvaluationException;

16

17

/**

18

* Returns the set of variable names referenced in this expression

19

*/

20

Set<String> getVariableNames();

21

22

/**

23

* Sets the value of a variable used in the expression

24

*/

25

void setVariable(String name, Object value);

26

}

27

28

interface ExpressionFactory {

29

/**

30

* Creates an expression from a string representation

31

*/

32

<T> Expression<T> createExpression(String expressionString);

33

34

/**

35

* Creates a boolean expression for conditional logic

36

*/

37

Expression<Boolean> createBooleanExpression(String expressionString);

38

}

39

40

class ExpressionEvaluationException extends Exception {

41

ExpressionEvaluationException(String message);

42

ExpressionEvaluationException(String message, Throwable cause);

43

}

44

```

45

46

### Expression Model

47

48

Data model classes for representing and manipulating expressions.

49

50

```java { .api }

51

class ExpressionModel {

52

String getExpressionString();

53

void setExpressionString(String expressionString);

54

Map<String, Object> getVariables();

55

void setVariable(String name, Object value);

56

}

57

58

class ExpressionContext {

59

Locale getLocale();

60

Map<String, Object> getVariables();

61

long getCompanyId();

62

long getGroupId();

63

long getUserId();

64

}

65

```

66

67

## Usage Examples

68

69

### Creating and Evaluating Expressions

70

71

```java

72

@Component

73

public class ExpressionExample {

74

75

@Reference

76

private ExpressionFactory expressionFactory;

77

78

public void evaluateFormRules() throws ExpressionEvaluationException {

79

// Create a boolean expression for field visibility

80

Expression<Boolean> visibilityExpression = expressionFactory.createBooleanExpression(

81

"getValue('country') == 'US' && getValue('age') >= 18"

82

);

83

84

// Set field values

85

visibilityExpression.setVariable("country", "US");

86

visibilityExpression.setVariable("age", 25);

87

88

// Evaluate the expression

89

boolean isVisible = visibilityExpression.evaluate();

90

System.out.println("Field should be visible: " + isVisible);

91

92

// Create a calculation expression

93

Expression<Number> calculationExpression = expressionFactory.createExpression(

94

"getValue('quantity') * getValue('price') * (1 + getValue('tax_rate'))"

95

);

96

97

calculationExpression.setVariable("quantity", 5);

98

calculationExpression.setVariable("price", 19.99);

99

calculationExpression.setVariable("tax_rate", 0.08);

100

101

Number totalCost = calculationExpression.evaluate();

102

System.out.println("Total cost: $" + totalCost);

103

}

104

}

105

```

106

107

## Types

108

109

### Expression Constants

110

111

```java { .api }

112

class ExpressionConstants {

113

// Built-in functions available in expressions

114

String FUNCTION_BETWEEN = "between";

115

String FUNCTION_CONTAINS = "contains";

116

String FUNCTION_GET_VALUE = "getValue";

117

String FUNCTION_IS_EMAIL_ADDRESS = "isEmailAddress";

118

String FUNCTION_IS_URL = "isURL";

119

String FUNCTION_MATCH = "match";

120

String FUNCTION_SUM = "sum";

121

122

// Expression operators

123

String OPERATOR_AND = "&&";

124

String OPERATOR_OR = "||";

125

String OPERATOR_NOT = "!";

126

String OPERATOR_EQUALS = "==";

127

String OPERATOR_NOT_EQUALS = "!=";

128

String OPERATOR_GREATER_THAN = ">";

129

String OPERATOR_LESS_THAN = "<";

130

}

131

```