public void triggerNode(long nodeId, boolean fireEvents) { org.jbpm.workflow.instance.NodeInstance nodeInstance = (org.jbpm.workflow.instance.NodeInstance) ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()) .getNodeInstance(getNode().getNodeContainer().getNode(nodeId)); triggerNodeInstance(nodeInstance, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, fireEvents); }
@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)
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); hidden = true; InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); if (!hidden) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()) .nodeInstanceCompleted(this, type); if (!hidden) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) { return;
public NodeInstance getNodeInstance(Node node, WorkflowProcessInstance processInstance, NodeInstanceContainer nodeInstanceContainer) { NodeInstance result = ((org.jbpm.workflow.instance.NodeInstanceContainer) nodeInstanceContainer).getFirstNodeInstance( node.getId() ); if (result != null) { return result; } try { NodeInstanceImpl nodeInstance = (NodeInstanceImpl) cls.newInstance(); nodeInstance.setNodeId(node.getId()); nodeInstance.setNodeInstanceContainer(nodeInstanceContainer); nodeInstance.setProcessInstance(processInstance); String uniqueId = (String) node.getMetaData().get("UniqueId"); assert uniqueId != null : 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) { throw new RuntimeException("Unable to instantiate node '" + this.cls.getName() + "': " + e.getMessage()); } }
@Override public void triggerCompleted() { getProcessInstance().removeEventListener(getEventType(), getEventListener(), true); ((org.jbpm.workflow.instance.NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(getLevel()); ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this); NodeInstance instance = ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getNodeInstance(getNode()); triggerNodeInstance((org.jbpm.workflow.instance.NodeInstance) instance, NodeImpl.CONNECTION_DEFAULT_TYPE); }
long thisNodeCurrentTime = context.getClock().getCurrentTime(); List<Connection> outgoing = getNode().getOutgoingConnections().get(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE); for (Connection conn : outgoing) { if (context.getCurrentPath().getSequenceFlowsIds().contains(conn.getMetaData().get("UniqueId"))) { for (Node node : getNode().getNodeContainer().getNodes()) { if (node.getMetaData().get("UniqueId").equals(boundaryEvent) && node.getMetaData().get("AttachedTo").equals(getNode().getMetaData().get("UniqueId"))) { NodeInstance next = ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getNodeInstance(boundaryEventNode); setNodeId(boundaryEventNode.getId()); this.trigger(next, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
((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; ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this); Node node = getNode(); List<Connection> connections = null; if (node != null) { connections = node.getOutgoingConnections(type); .nodeInstanceCompleted(this, type); } else { ExclusiveGroupInstance groupInstance = new ExclusiveGroupInstance(); if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) { return; if (getNode().getMetaData().get("hidden") != null) { hidden = true;
if (getNode().getMetaData().get("hidden") != null) { hidden = true; InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); if (!hidden) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime); ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this); if (getEndNode().isTerminate()) { if (getNodeInstanceContainer() instanceof CompositeNodeInstance) { if (getEndNode().getScope() == EndNode.PROCESS_SCOPE) { getProcessInstance().setState( ProcessInstance.STATE_COMPLETED ); } 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 ); .nodeInstanceCompleted(this, null);
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); } }
ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(faultName); NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer(); nodeInstanceContainer.removeNodeInstance(this); boolean exceptionHandled = false; if (getFaultNode().isTerminateParent()) { Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstance) nodeInstanceContainer).getNodeInstances(); for (NodeInstance nodeInstance: nodeInstances) { ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).cancel(); if (getNode().getMetaData().get("hidden") != null) { hidden = true; InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime); ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null); InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
public void activationCreated(MatchCreatedEvent event) { Connection selected = null; for (Connection connection: getNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) { Constraint constraint = getStateNode().getConstraint(connection); if (constraint != null) { String constraintName = getActivationEventType() + "-" + connection.getTo().getId() + "-" + connection.getToType(); if (constraintName.equals(event.getMatch().getRule().getName()) && checkProcessInstance((Activation) event.getMatch())) { selected = connection; } } } if (selected != null) { removeEventListeners(); ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this); triggerConnection(selected); } }
@Override public void internalTrigger(NodeInstance from, String type) { SimulationContext context = SimulationContext.getContext(); ActivitySimulator simulator = context.getRegistry().getSimulator(getNode()); SimulationEvent event = simulator.simulate(this, context); context.getRepository().storeEvent(event); // process event definitions if any Map<String, String> throwEvents = context.getCurrentPath().getThrowEvents(); String throwReference = throwEvents.get(getNode().getMetaData().get("UniqueId")); if (throwReference != null) { getProcessInstance().signalEvent(throwReference, null); } ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null); }
Constraint constraint = stateNode.getConstraint(connection); if (constraint != null && constraint.getPriority() < priority) { String rule = "RuleFlowStateNode-" + getProcessInstance().getProcessId() + "-" + getStateNode().getUniqueId() + "-" + connection.getTo().getId() + "-" + connection.getToType(); boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()) .isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", rule, getProcessInstance().getId()); if (isActive) { selected = connection; ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this); triggerConnection(selected); } else {
Constraint constraint = getStateNode().getConstraint(connection); if (constraint == null) { if (((String) event).equals(connection.getTo().getName())) { selected = true; removeEventListeners(); ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()) .removeNodeInstance(this); triggerConnection(connection); return;
processInstance); nodeInstance.setNodeId( _node.getNodeId() ); nodeInstance.setId( _node.getId() ); nodeInstance.setNodeInstanceContainer( nodeInstanceContainer ); nodeInstance.setProcessInstance( (org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance ); nodeInstance.setLevel(_node.getLevel()==0?1:_node.getLevel()); ((CompositeContextNodeInstance) nodeInstance).addContextInstance( ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance ); for ( Long nodeInstanceId : _excl.getGroupNodeInstanceIdList() ) { NodeInstance groupNodeInstance = ((org.jbpm.workflow.instance.NodeInstanceContainer)processInstance).getNodeInstance( nodeInstanceId, true ); if ( groupNodeInstance == null ) { throw new IllegalArgumentException( "Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId );
Stack<NodeInstance> generatedInstances = new Stack<NodeInstance>(); NodeContainer parentContainer = toCompensateNode.getNodeContainer(); while( !(parentContainer instanceof RuleFlowProcess) ) { nestedNodes.add(parentContainer); parentContainer = ((Node) parentContainer).getNodeContainer(); while( ! nestedNodes.isEmpty() ) { childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance((Node) nestedNodes.pop()); assert childInstance instanceof CompositeNodeInstance : "A node with child nodes should end up creating a CompositeNodeInstance type."; childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance(toCompensateNode); generatedInstances.add((NodeInstance) childInstance);
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); } } }
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); } } }
public Collection<NodeInstance> getNodeInstances(boolean recursive) { Collection<NodeInstance> result = nodeInstances; if (recursive) { result = new ArrayList<NodeInstance>(result); for (Iterator<NodeInstance> iterator = nodeInstances.iterator(); iterator.hasNext(); ) { NodeInstance nodeInstance = iterator.next(); if (nodeInstance instanceof NodeInstanceContainer) { result.addAll(((NodeInstanceContainer) nodeInstance).getNodeInstances(true)); } } } return Collections.unmodifiableCollection(result); }
protected org.jbpm.workflow.instance.NodeInstance followConnection(Connection connection) { // check for exclusive group first NodeInstanceContainer parent = getNodeInstanceContainer(); if (parent instanceof ContextInstanceContainer) { List<ContextInstance> contextInstances = ((ContextInstanceContainer) parent).getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP); if (contextInstances != null) { for (ContextInstance contextInstance: new ArrayList<ContextInstance>(contextInstances)) { ExclusiveGroupInstance groupInstance = (ExclusiveGroupInstance) contextInstance; if (groupInstance.containsNodeInstance(this)) { for (NodeInstance nodeInstance: groupInstance.getNodeInstances()) { if (nodeInstance != this) { ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).cancel(); } } ((ContextInstanceContainer) parent).removeContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, contextInstance); } } } } return (org.jbpm.workflow.instance.NodeInstance) ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()) .getNodeInstance(connection.getTo()); }