stream.writeShort(PersisterEnums.FOR_EACH_NODE_INSTANCE); ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance; List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(forEachNodeInstance.getNodeInstances()); Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
nodeInstance = new ForEachNodeInstance(); break; case PersisterEnums.DYNAMIC_NODE_INSTANCE:
Map<String, Object> tempVariables = new HashMap<String, Object>(); VariableScopeInstance subprocessVariableScopeInstance = null; if (getForEachNode().getOutputVariableName() != null) { subprocessVariableScopeInstance = (VariableScopeInstance) getContextInstance(VariableScope.VARIABLE_SCOPE); ((NodeInstanceImpl)from).resolveContextInstance(VariableScope.VARIABLE_SCOPE, getForEachNode().getOutputVariableName()); Object outputVariable = null; if (variableScopeInstance != null) { outputVariable = variableScopeInstance.getVariable(getForEachNode().getOutputVariableName()); tempVariables.put(getForEachNode().getOutputVariableName(), outputVariable); String outputCollectionName = getForEachNode().getOutputCollectionExpression(); if (outputCollection != null) { tempVariables.put(outputCollectionName, outputCollection); boolean isCompletionConditionMet = evaluateCompletionCondition(getForEachNode().getCompletionConditionExpression(), tempVariables); if (getNodeInstanceContainer().getNodeInstances().size() == 1 || isCompletionConditionMet) { String outputCollection = getForEachNode().getOutputCollectionExpression(); if (outputCollection != null) { VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, outputCollection); if (getForEachNode().isWaitForCompletion()) {
@Override public ContextInstance getContextInstance(String contextId) { ContextInstance contextInstance = super.getContextInstance(contextId); if (contextInstance == null) { contextInstance = resolveContextInstance(contextId, TEMP_OUTPUT_VAR); setContextInstance(contextId, contextInstance); } return contextInstance; }
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); } } }
JBPMMessages.ProcessInstance.NodeInstanceContent.ForEachNode.Builder _foreach = JBPMMessages.ProcessInstance.NodeInstanceContent.ForEachNode.newBuilder(); ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance; List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( forEachNodeInstance.getNodeInstances() ); Collections.sort( nodeInstances, new Comparator<NodeInstance>() { VariableScopeInstance variableScopeInstance = (VariableScopeInstance) forEachNodeInstance.getContextInstance( VariableScope.VARIABLE_SCOPE); if ( variableScopeInstance != null ) { List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>( variableScopeInstance.getVariables().entrySet() ); List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>( forEachNodeInstance.getIterationLevels().entrySet() ); Collections.sort( iterationlevels, new Comparator<Map.Entry<String, Integer>>() {
nodeInstance.setNodeId(node.getId()); nodeInstance.setNodeInstanceContainer(this); nodeInstance.setProcessInstance(getProcessInstance()); String uniqueID = (String) node.getMetaData().get("UniqueId"); assert uniqueID != null : node.getName() + " does not have a unique id."; uniqueID = node.getId()+""; int level = this.getLevelForNode(uniqueID); nodeInstance.setLevel(level); return nodeInstance; } else if (node instanceof ForEachJoinNode) { ForEachJoinNodeInstance nodeInstance = (ForEachJoinNodeInstance) getFirstNodeInstance(node.getId()); if (nodeInstance == null) { nodeInstance = new ForEachJoinNodeInstance(); nodeInstance.setNodeId(node.getId()); nodeInstance.setNodeInstanceContainer(this); nodeInstance.setProcessInstance(getProcessInstance()); String uniqueID = (String) node.getMetaData().get("UniqueId"); assert uniqueID != null : node.getName() + " does not have a unique id."; uniqueID = node.getId()+""; int level = this.getLevelForNode(uniqueID); nodeInstance.setLevel(level);
(ForEachNodeInstance) nodeInstance, processInstance ); VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ForEachNodeInstance) nodeInstance).getContextInstance( VariableScope.VARIABLE_SCOPE ); for ( JBPMMessages.Variable _variable : _node.getContent().getForEach().getVariableList() ) { try { ((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
@Override public ContextContainer getContextContainer() { return (ContextContainer) getForEachNode().getCompositeNode(); }
public ForEachNode getForEachNode() { return (ForEachNode) getNode(); }
resolveContextInstance(VariableScope.VARIABLE_SCOPE, collectionExpression); if (variableScopeInstance != null) { collection = variableScopeInstance.getVariable(collectionExpression);
JBPMMessages.ProcessInstance.NodeInstanceContent.ForEachNode.Builder _foreach = JBPMMessages.ProcessInstance.NodeInstanceContent.ForEachNode.newBuilder(); ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance; List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( forEachNodeInstance.getNodeInstances() ); Collections.sort( nodeInstances, new Comparator<NodeInstance>() { VariableScopeInstance variableScopeInstance = (VariableScopeInstance) forEachNodeInstance.getContextInstance( VariableScope.VARIABLE_SCOPE); if ( variableScopeInstance != null ) { List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>( variableScopeInstance.getVariables().entrySet() ); List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>( forEachNodeInstance.getIterationLevels().entrySet() ); Collections.sort( iterationlevels, new Comparator<Map.Entry<String, Integer>>() {
nodeInstance.setNodeId(node.getId()); nodeInstance.setNodeInstanceContainer(this); nodeInstance.setProcessInstance(getProcessInstance()); String uniqueID = (String) node.getMetaData().get("UniqueId"); assert uniqueID != null : node.getName() + " does not have a unique id."; uniqueID = node.getId()+""; int level = this.getLevelForNode(uniqueID); nodeInstance.setLevel(level); return nodeInstance; } else if (node instanceof ForEachJoinNode) { ForEachJoinNodeInstance nodeInstance = (ForEachJoinNodeInstance) getFirstNodeInstance(node.getId()); if (nodeInstance == null) { nodeInstance = new ForEachJoinNodeInstance(); nodeInstance.setNodeId(node.getId()); nodeInstance.setNodeInstanceContainer(this); nodeInstance.setProcessInstance(getProcessInstance()); String uniqueID = (String) node.getMetaData().get("UniqueId"); assert uniqueID != null : node.getName() + " does not have a unique id."; uniqueID = node.getId()+""; int level = this.getLevelForNode(uniqueID); nodeInstance.setLevel(level);
@Override public ContextInstance getContextInstance(String contextId) { ContextInstance contextInstance = super.getContextInstance(contextId); if (contextInstance == null) { contextInstance = resolveContextInstance(contextId, TEMP_OUTPUT_VAR); setContextInstance(contextId, contextInstance); } return contextInstance; }
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); } } }
(ForEachNodeInstance) nodeInstance, processInstance ); VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ForEachNodeInstance) nodeInstance).getContextInstance( VariableScope.VARIABLE_SCOPE ); for ( JBPMMessages.Variable _variable : _node.getContent().getForEach().getVariableList() ) { try { ((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
@Override public ContextContainer getContextContainer() { return (ContextContainer) getForEachNode().getCompositeNode(); }
public ForEachNode getForEachNode() { return (ForEachNode) getNode(); }
resolveContextInstance(VariableScope.VARIABLE_SCOPE, collectionExpression); if (variableScopeInstance != null) { collection = variableScopeInstance.getVariable(collectionExpression);
.getNodeInstances(); assertEquals(2, nodeInstancesChild.size()); .getNodeInstances(); assertEquals(1, nodeInstancesChild.size()); } else { nodeInstancesChild = ((ForEachNodeInstance) nodeInstance) .getNodeInstances(); assertEquals(2, nodeInstancesChild.size());