All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brainslug.flow.execution.impl.JoinNodeExecutor Maven / Gradle / Ivy

There is a newer version: 0.21
Show newest version
package brainslug.flow.execution.impl;

import brainslug.flow.execution.ExecutionContext;
import brainslug.flow.execution.Token;
import brainslug.flow.model.FlowEdgeDefinition;
import brainslug.flow.model.FlowNodeDefinition;
import brainslug.flow.model.Identifier;
import brainslug.flow.model.JoinDefinition;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class JoinNodeExecutor extends DefaultNodeExecutor {

  @Override
  public List execute(JoinDefinition joinDefinition, ExecutionContext execution) {
    Identifier instanceId = execution.getTrigger().getInstanceId();
    Map> joinTokens = tokenStore.getNodeTokens(joinDefinition.getId(), instanceId).groupedBySourceNode();
    List consumedTokens = new ArrayList();
    for (FlowEdgeDefinition edge : joinDefinition.getIncoming()) {
      List edgeTokens = joinTokens.get(edge.getSource().getId());
      if (edgeTokens == null || edgeTokens.isEmpty()) {
        return takeNone();
      } else {
        consumedTokens.addAll(edgeTokens);
      }
    }
    removeTokens(instanceId, consumedTokens);
    return takeAll(joinDefinition);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy