Class SwitchExecutor

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

@Component public class SwitchExecutor extends Object implements NodeExecutor
Executor for the "switch" node type - provides multi-branch conditional routing.

Routes workflow execution to different branches based on evaluating a set of rules against input data. Unlike IfExecutor which provides binary branching, SwitchExecutor supports multiple target branches with complex condition matching.

Node Parameters

rules
List of rule objects with conditions (default: [])
fallbackOutput
Output branch when no rules match (default: "fallback")

Rule Structure

Each rule in the rules list has:

  • name - Output branch name
  • conditions - List of condition objects
  • combineWith - "and" or "or" (how to combine conditions, default: "and")

Condition Structure

Each condition object has the following properties:

  • field - Field name from input data to evaluate
  • operator - Comparison operator (see below)
  • value - Value to compare against

Supported Operators

  • equals / == / eq - Equality check
  • notEquals / != / neq - Inequality check
  • contains - String contains or list membership
  • notContains - Negation of contains
  • greaterThan / > / gt
  • lessThan / < / lt
  • greaterThanOrEquals / >= / gte
  • lessThanOrEquals / <= / lte
  • startsWith - String prefix check
  • endsWith - String suffix check
  • isEmpty - Null, empty string, or empty collection
  • isNotEmpty - Has value
  • matches / regex - Regular expression match
  • isNull - Check if value is null
  • isNotNull - Check if value is not null
  • in - Check if value is in a list
  • notIn - Check if value is not in a list

Output Data

The executor adds the following keys to the output:

  • _branch - The name of the selected output branch
  • _matchedRuleIndex - Index of the matched rule (-1 if none)
  • _matched - Boolean indicating if any rule matched
  • _selectedOutput - Name of the selected output branch (legacy)
See Also:
  • Constructor Details

    • SwitchExecutor

      public SwitchExecutor()
      Default constructor for Spring.
  • 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").