bpm_engine_runtime/
gateway.rs1use std::collections::HashMap;
4
5use bpm_engine_core::{EdgeCondition, Node, NodeId};
6
7pub trait GatewayEvaluator {
8 fn evaluate(&self, node: &Node, variables: &HashMap<String, String>) -> Vec<NodeId>;
9}
10
11pub struct ExclusiveGatewayEvaluator;
12
13impl GatewayEvaluator for ExclusiveGatewayEvaluator {
14 fn evaluate(&self, node: &Node, variables: &HashMap<String, String>) -> Vec<NodeId> {
15 let mut default_target: Option<NodeId> = None;
16 for edge in &node.outgoing_edges {
17 match &edge.condition {
18 None => return vec![edge.target],
19 Some(EdgeCondition::Default) => default_target = Some(edge.target),
20 Some(EdgeCondition::VariableEq { key, value }) => {
21 if variables.get(key) == Some(value) {
22 return vec![edge.target];
23 }
24 }
25 Some(EdgeCondition::Expression(expr)) => {
26 if super::el::eval_condition(expr, variables).unwrap_or(false) {
27 return vec![edge.target];
28 }
29 }
30 }
31 }
32 default_target.map(|t| vec![t]).unwrap_or_default()
33 }
34}