Class VariableMappingTransformer

java.lang.Object
io.camunda.zeebe.engine.processing.deployment.model.transformer.VariableMappingTransformer

public final class VariableMappingTransformer extends Object
Transform variable mappings into an expression.

The resulting expression is a FEEL context that has a similar structure as a JSON document. Each target of a mapping is a key in the context and the source of this mapping is the context value. The source expression can be any FEEL expression. A nested target expression is transformed into a nested context.

Variable mappings:

   source | target
   =======|=======
    x     | a
    y     | b.c
    z     | b.d
 
FEEL context expression:
   {
     a: x,
     b: {
       c: y,
       d: z
     }
   }
 

Output variable mappings differ from input mappings that the result variables needs to be merged with the existing variables if the variable is a JSON object. The merging is done, as a first draft, by calling the FEEL function 'put all()' and referencing the variable.

   {
     a: x,
     b: if (b = null)
        then {
          c: y,
          d: z
        }
        else put all(b, {
          c: y,
          d: z
       })
   }
 

There is one edge case, though, which was revealed in #9543: At the time of this writing the two branches of the if statement behave differently with respect to evaluation errors. The first branch (if the target variable is null) will propagate any error that occurs to the result of the evaluation. However, the second branch uses the put all(...) method which will transform any error in one of its parameters into a null as result. Therefore, the two branches will produce inconsistent results if there are errors in the expression.

To account for this the expression, was amended to

  if (targetVar != null and is defined(outputMappingResult))
    then put all(targetVar,outputMappingResult)
    else outputMappingResult
 

This is a workaround which hopefully can be removed in the future. It first checks whether the result of the output mapping is defined, and the target variable exists. If this is true, the put all(...) method is called to merge the result into the existing target variable. In all other cases the output mapping result is returned as is. If it evaluates to en error, this error is propagated to the final result of the evaluation

  • Constructor Details

    • VariableMappingTransformer

      public VariableMappingTransformer()
  • Method Details

    • transformInputMappings

      public io.camunda.zeebe.el.Expression transformInputMappings(Collection<? extends ZeebeMapping> inputMappings, io.camunda.zeebe.el.ExpressionLanguage expressionLanguage)
    • transformOutputMappings

      public io.camunda.zeebe.el.Expression transformOutputMappings(Collection<? extends ZeebeMapping> outputMappings, io.camunda.zeebe.el.ExpressionLanguage expressionLanguage)