public Collection<org.kie.api.runtime.process.NodeInstance> getNodeInstances() { return new ArrayList<org.kie.api.runtime.process.NodeInstance>(getNodeInstances(false)); }
private static DynamicNodeInstance findDynamicContext(WorkflowProcessInstance processInstance, String uniqueId) { for (NodeInstance nodeInstance : ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances(true)) { if (uniqueId.equals(((NodeInstanceImpl) nodeInstance).getUniqueId())) { return (DynamicNodeInstance) nodeInstance; } } throw new IllegalArgumentException("Could not find node instance " + uniqueId); }
public NodeInstance getNodeInstance(long nodeInstanceId, boolean recursive) { for (NodeInstance nodeInstance: getNodeInstances(recursive)) { if (nodeInstance.getId() == nodeInstanceId) { return nodeInstance; } } return null; }
private Function<String, String> getResolver(Node node, String type, List<NodeInstance> currentView) { if (node instanceof DynamicNode) { // special handling for dynamic node to allow to resolve variables from individual node instances of the dynamic node // instead of just relying on process instance's variables return (e) -> { List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView); if (nodeInstances != null && !nodeInstances.isEmpty()) { StringBuilder st = new StringBuilder(); for (NodeInstance ni : nodeInstances) { String result = resolveVariable(e, new NodeInstanceResolverFactory(ni)); st.append(result).append("###"); } return st.toString(); } else { return resolveVariable(e); } }; } else { return (e) -> resolveVariable(e); } }
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances()); Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
@Override public Map<Long, List<TimerInstance>> execute(Context context) { Map<Long, List<TimerInstance>> result = new LinkedHashMap<>(); KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class); TimerManager timerManager = getTimerManager(kieSession); WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kieSession.getProcessInstance(migrationSpec.getProcessInstanceId()); Collection<org.jbpm.workflow.instance.NodeInstance> activeInstances = processInstance.getNodeInstances(true); for (org.jbpm.workflow.instance.NodeInstance active : activeInstances) { if (active instanceof TimerNodeInstance) { TimerInstance timerInstance = timerManager.getTimerMap().get(((TimerNodeInstance) active).getTimerId()); timerManager.cancelTimer(timerInstance.getId()); result.put(active.getId(), Arrays.asList(timerInstance)); } else if (active instanceof StateBasedNodeInstance) { List<Long> timers = ((StateBasedNodeInstance) active).getTimerInstances(); if (timers != null && !timers.isEmpty()) { List<TimerInstance> collected = new ArrayList<>(); for (Long timerId : timers) { TimerInstance timerInstance = timerManager.getTimerMap().get(timerId); timerManager.cancelTimer(timerInstance.getId()); collected.add(timerInstance); } result.put(active.getId(), collected); } } } return result; } });
this.participants = new LinkedHashSet<>(); Collection<NodeInstance> instances = ((WorkflowProcessInstanceImpl)source).getNodeInstances(true); for (NodeInstance instance : instances) { if (instance instanceof MilestoneNodeInstance) {
dynamicNodeInstance.signalEvent(type, event); } else { List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView); if (nodeInstances != null && !nodeInstances.isEmpty()) { for (NodeInstance nodeInstance : nodeInstances) {
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( workFlow.getNodeInstances() ); Collections.sort( nodeInstances, new Comparator<NodeInstance>() {
.getNodeInstances(); assertEquals(1, nodeInstances.size()); NodeInstance nodeInstance = nodeInstances.iterator().next(); .getNodeInstances(); assertEquals(1, nodeInstances.size()); nodeInstance = nodeInstances.iterator().next();
public Collection<org.kie.api.runtime.process.NodeInstance> getNodeInstances() { return new ArrayList<org.kie.api.runtime.process.NodeInstance>(getNodeInstances(false)); }
private static DynamicNodeInstance findDynamicContext(WorkflowProcessInstance processInstance, String uniqueId) { for (NodeInstance nodeInstance : ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances(true)) { if (uniqueId.equals(((NodeInstanceImpl) nodeInstance).getUniqueId())) { return (DynamicNodeInstance) nodeInstance; } } throw new IllegalArgumentException("Could not find node instance " + uniqueId); }
public NodeInstance getNodeInstance(long nodeInstanceId, boolean recursive) { for (NodeInstance nodeInstance: getNodeInstances(recursive)) { if (nodeInstance.getId() == nodeInstanceId) { return nodeInstance; } } return null; }
private Function<String, String> getResolver(Node node, String type, List<NodeInstance> currentView) { if (node instanceof DynamicNode) { // special handling for dynamic node to allow to resolve variables from individual node instances of the dynamic node // instead of just relying on process instance's variables return (e) -> { List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView); if (nodeInstances != null && !nodeInstances.isEmpty()) { StringBuilder st = new StringBuilder(); for (NodeInstance ni : nodeInstances) { String result = resolveVariable(e, new NodeInstanceResolverFactory(ni)); st.append(result).append("###"); } return st.toString(); } else { return resolveVariable(e); } }; } else { return (e) -> resolveVariable(e); } }
@Override public Map<Long, List<TimerInstance>> execute(Context context) { Map<Long, List<TimerInstance>> result = new LinkedHashMap<>(); KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class); TimerManager timerManager = getTimerManager(kieSession); WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kieSession.getProcessInstance(migrationSpec.getProcessInstanceId()); Collection<org.jbpm.workflow.instance.NodeInstance> activeInstances = processInstance.getNodeInstances(true); for (org.jbpm.workflow.instance.NodeInstance active : activeInstances) { if (active instanceof TimerNodeInstance) { TimerInstance timerInstance = timerManager.getTimerMap().get(((TimerNodeInstance) active).getTimerId()); timerManager.cancelTimer(timerInstance.getId()); result.put(active.getId(), Arrays.asList(timerInstance)); } else if (active instanceof StateBasedNodeInstance) { List<Long> timers = ((StateBasedNodeInstance) active).getTimerInstances(); if (timers != null && !timers.isEmpty()) { List<TimerInstance> collected = new ArrayList<>(); for (Long timerId : timers) { TimerInstance timerInstance = timerManager.getTimerMap().get(timerId); timerManager.cancelTimer(timerInstance.getId()); collected.add(timerInstance); } result.put(active.getId(), collected); } } } return result; } });
public static List<Node> getProcessActiveNodeList(final StatefulKnowledgeSession inSession, final WorkflowProcessInstanceImpl inInstance) { final List<Node> nodes = new ArrayList<>(); final WorkflowProcess process = (WorkflowProcess) inSession.getKnowledgeBase().getProcess(inInstance.getProcessId()); for (Node node : process.getNodes()) { if (node instanceof EventNode && ((EventNode) node).getFrom() == null) { // a free-standing event, without an entry point; this would be a start of an "optional" branch nodes.add(node); } else { // a node that has an inbound connection; all nodes on the main branch are of this kind List<NodeInstance> nodeInstances = inInstance.getNodeInstances(node.getId()); if (nodeInstances != null && !nodeInstances.isEmpty()) { for (NodeInstance nodeInstance : nodeInstances) { Node nodeInstanceNode = process.getNode(nodeInstance.getNodeId()); nodes.add(0, nodeInstanceNode); } } } } return nodes; }
@Test public void testGetTaskAudit() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); assertNotNull(processInstanceId); ProcessInstance instance = processService.getProcessInstance(processInstanceId); assertNotNull(instance); Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances(); assertNotNull(activeNodes); assertEquals(1, activeNodes.size()); NodeInstance node = activeNodes.iterator().next(); assertNotNull(node); assertTrue(node instanceof WorkItemNodeInstance); Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId(); assertNotNull(workItemId); List<AuditTask> auditTasks = runtimeDataService.getAllAuditTask("salaboy", new QueryFilter(0, 10)); assertNotNull(auditTasks); assertEquals(1, auditTasks.size()); assertEquals("Write a Document", auditTasks.get(0).getName()); }
@Test public void testGetTaskByWorkItemId() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); assertNotNull(processInstanceId); ProcessInstance instance = processService.getProcessInstance(processInstanceId); assertNotNull(instance); Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances(); assertNotNull(activeNodes); assertEquals(1, activeNodes.size()); NodeInstance node = activeNodes.iterator().next(); assertNotNull(node); assertTrue(node instanceof WorkItemNodeInstance); Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId(); assertNotNull(workItemId); UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId); assertNotNull(userTask); assertEquals(processInstanceId, userTask.getProcessInstanceId()); assertEquals("Write a Document", userTask.getName()); }
@Test public void testGetTaskEvents() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); assertNotNull(processInstanceId); ProcessInstance instance = processService.getProcessInstance(processInstanceId); assertNotNull(instance); Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances(); assertNotNull(activeNodes); assertEquals(1, activeNodes.size()); NodeInstance node = activeNodes.iterator().next(); assertNotNull(node); assertTrue(node instanceof WorkItemNodeInstance); Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId(); assertNotNull(workItemId); UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId); assertNotNull(userTask); List<TaskEvent> auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter()); assertNotNull(auditTasks); assertEquals(1, auditTasks.size()); assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType()); userTaskService.start(userTask.getTaskId(), "salaboy"); auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter()); assertNotNull(auditTasks); assertEquals(2, auditTasks.size()); assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType()); assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType()); }
@Test public void testGetNodeInstanceForWorkItem() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); assertNotNull(processInstanceId); ProcessInstance instance = processService.getProcessInstance(processInstanceId); assertNotNull(instance); Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances(); assertNotNull(activeNodes); assertEquals(1, activeNodes.size()); NodeInstance node = activeNodes.iterator().next(); assertNotNull(node); assertTrue(node instanceof WorkItemNodeInstance); Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId(); assertNotNull(workItemId); NodeInstanceDesc desc = runtimeDataService.getNodeInstanceForWorkItem(workItemId); assertNotNull(desc); assertEquals(processInstanceId, desc.getProcessInstanceId()); assertEquals("Write a Document", desc.getName()); assertEquals("HumanTaskNode", desc.getNodeType()); }