Class SwitchExecutor
java.lang.Object
ai.nervemind.app.executor.SwitchExecutor
- All Implemented Interfaces:
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 checknotEquals/!=/neq- Inequality checkcontains- String contains or list membershipnotContains- Negation of containsgreaterThan/>/gtlessThan/</ltgreaterThanOrEquals/>=/gtelessThanOrEquals/<=/ltestartsWith- String prefix checkendsWith- String suffix checkisEmpty- Null, empty string, or empty collectionisNotEmpty- Has valuematches/regex- Regular expression matchisNull- Check if value is nullisNotNull- Check if value is not nullin- Check if value is in a listnotIn- 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexecute(ai.nervemind.common.domain.Node node, Map<String, Object> input, ExecutionService.ExecutionContext context) Executes the business logic for this node type.Unique identifier for the node type this executor handles.
-
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:NodeExecutorExecutes the business logic for this node type.- Specified by:
executein interfaceNodeExecutor- Parameters:
node- The node definition containing parameters and configuration. UseNode.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: Returningnullis treated as an empty map.
-
getNodeType
Description copied from interface:NodeExecutorUnique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.- Specified by:
getNodeTypein interfaceNodeExecutor- Returns:
- The unique type string (e.g., "httpRequest", "llmChat").
-