brainslug.flow.execution.impl.DefaultNodeExecutor Maven / Gradle / Ivy
package brainslug.flow.execution.impl;
import brainslug.flow.execution.*;
import brainslug.flow.model.FlowEdgeDefinition;
import brainslug.flow.model.FlowNodeDefinition;
import brainslug.flow.model.Identifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class DefaultNodeExecutor implements FlowNodeExecutor {
protected TokenStore tokenStore;
DefaultNodeExecutor withTokenStore(TokenStore tokenStore) {
this.tokenStore = tokenStore;
return this;
}
@Override
public List execute(T node, ExecutionContext execution) {
consumeAllNodeTokens(execution.getTrigger().getInstanceId(), execution.getTrigger().getNodeId());
return takeAll(node);
}
protected void consumeAllNodeTokens(Identifier instanceId, Identifier nodeId) {
Map> nodeTokens = tokenStore.getNodeTokens(nodeId, instanceId).groupedBySourceNode();
for (List tokens : nodeTokens.values()) {
removeTokens(instanceId, tokens);
}
}
protected void removeTokens(Identifier instanceId, List tokens) {
for (Token token : tokens) {
tokenStore.removeToken(instanceId, token.getId());
}
}
protected List takeAll(FlowNodeDefinition> node) {
List next = new ArrayList();
for (FlowEdgeDefinition edge : node.getOutgoing()) {
next.add(edge.getTarget());
}
return next;
}
protected List takeNone() {
return new ArrayList();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy