public NodeInstance getNodeInstance(long nodeInstanceId, boolean recursive) { for (NodeInstance nodeInstance: getNodeInstances(recursive)) { if (nodeInstance.getId() == nodeInstanceId) { return nodeInstance; } } return null; }
public JBPMMessages.ProcessInstance.NodeInstance writeNodeInstance(MarshallerWriteContext context, NodeInstance nodeInstance) throws IOException { JBPMMessages.ProcessInstance.NodeInstance.Builder _node = JBPMMessages.ProcessInstance.NodeInstance.newBuilder() .setId( nodeInstance.getId() ) .setNodeId( nodeInstance.getNodeId()) .setLevel(((org.jbpm.workflow.instance.NodeInstance)nodeInstance).getLevel()) .setSlaCompliance(((org.jbpm.workflow.instance.NodeInstance)nodeInstance).getSlaCompliance()); if (((org.jbpm.workflow.instance.NodeInstance)nodeInstance).getSlaDueDate() != null) { _node.setSlaDueDate(((org.jbpm.workflow.instance.NodeInstance)nodeInstance).getSlaDueDate().getTime()); } if (((org.jbpm.workflow.instance.NodeInstance)nodeInstance).getSlaTimerId() != null) { _node.setSlaTimerId(((org.jbpm.workflow.instance.NodeInstance)nodeInstance).getSlaTimerId()); } _node.setContent( writeNodeInstanceContent( _node, nodeInstance, context ) ); return _node.build(); }
@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); nodeInstanceIdQuery .setParameter("oldNodeId", oldNodeId) .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId()); "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) .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());
public NodeInstance getFirstNodeInstance(final long nodeId) { for (final Iterator<NodeInstance> iterator = this.nodeInstances .iterator(); iterator.hasNext();) { final NodeInstance nodeInstance = iterator.next(); if (nodeInstance.getNodeId() == nodeId && nodeInstance.getLevel() == getCurrentLevel()) { return nodeInstance; } } return null; }
public NodeInstance getFirstNodeInstance(final long nodeId) { for ( final Iterator<NodeInstance> iterator = this.nodeInstances.iterator(); iterator.hasNext(); ) { final NodeInstance nodeInstance = iterator.next(); if ( nodeInstance.getNodeId() == nodeId && nodeInstance.getLevel() == getCurrentLevel()) { return nodeInstance; } } return null; }
@SuppressWarnings("unchecked") protected void triggerSelectedNode(Node node, Object event) { NodeInstance nodeInstance = getNodeInstance(node); if (event != null) { Map<String, Object> dynamicParams = new HashMap<>(); if (event instanceof Map) { dynamicParams.putAll((Map<String, Object>) event); } else { dynamicParams.put("Data", event); } ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).setDynamicParameters(dynamicParams); } ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, NodeImpl.CONNECTION_DEFAULT_TYPE); }
@SuppressWarnings("unchecked") public void signalEvent(String type, Object event) { logger.debug("Signal {} received with data {} in process instance {}", type, event, getId()); synchronized (this) { if (getState() != ProcessInstance.STATE_ACTIVE) { return; TimerInstance timer = (TimerInstance) event; if (timer.getId() == slaTimerId) { handleSLAViolation(); dynamicNodeInstance.signalEvent(type, event); } else { List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView); if (nodeInstances != null && !nodeInstances.isEmpty()) { for (NodeInstance nodeInstance : nodeInstances) { if (((org.jbpm.workflow.core.WorkflowProcess) getWorkflowProcess()).isDynamic()) { for (Node node : getWorkflowProcess().getNodes()) { if (type.equals(node.getName()) && node.getIncomingConnections().isEmpty()) { NodeInstance nodeInstance = getNodeInstance(node); if (event != null) { dynamicParams.put("Data", event); ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).setDynamicParameters(dynamicParams); ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, NodeImpl.CONNECTION_DEFAULT_TYPE);
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;
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); } }
private static void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) { for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) { String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId(); Long newNodeId = nodeMapping.get(oldNodeId); if (newNodeId == null) { newNodeId = nodeInstance.getNodeId(); } // clean up iteration levels for removed (old) nodes Map<String, Integer> iterLevels = ((WorkflowProcessInstanceImpl) nodeInstance.getProcessInstance()).getIterationLevels(); String uniqueId = (String) ((NodeImpl) nodeInstance.getNode()).getMetaData("UniqueId"); iterLevels.remove(uniqueId); // and now set to new node id ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId); if (nodeInstance instanceof NodeInstanceContainer) { updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping); } } }
List<Connection> connections = nodeAndType.getNode().getIncomingConnections(nodeAndType.getType()); for (Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) { Connection connection = iterator.next(); if ((connection.getFrom() instanceof CompositeNode.CompositeNodeStart) && (from == null || ((CompositeNode.CompositeNodeStart) connection.getFrom()).getInNode().getId() == from.getNodeId())) { NodeInstance nodeInstance = getNodeInstance(connection.getFrom()); ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, nodeAndType.getType()); return; NodeInstance nodeInstance = getNodeInstance(startNode); ((org.jbpm.workflow.instance.NodeInstance) nodeInstance) .trigger(null, null); found = true;
if (getNode().getMetaData().get("hidden") != null) { hidden = true; .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime); ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this); if (getEndNode().isTerminate()) { if (getNodeInstanceContainer() instanceof CompositeNodeInstance) { } else { while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) { ((org.jbpm.workflow.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel(); ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null); ((NodeInstanceContainer) getNodeInstanceContainer()).setState( ProcessInstance.STATE_COMPLETED );
((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; List<Connection> connections = null; if (node != null) { connections = node.getOutgoingConnections(type); if (getNode().getMetaData().get("hidden") != null) { hidden = true; .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime); ((org.jbpm.workflow.instance.NodeInstance) entry.getKey()).trigger(this, entry.getValue()); if (!hidden) { ((InternalProcessRuntime) kruntime.getProcessRuntime())
public void nodeInstanceCompleted(NodeInstance nodeInstance, String outType) { Node nodeInstanceNode = nodeInstance.getNode(); if( nodeInstanceNode != null ) { Object compensationBoolObj = nodeInstanceNode.getMetaData().get("isForCompensation"); boolean isForCompensation = compensationBoolObj == null ? false : ((Boolean) compensationBoolObj); if( isForCompensation ) { return; } } if (nodeInstance instanceof FaultNodeInstance || nodeInstance instanceof EndNodeInstance || ((org.jbpm.workflow.core.WorkflowProcess) getWorkflowProcess()).isDynamic() || nodeInstance instanceof CompositeNodeInstance) { if (((org.jbpm.workflow.core.WorkflowProcess) getProcess()).isAutoComplete()) { if (canComplete()) { setState(ProcessInstance.STATE_COMPLETED); } } } else { throw new IllegalArgumentException( "Completing a node instance that has no outgoing connection is not supported."); } }
public void nodeInstanceCompleted(NodeInstance nodeInstance, String outType) { Node nodeInstanceNode = nodeInstance.getNode(); if( nodeInstanceNode != null ) { Object compensationBoolObj = nodeInstanceNode.getMetaData().get("isForCompensation"); boolean isForCompensation = compensationBoolObj == null ? false : ((Boolean) compensationBoolObj); if( isForCompensation ) { return; } } if (nodeInstance instanceof FaultNodeInstance || nodeInstance instanceof EndNodeInstance || nodeInstance instanceof EventSubProcessNodeInstance ) { if (getCompositeNode().isAutoComplete()) { if (nodeInstances.isEmpty()) { triggerCompleted( org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE); } } } else { throw new IllegalArgumentException( "Completing a node instance that has no outgoing connection not supported."); } }
private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) { for (NodeInstance nodeInstance: nodeInstanceContainer.getNodeInstances()) { String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId(); Long newNodeId = nodeMapping.get(oldNodeId); if (newNodeId == null) { newNodeId = nodeInstance.getNodeId(); } ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId); if (nodeInstance instanceof NodeInstanceContainer) { updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping); } } }
if (((org.jbpm.workflow.instance.NodeInstance)nodeInstance).getLevel() != getLevel()) { continue; Node node = nodeInstance.getNode(); Set<Long> vistedNodes = new HashSet<Long>(); checkNodes(vistedNodes,node, node, lookFor); if (vistedNodes.contains(lookFor.getId()) && !vistedNodes.contains(node.getId())) { return true;
public void internalStart(String trigger) { StartNode startNode = getRuleFlowProcess().getStart(trigger); if (startNode != null) { ((NodeInstance) getNodeInstance(startNode)).trigger(null, null); } else if (!getRuleFlowProcess().isDynamic()) { throw new IllegalArgumentException("There is no start node that matches the trigger " + (trigger == null ? "none" : trigger)); } // activate ad hoc fragments if they are marked as such List<Node> autoStartNodes = getRuleFlowProcess().getAutoStartNodes(); autoStartNodes .forEach(austoStartNode -> signalEvent(austoStartNode.getName(), null)); }
if (event.getNodeInstance() != null) { long nodeInstanceId = event.getNodeInstance().getId(); long processInstanceId = event.getProcessInstance().getId(); NodeInstanceLog log = (NodeInstanceLog) ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().get("NodeInstanceLog"); if (log == null) { List<NodeInstanceLog> result = em.createQuery( log.setSlaCompliance(((NodeInstance)event.getNodeInstance()).getSlaCompliance()); em.merge(log);
public void internalTrigger(org.kie.api.runtime.process.NodeInstance fromm, String type) { String collectionExpression = getForEachNode().getCollectionExpression(); Collection<?> collection = evaluateCollectionExpression(collectionExpression); ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this); if (collection.isEmpty()) { ForEachNodeInstance.this.triggerCompleted(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, true); } else { List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(); for (Object o: collection) { String variableName = getForEachNode().getVariableName(); NodeInstance nodeInstance = (NodeInstance) ((NodeInstanceContainer) getNodeInstanceContainer()).getNodeInstance(getForEachSplitNode().getTo().getTo()); VariableScopeInstance variableScopeInstance = (VariableScopeInstance) nodeInstance.resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName); variableScopeInstance.setVariable(variableName, o); nodeInstances.add(nodeInstance); } for (NodeInstance nodeInstance: nodeInstances) { logger.debug( "Triggering [{}] in multi-instance loop.", ((NodeInstanceImpl) nodeInstance).getNodeId() ); ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(this, getForEachSplitNode().getTo().getToType()); } if (!getForEachNode().isWaitForCompletion()) { ForEachNodeInstance.this.triggerCompleted(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, false); } } }