org.kie.api.definition.process.Node类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中org.kie.api.definition.process.Node类的一些代码示例,展示了Node类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node类的具体详情如下:
包路径:org.kie.api.definition.process.Node
类名称:Node

Node介绍

[英]A Node represents an activity in the process flow chart. Many different predefined nodes are supported out-of-the-box.
[中]节点表示流程图中的活动。许多不同的预定义节点都支持开箱即用。

代码示例

代码示例来源:origin: kiegroup/jbpm

public NodeInstance getNodeInstance(Node node, WorkflowProcessInstance processInstance, NodeInstanceContainer nodeInstanceContainer) {     
  try {
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) this.cls.newInstance();
    nodeInstance.setNodeId(node.getId());
    nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
    nodeInstance.setProcessInstance(processInstance);
    String uniqueId = (String) node.getMetaData().get("UniqueId");
    assert uniqueId != null : node.getClass().getSimpleName() + " [" + node.getName() + "] does not have a unique id.";
    if (uniqueId == null) {
      uniqueId = node.getId()+"";
    }
    nodeInstance.setMetaData("UniqueId", uniqueId);
    int level = ((org.jbpm.workflow.instance.NodeInstanceContainer)nodeInstanceContainer).getLevelForNode(uniqueId);
    nodeInstance.setLevel(level);
    return nodeInstance;
  } catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException("Unable to instantiate node: '"
      + this.cls.getName() + "':" + e.getMessage());
  }
}

代码示例来源:origin: kiegroup/jbpm

public final void trigger(NodeInstance from, String type) {
  boolean hidden = false;
  if (getNode().getMetaData().get("hidden") != null) {
    hidden = true;
    int level = ((org.jbpm.workflow.instance.NodeInstance)from).getLevel();
    ((org.jbpm.workflow.instance.NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(level);
    Collection<Connection> incoming = getNode().getIncomingConnections(type);
    for (Connection conn : incoming) {
      if (conn.getFrom().getId() == from.getNodeId()) {
        this.metaData.put("IncomingConnection", conn.getMetaData().get("UniqueId"));
        break;
  configureSla();
  InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  if (!hidden) {
    ((InternalProcessRuntime) kruntime.getProcessRuntime())
      .getProcessEventSupport().fireBeforeNodeTriggered(this, kruntime);
    ((InternalProcessRuntime) kruntime.getProcessRuntime())
      .getProcessEventSupport().fireAfterNodeTriggered(this, kruntime);

代码示例来源:origin: kiegroup/jbpm

protected void triggerNodeInstance(org.jbpm.workflow.instance.NodeInstance nodeInstance, String type, boolean fireEvents) {
  boolean hidden = false;
  if (getNode().getMetaData().get("hidden") != null) {
    hidden = true;
  }
  InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  if (!hidden && fireEvents) {
    ((InternalProcessRuntime) kruntime.getProcessRuntime())
      .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
  }
  // trigger next node
  nodeInstance.trigger(this, type);
  Collection<Connection> outgoing = getNode().getOutgoingConnections(type);
  for (Connection conn : outgoing) {
    if (conn.getTo().getId() == nodeInstance.getNodeId()) {
      this.metaData.put("OutgoingConnection", conn.getMetaData().get("UniqueId"));
      break;
    }
  }
  if (!hidden && fireEvents) {
    ((InternalProcessRuntime) kruntime.getProcessRuntime())
      .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
  }
}

代码示例来源:origin: kiegroup/jbpm

protected void addErrorMessage(RuleFlowProcess process,
                  Node node,
                  List<ProcessValidationError> errors,
                  String message) {
    String error = String.format("Node '%s' [%d] " + message,
                   node.getName(),
                   node.getId());
    errors.add(new ProcessValidationErrorImpl(process,
                         error));
  }
}

代码示例来源:origin: kiegroup/jbpm

public List<Node> getAutoStartNodes() {
  List<Node> nodes = Arrays.stream(getNodes())
      .filter(n -> n.getIncomingConnections().isEmpty() && "true".equalsIgnoreCase((String)n.getMetaData().get("customAutoStart")))
      .collect(Collectors.toList());
      
  return nodes;
}

代码示例来源:origin: kiegroup/jbpm

public static String getUniqueNodeId(Node node) {
  String result = (String) node.getMetaData().get("UniqueId");
  if (result != null) {
    return result;
  }
  result = node.getId() + "";
  NodeContainer nodeContainer = node.getNodeContainer();
  while (nodeContainer instanceof CompositeNode) {
    CompositeNode composite = (CompositeNode) nodeContainer;
    result = composite.getId() + "-" + result;
    nodeContainer = composite.getNodeContainer();
  }
  return "_" + result;
}

代码示例来源:origin: kiegroup/jbpm

public void assertNumOfOutgoingConnections(ProcessInstance process,
    String nodeName, int num) {
  assertNodeExists(process, nodeName);
  WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
  for (Node node : instance.getNodeContainer().getNodes()) {
    if (node.getName().equals(nodeName)) {
      if (node.getOutgoingConnections().size() != num) {
        fail("Expected outgoing connections: " + num + " - found "
            + node.getOutgoingConnections().size());
      } else {
        break;
      }
    }
  }
}

代码示例来源:origin: kiegroup/jbpm

public void assertNumOfIncommingConnections(ProcessInstance process,
    String nodeName, int num) {
  assertNodeExists(process, nodeName);
  WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
  for (Node node : instance.getNodeContainer().getNodes()) {
    if (node.getName().equals(nodeName)) {
      if (node.getIncomingConnections().size() != num) {
        fail("Expected incomming connections: " + num + " - found "
            + node.getIncomingConnections().size());
      } else {
        break;
      }
    }
  }
}

代码示例来源:origin: kiegroup/jbpm

protected void triggerCompleted(String type, boolean remove) {
  getExecutionErrorHandler().processed(this);
  Node node = getNode();
  if (node != null) {
    String uniqueId = (String) node.getMetaData().get("UniqueId");
    if( uniqueId == null ) { 
      uniqueId = ((NodeImpl) node).getUniqueId();
    ((WorkflowProcessInstanceImpl) processInstance).addCompletedNodeId(uniqueId);
    ((WorkflowProcessInstanceImpl) processInstance).getIterationLevels().remove(uniqueId);
  if ((getNodeInstanceContainer().getNodeInstance(getId()) == null)
      || (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE)) {
    return;
    ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer())
      .removeNodeInstance(this);
        if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
          return;
        throw new IllegalArgumentException( "Uncontrolled flow node could not find at least one valid outgoing connection " + getNode().getName() );
      connections = node.getOutgoingConnections(type); 
    boolean hidden = false;
    Node currentNode = getNode();
    if (currentNode != null && currentNode.getMetaData().get("hidden") != null) {
      hidden = true;

代码示例来源:origin: kiegroup/jbpm

public void validateAddOutgoingConnection(final String type, final Connection connection) {
  super.validateAddOutgoingConnection(type, connection);
  if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
    throw new IllegalArgumentException(
        "This type of node [" + connection.getFrom().getMetaData().get("UniqueId") + ", " + connection.getFrom().getName() 
        + "] only accepts default outgoing connection type!");
  }
}

代码示例来源:origin: kiegroup/jbpm

private static Node findNodeByIdOrUniqueIdInMetadata(NodeContainer nodeContainer, final String nodeRef, String errorMsg) {
  Node node = null;
  // try looking for a node with same "UniqueId" (in metadata)
  for (Node containerNode : nodeContainer.getNodes()) {
    if (nodeRef.equals(containerNode.getMetaData().get("UniqueId"))) {
      node = containerNode;
      break;
    }
  }
  if (node == null) {
    throw new IllegalArgumentException(errorMsg);
  }
  return node;
}

代码示例来源:origin: kiegroup/jbpm

Node topNode = nodeStack.pop();
  if (topNode.getName().compareTo(nodeName) == 0) {
    match = topNode;
    break;
    for (Node node : ((NodeContainer) topNode).getNodes()) {
      nodeStack.push(node);
  while (!(match.getNodeContainer() instanceof Process)) {
    id = ":" + match.getId() + id;
    match = (Node) match.getNodeContainer();
id = match.getId() + id;

代码示例来源:origin: kiegroup/jbpm

@SuppressWarnings("unchecked")
private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, String> nodeMapping, NodeContainer nodeContainer, EntityManager em) {
  for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) {
    if (nodeInstance.getNode() == null) {
      continue;
    String oldNodeId = (String) ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getMetaData().get("UniqueId");
    String newNodeId = nodeMapping.get(oldNodeId);
    if (newNodeId == null) {
      Boolean isHidden = (Boolean) ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getMetaData().get("hidden");
      if (isHidden != null && isHidden.booleanValue()) {
      upgradedNodeId = upgradedNode.getId();
    ((NodeInstanceImpl) nodeInstance).setNodeId(upgradedNodeId);
                          "where nodeInstanceId in (:ids) and processInstanceId = :processInstanceId");
        nodeLogQuery
              .setParameter("nodeId", (String) upgradedNode.getMetaData().get("UniqueId"))
              .setParameter("nodeName", VariableUtil.resolveVariable(upgradedNode.getName(), nodeInstance))
              .setParameter("nodeType", upgradedNode.getClass().getSimpleName())
              .setParameter("ids", nodeInstanceIds)

代码示例来源:origin: kiegroup/jbpm

timerInstances = new ArrayList<Long>(timers.size());
  TimerManager timerManager = ((InternalProcessRuntime)
    getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getTimerManager();
  for (Timer timer: timers.keySet()) {
    TimerInstance timerInstance = createTimerInstance(timer);
    boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda())
      .isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", name, getProcessInstance().getId());
    if (isActive) {
      getProcessInstance().getKnowledgeRuntime().signalEvent(name, null);
    } else {
      addActivationListener();
((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));

代码示例来源:origin: kiegroup/jbpm

private Node findNode(String nodeId) { 
  Node found = null;
  Queue<Node> allProcessNodes = new LinkedList<Node>();
  allProcessNodes.addAll(Arrays.asList( instance.getNodeContainer().getNodes() ));
  while( ! allProcessNodes.isEmpty() ) { 
    Node node = allProcessNodes.poll();
    if( nodeId.equals(node.getMetaData().get("UniqueId")) ) {
      found = node;
      break;
    }
    if( node instanceof NodeContainer ) { 
      allProcessNodes.addAll(Arrays.asList( ((NodeContainer) node).getNodes()));
    }
  }
  return found;
}

代码示例来源:origin: kiegroup/jbpm

((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
if ( selected == null ) {
  for ( final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
  ((NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(1);
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
outgoing = split.getDefaultOutgoingConnections();
boolean found = false;
  if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
    return;
List<Connection> connections = null;
if (node != null) {
  connections = node.getOutgoingConnections(type);
    if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
      return;
    if (getNode().getMetaData().get("hidden") != null) {
      hidden = true;
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    if (!hidden) {
      ((InternalProcessRuntime) kruntime.getProcessRuntime())
        .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);

代码示例来源:origin: kiegroup/jbpm

public void cancel() {
  boolean hidden = false;
  Node node = getNode();
  if (node != null && node.getMetaData().get("hidden") != null) {
    hidden = true;
  }
  if (!hidden) {
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    ((InternalProcessRuntime) kruntime.getProcessRuntime())
      .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
  }
  nodeInstanceContainer.removeNodeInstance(this);
  if (!hidden) {
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    ((InternalProcessRuntime) kruntime.getProcessRuntime())
        .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
  }
}

代码示例来源:origin: kiegroup/jbpm

protected boolean useAsync(final Node node) {
  if (!(node instanceof EventSubProcessNode) && (node instanceof ActionNode || node instanceof StateBasedNode || node instanceof EndNode)) {              
    boolean asyncMode = Boolean.parseBoolean((String)node.getMetaData().get("customAsync"));
    if (asyncMode) {
      return asyncMode;
    }
    
    return Boolean.parseBoolean((String)getKnowledgeRuntime().getEnvironment().get("AsyncMode"));
  }
  
  return false;
}

代码示例来源:origin: kiegroup/jbpm

public void assertNodeExists(ProcessInstance process, String... nodeNames) {
  WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
  List<String> names = new ArrayList<String>();
  for (String nodeName : nodeNames) {
    names.add(nodeName);
  }
  for (Node node : instance.getNodeContainer().getNodes()) {
    if (names.contains(node.getName())) {
      names.remove(node.getName());
    }
  }
  if (!names.isEmpty()) {
    String s = names.get(0);
    for (int i = 1; i < names.size(); i++) {
      s += ", " + names.get(i);
    }
    fail("Node(s) do not exist: " + s);
  }
}

代码示例来源:origin: kiegroup/jbpm

protected boolean checkNodes(Node currentNode, final Node lookFor, Set<Long> vistedNodes) {        
  List<Connection> connections = currentNode.getOutgoingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
  for (Connection conn : connections) {
    Node nextNode = conn.getTo();
    if (nextNode == null) {
      continue;
    } else if (vistedNodes.contains(nextNode.getId())) {
      continue;
    } else {
      vistedNodes.add(nextNode.getId());
      if (nextNode.getId() == lookFor.getId()) {                    
        return true;
      } 
              
      boolean nestedCheck = checkNodes(nextNode, lookFor, vistedNodes);
      if (nestedCheck) {
        return true;
      }
      
    }
  }
  
  return false;
}

相关文章