Class IfExecutor

java.lang.Object
ai.nervemind.app.executor.IfExecutor
All Implemented Interfaces:
NodeExecutor

@Component public class IfExecutor extends Object implements NodeExecutor
Executor for the "if" node type - provides conditional branching in workflows.

Evaluates a condition expression and routes execution to different branches based on the result. Uses Spring Expression Language (SpEL) for condition evaluation with support for template interpolation.

Node Parameters

If node configuration parameters
Parameter Type Default Description
condition String "true" SpEL expression to evaluate

Template Variables

Use {{ variableName }} syntax to reference input data:

  • {{ status }} == 'active' - Simple variable comparison
  • {{ data.count }} > 10 - Nested path access
  • {{ items[0].value }} - Array index access

SpEL Expression Examples

  • {{ price }} > 100 and {{ stock }} > 0 - Logical AND
  • {{ status }} == 'active' or {{ status }} == 'pending' - Logical OR
  • #input['response'] != null - Null check with SpEL syntax

Output Data

Output keys added by this executor
Key Type Description
conditionResult Boolean The evaluated condition result
branch String "true" or "false" - indicates which branch to take
See Also:
  • Constructor Details

    • IfExecutor

      public IfExecutor()
      Default constructor.
  • Method Details

    • execute

      public Map<String,Object> execute(ai.nervemind.common.domain.Node node, Map<String,Object> input, ExecutionService.ExecutionContext context)
      Description copied from interface: NodeExecutor
      Executes the business logic for this node type.
      Specified by:
      execute in interface NodeExecutor
      Parameters:
      node - The node definition containing parameters and configuration. Use Node.parameters() to access user settings.
      input - Combined output from all upstream nodes that connected to this node. For simple flows, this contains the direct predecessor's output. For merge nodes, it contains combined data.
      context - Verification context providing access to workflow-scoped services, logger, and execution metadata.
      Returns:
      A Map containing the results of this node's execution. Keys in this map become available variables for downstream nodes.
      Note: Returning null is treated as an empty map.
    • getNodeType

      public String getNodeType()
      Description copied from interface: NodeExecutor
      Unique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.
      Specified by:
      getNodeType in interface NodeExecutor
      Returns:
      The unique type string (e.g., "httpRequest", "llmChat").