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

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

本文整理了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

  1. public NodeInstance getNodeInstance(Node node, WorkflowProcessInstance processInstance, NodeInstanceContainer nodeInstanceContainer) {
  2. try {
  3. NodeInstanceImpl nodeInstance = (NodeInstanceImpl) this.cls.newInstance();
  4. nodeInstance.setNodeId(node.getId());
  5. nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
  6. nodeInstance.setProcessInstance(processInstance);
  7. String uniqueId = (String) node.getMetaData().get("UniqueId");
  8. assert uniqueId != null : node.getClass().getSimpleName() + " [" + node.getName() + "] does not have a unique id.";
  9. if (uniqueId == null) {
  10. uniqueId = node.getId()+"";
  11. }
  12. nodeInstance.setMetaData("UniqueId", uniqueId);
  13. int level = ((org.jbpm.workflow.instance.NodeInstanceContainer)nodeInstanceContainer).getLevelForNode(uniqueId);
  14. nodeInstance.setLevel(level);
  15. return nodeInstance;
  16. } catch (Exception e) {
  17. e.printStackTrace();
  18. throw new RuntimeException("Unable to instantiate node: '"
  19. + this.cls.getName() + "':" + e.getMessage());
  20. }
  21. }

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

  1. public final void trigger(NodeInstance from, String type) {
  2. boolean hidden = false;
  3. if (getNode().getMetaData().get("hidden") != null) {
  4. hidden = true;
  5. int level = ((org.jbpm.workflow.instance.NodeInstance)from).getLevel();
  6. ((org.jbpm.workflow.instance.NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(level);
  7. Collection<Connection> incoming = getNode().getIncomingConnections(type);
  8. for (Connection conn : incoming) {
  9. if (conn.getFrom().getId() == from.getNodeId()) {
  10. this.metaData.put("IncomingConnection", conn.getMetaData().get("UniqueId"));
  11. break;
  12. configureSla();
  13. InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  14. if (!hidden) {
  15. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  16. .getProcessEventSupport().fireBeforeNodeTriggered(this, kruntime);
  17. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  18. .getProcessEventSupport().fireAfterNodeTriggered(this, kruntime);

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

  1. protected void triggerNodeInstance(org.jbpm.workflow.instance.NodeInstance nodeInstance, String type, boolean fireEvents) {
  2. boolean hidden = false;
  3. if (getNode().getMetaData().get("hidden") != null) {
  4. hidden = true;
  5. }
  6. InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  7. if (!hidden && fireEvents) {
  8. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  9. .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
  10. }
  11. // trigger next node
  12. nodeInstance.trigger(this, type);
  13. Collection<Connection> outgoing = getNode().getOutgoingConnections(type);
  14. for (Connection conn : outgoing) {
  15. if (conn.getTo().getId() == nodeInstance.getNodeId()) {
  16. this.metaData.put("OutgoingConnection", conn.getMetaData().get("UniqueId"));
  17. break;
  18. }
  19. }
  20. if (!hidden && fireEvents) {
  21. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  22. .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
  23. }
  24. }

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

  1. protected void addErrorMessage(RuleFlowProcess process,
  2. Node node,
  3. List<ProcessValidationError> errors,
  4. String message) {
  5. String error = String.format("Node '%s' [%d] " + message,
  6. node.getName(),
  7. node.getId());
  8. errors.add(new ProcessValidationErrorImpl(process,
  9. error));
  10. }
  11. }

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

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

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

  1. public static String getUniqueNodeId(Node node) {
  2. String result = (String) node.getMetaData().get("UniqueId");
  3. if (result != null) {
  4. return result;
  5. }
  6. result = node.getId() + "";
  7. NodeContainer nodeContainer = node.getNodeContainer();
  8. while (nodeContainer instanceof CompositeNode) {
  9. CompositeNode composite = (CompositeNode) nodeContainer;
  10. result = composite.getId() + "-" + result;
  11. nodeContainer = composite.getNodeContainer();
  12. }
  13. return "_" + result;
  14. }

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

  1. public void assertNumOfOutgoingConnections(ProcessInstance process,
  2. String nodeName, int num) {
  3. assertNodeExists(process, nodeName);
  4. WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
  5. for (Node node : instance.getNodeContainer().getNodes()) {
  6. if (node.getName().equals(nodeName)) {
  7. if (node.getOutgoingConnections().size() != num) {
  8. fail("Expected outgoing connections: " + num + " - found "
  9. + node.getOutgoingConnections().size());
  10. } else {
  11. break;
  12. }
  13. }
  14. }
  15. }

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

  1. public void assertNumOfIncommingConnections(ProcessInstance process,
  2. String nodeName, int num) {
  3. assertNodeExists(process, nodeName);
  4. WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
  5. for (Node node : instance.getNodeContainer().getNodes()) {
  6. if (node.getName().equals(nodeName)) {
  7. if (node.getIncomingConnections().size() != num) {
  8. fail("Expected incomming connections: " + num + " - found "
  9. + node.getIncomingConnections().size());
  10. } else {
  11. break;
  12. }
  13. }
  14. }
  15. }

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

  1. protected void triggerCompleted(String type, boolean remove) {
  2. getExecutionErrorHandler().processed(this);
  3. Node node = getNode();
  4. if (node != null) {
  5. String uniqueId = (String) node.getMetaData().get("UniqueId");
  6. if( uniqueId == null ) {
  7. uniqueId = ((NodeImpl) node).getUniqueId();
  8. ((WorkflowProcessInstanceImpl) processInstance).addCompletedNodeId(uniqueId);
  9. ((WorkflowProcessInstanceImpl) processInstance).getIterationLevels().remove(uniqueId);
  10. if ((getNodeInstanceContainer().getNodeInstance(getId()) == null)
  11. || (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE)) {
  12. return;
  13. ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer())
  14. .removeNodeInstance(this);
  15. if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
  16. return;
  17. throw new IllegalArgumentException( "Uncontrolled flow node could not find at least one valid outgoing connection " + getNode().getName() );
  18. connections = node.getOutgoingConnections(type);
  19. boolean hidden = false;
  20. Node currentNode = getNode();
  21. if (currentNode != null && currentNode.getMetaData().get("hidden") != null) {
  22. hidden = true;

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

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

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

  1. private static Node findNodeByIdOrUniqueIdInMetadata(NodeContainer nodeContainer, final String nodeRef, String errorMsg) {
  2. Node node = null;
  3. // try looking for a node with same "UniqueId" (in metadata)
  4. for (Node containerNode : nodeContainer.getNodes()) {
  5. if (nodeRef.equals(containerNode.getMetaData().get("UniqueId"))) {
  6. node = containerNode;
  7. break;
  8. }
  9. }
  10. if (node == null) {
  11. throw new IllegalArgumentException(errorMsg);
  12. }
  13. return node;
  14. }

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

  1. Node topNode = nodeStack.pop();
  2. if (topNode.getName().compareTo(nodeName) == 0) {
  3. match = topNode;
  4. break;
  5. for (Node node : ((NodeContainer) topNode).getNodes()) {
  6. nodeStack.push(node);
  7. while (!(match.getNodeContainer() instanceof Process)) {
  8. id = ":" + match.getId() + id;
  9. match = (Node) match.getNodeContainer();
  10. id = match.getId() + id;

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

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

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

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

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

  1. private Node findNode(String nodeId) {
  2. Node found = null;
  3. Queue<Node> allProcessNodes = new LinkedList<Node>();
  4. allProcessNodes.addAll(Arrays.asList( instance.getNodeContainer().getNodes() ));
  5. while( ! allProcessNodes.isEmpty() ) {
  6. Node node = allProcessNodes.poll();
  7. if( nodeId.equals(node.getMetaData().get("UniqueId")) ) {
  8. found = node;
  9. break;
  10. }
  11. if( node instanceof NodeContainer ) {
  12. allProcessNodes.addAll(Arrays.asList( ((NodeContainer) node).getNodes()));
  13. }
  14. }
  15. return found;
  16. }

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

  1. ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
  2. if ( selected == null ) {
  3. for ( final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
  4. ((NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(1);
  5. ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
  6. outgoing = split.getDefaultOutgoingConnections();
  7. boolean found = false;
  8. if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
  9. return;
  10. List<Connection> connections = null;
  11. if (node != null) {
  12. connections = node.getOutgoingConnections(type);
  13. if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
  14. return;
  15. if (getNode().getMetaData().get("hidden") != null) {
  16. hidden = true;
  17. InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  18. if (!hidden) {
  19. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  20. .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);

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

  1. public void cancel() {
  2. boolean hidden = false;
  3. Node node = getNode();
  4. if (node != null && node.getMetaData().get("hidden") != null) {
  5. hidden = true;
  6. }
  7. if (!hidden) {
  8. InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  9. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  10. .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
  11. }
  12. nodeInstanceContainer.removeNodeInstance(this);
  13. if (!hidden) {
  14. InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  15. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  16. .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
  17. }
  18. }

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

  1. protected boolean useAsync(final Node node) {
  2. if (!(node instanceof EventSubProcessNode) && (node instanceof ActionNode || node instanceof StateBasedNode || node instanceof EndNode)) {
  3. boolean asyncMode = Boolean.parseBoolean((String)node.getMetaData().get("customAsync"));
  4. if (asyncMode) {
  5. return asyncMode;
  6. }
  7. return Boolean.parseBoolean((String)getKnowledgeRuntime().getEnvironment().get("AsyncMode"));
  8. }
  9. return false;
  10. }

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

  1. public void assertNodeExists(ProcessInstance process, String... nodeNames) {
  2. WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
  3. List<String> names = new ArrayList<String>();
  4. for (String nodeName : nodeNames) {
  5. names.add(nodeName);
  6. }
  7. for (Node node : instance.getNodeContainer().getNodes()) {
  8. if (names.contains(node.getName())) {
  9. names.remove(node.getName());
  10. }
  11. }
  12. if (!names.isEmpty()) {
  13. String s = names.get(0);
  14. for (int i = 1; i < names.size(); i++) {
  15. s += ", " + names.get(i);
  16. }
  17. fail("Node(s) do not exist: " + s);
  18. }
  19. }

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

  1. protected boolean checkNodes(Node currentNode, final Node lookFor, Set<Long> vistedNodes) {
  2. List<Connection> connections = currentNode.getOutgoingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
  3. for (Connection conn : connections) {
  4. Node nextNode = conn.getTo();
  5. if (nextNode == null) {
  6. continue;
  7. } else if (vistedNodes.contains(nextNode.getId())) {
  8. continue;
  9. } else {
  10. vistedNodes.add(nextNode.getId());
  11. if (nextNode.getId() == lookFor.getId()) {
  12. return true;
  13. }
  14. boolean nestedCheck = checkNodes(nextNode, lookFor, vistedNodes);
  15. if (nestedCheck) {
  16. return true;
  17. }
  18. }
  19. }
  20. return false;
  21. }

相关文章