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()); } }
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);
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); } }
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; }
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; }
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; } } } }
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; } } } }
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;
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!"); } }
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; }
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;
@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)
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"));
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; }
((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);
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); } }
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; }
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); } }
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; }