RemoteProcessRuntimeDataServiceImpl extends AbstractKieServerService implements ProcessRuntimeDataService { @Override public ProcessInstanceDiagramSummary getProcessInstanceDiagramSummary(ProcessInstanceKey processInstanceKey, String completedNodeColor, String completedNodeBorderColor, String activeNodeBorderColor) { if (processInstanceKey == null || processInstanceKey.isValid() == false) { return null; } final ProcessInstanceSummary processInstance = getProcessInstance(processInstanceKey); ProcessInstanceDiagramSummary summary = new ProcessInstanceDiagramSummary(); summary.setId(processInstance.getId()); summary.setName(processInstance.getName()); summary.setSvgContent(processImageService.getProcessInstanceDiagram(processInstanceKey.getServerTemplateId(), processInstanceKey.getDeploymentId(), processInstanceKey.getProcessInstanceId(), completedNodeColor, completedNodeBorderColor, activeNodeBorderColor)); summary.setProcessDefinition(getProcess(new ProcessDefinitionKey(processInstance.getServerTemplateId(), processInstance.getDeploymentId(), processInstance.getProcessId()))); summary.setSubProcessInstances(getProcessInstancesByParentId(processInstanceKey, processInstanceKey.getDeploymentId())); if (processInstance.getParentId() != -1) { summary.setParentProcessInstanceSummary(getProcessInstance(new ProcessInstanceKey(processInstanceKey.getServerTemplateId(), "", processInstance.getParentId()))); } else { summary.setParentProcessInstanceSummary(null); } if (processInstance.getState() == org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE) { List<NodeInstanceSummary> nodeInstances = getProcessInstanceActiveNodes(processInstanceKey); nodeInstances.addAll(getProcessInstanceCompletedNodes(processInstanceKey)); summary.setNodeInstances(nodeInstances); summary.setTimerInstances(getProcessInstanceTimerInstances(processInstanceKey)); } else { summary.setNodeInstances(emptyList()); summary.setTimerInstances(emptyList()); } return summary; }  @Override ProcessInstanceSummary getProcessInstance(ProcessInstanceKey processInstanceKey); @Override List<NodeInstanceSummary> getProcessInstanceActiveNodes(ProcessInstanceKey processInstanceKey); @Override List<NodeInstanceSummary> getProcessInstanceCompletedNodes(ProcessInstanceKey processInstanceKey); @Override ProcessInstanceDiagramSummary getProcessInstanceDiagramSummary(ProcessInstanceKey processInstanceKey, String completedNodeColor,
                                                                          String completedNodeBorderColor, String activeNodeBorderColor); @Override List<TimerInstanceSummary> getProcessInstanceTimerInstances(ProcessInstanceKey processInstanceKey); @Override void triggerProcessInstanceNode(ProcessInstanceKey processInstanceKey,
                                           Long nodeId); @Override void cancelProcessInstanceNode(ProcessInstanceKey processInstanceKey,
                                          Long nodeInstanceId); @Override void reTriggerProcessInstanceNode(ProcessInstanceKey processInstanceKey,
                                             Long nodeInstanceId); @Override void rescheduleTimerInstance(ProcessInstanceKey processInstanceKey,
                                        TimerInstanceSummary summary); @Override List<ProcessSummary> getProcesses(String serverTemplateId,
                                             Integer page,
                                             Integer pageSize,
                                             String sort,
                                             Boolean sortOrder); @Override ProcessSummary getProcess(final ProcessDefinitionKey processDefinitionKey); @Override List<ProcessSummary> getProcessesByFilter(String serverTemplateId,
                                                     String textSearch,
                                                     Integer page,
                                                     Integer pageSize,
                                                     String sort,
                                                     Boolean sortOrder); @Override List<TaskDefSummary> getProcessUserTasks(final String serverTemplateId,
                                                    final String containerId,
                                                    final String processId); @Override WorkItemSummary getWorkItemByProcessInstanceId(final String serverTemplateId,
                                                          final String containerId,
                                                          final Long processInstanceId,
                                                          final Long workItemId); @Override ProcessInstanceSummary getProcessInstanceByCorrelationKey(String serverTemplateId, String correlationKey); static int NOT_FOUND_ERROR_CODE; }
@Test public void testGetProcessInstanceDiagramSummary() { ProcessInstanceKey instanceKey = new ProcessInstanceKey(serverTemplateId, containerId, processInstanceId); String svgContent = "<svg></svg>"; Integer state = org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE; String processName = "process"; when(queryServicesClient.findProcessInstanceById(processInstanceId)).thenReturn(ProcessInstance.builder().id(processInstanceId).containerId(containerId).processId(processId).state(state).parentInstanceId(-1L).processName(processName).build()); when(processImageService.getProcessInstanceDiagram(serverTemplateId, containerId, processInstanceId, "", "", "")).thenReturn(svgContent); List<NodeDefinition> processNodes = Arrays.asList(NodeDefinition.builder().id(1L).name("name-1").type("HumanTask").uniqueId("_1").build(), NodeDefinition.builder().id(2L).name(" ").type("Split").uniqueId("_2").build()); List<TimerDefinition> timers = Arrays.asList(TimerDefinition.builder().id(1L).nodeId(2L).nodeName("name-1").uniqueId("_1").build(), TimerDefinition.builder().id(2L).nodeId(0L).nodeName(" ").uniqueId("_2").build()); when(processServicesClient.getProcessDefinition(containerId, processId)).thenReturn(ProcessDefinition.builder().id(processId).nodes(processNodes).timers(timers).build()); List<NodeInstance> activeNodeInstances = Arrays.asList(NodeInstance.builder().id(1l).name("name-1").nodeType("HumanTask").build(), NodeInstance.builder().id(2l).name(" ").nodeType("Split").build()); when(queryServicesClient.findActiveNodeInstances(processInstanceId, 0, Integer.MAX_VALUE)).thenReturn(activeNodeInstances); List<NodeInstance> completedNodeInstances = Arrays.asList(NodeInstance.builder().id(3L).name("name-3").nodeType("HumanTask").completed(true).build(), NodeInstance.builder().id(4L).name(" ").nodeType("End").completed(true).build()); when(queryServicesClient.findCompletedNodeInstances(processInstanceId, 0, Integer.MAX_VALUE)).thenReturn(completedNodeInstances); List<TimerInstance> timerInstances = Arrays.asList(TimerInstance.builder().id(1L).timerId(1L).timerName("timer1").processInstanceId(processInstanceId).repeatLimit(1).period(2l).delay(1).build(), TimerInstance.builder().id(2L).timerId(2l).timerName("time2").processInstanceId(processInstanceId).repeatLimit(1).period(1l).delay(2).build()); when(processAdminServicesClient.getTimerInstances(containerId, processInstanceId)).thenReturn(timerInstances); ProcessInstanceDiagramSummary summary = service.getProcessInstanceDiagramSummary(instanceKey, "", "", ""); assertEquals(processInstanceId, summary.getId()); assertEquals(processName, summary.getName()); assertEquals(svgContent, summary.getSvgContent()); assertNotNull(summary.getProcessDefinition()); assertThat(summary.getProcessDefinition().getNodes()).hasSize(2).containsExactly(new ProcessNodeSummary(1l, "name-1", "HumanTask", "_1"), new ProcessNodeSummary(2l, " ", "Split", "_2")); assertThat(summary.getProcessDefinition().getTimers()).hasSize(2).containsExactly(new TimerSummary(1l, 2l, "name-1", "_1"), new TimerSummary(2l, 0l, " ", "_2")); assertThat(summary.getNodeInstances()).hasSize(4).containsExactly(NodeInstanceSummary.builder().withId(1l).withName("name-1").withType("HumanTask").build(), NodeInstanceSummary.builder().withId(2l).withName(" ").withType("Split").build(), NodeInstanceSummary.builder().withId(3l).withName("name-3").withType("HumanTask").withCompleted(true).build(), NodeInstanceSummary.builder().withId(4l).withName(" ").withType("End").withCompleted(true).build()); assertThat(summary.getTimerInstances()).hasSize(2).containsExactly(TimerInstanceSummary.builder().withId(1l).withTimerId(1l).withName("timer1").withProcessInstanceId(processInstanceId).withRepeatLimit(1).withPeriod(2l).withDelay(1l).build(), TimerInstanceSummary.builder().withId(2l).withTimerId(2l).withName("time2").withProcessInstanceId(processInstanceId).withRepeatLimit(1).withPeriod(1l).withDelay(2l).build()); }
@Test public void testGetProcessInstanceDiagramSummaryCompletedStatus() { ProcessInstanceKey instanceKey = new ProcessInstanceKey(serverTemplateId, containerId, processInstanceId); String svgContent = "<svg></svg>"; Integer state = org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED; String processName = "process"; when(queryServicesClient.findProcessInstanceById(processInstanceId)).thenReturn(ProcessInstance.builder().id(processInstanceId).processId(processId).containerId(containerId).state(state).parentInstanceId(-1L).processName(processName).build()); when(processImageService.getProcessInstanceDiagram(serverTemplateId, containerId, processInstanceId, "", "", "")).thenReturn(svgContent); when(processServicesClient.getProcessDefinition(containerId, processId)).thenReturn(new ProcessDefinition()); ProcessInstanceDiagramSummary summary = service.getProcessInstanceDiagramSummary(instanceKey, "", "", ""); assertEquals(processInstanceId, summary.getId()); assertEquals(processName, summary.getName()); assertEquals(svgContent, summary.getSvgContent()); assertNotNull(summary.getProcessDefinition()); assertThat(summary.getProcessDefinition().getNodes()).isEmpty(); assertThat(summary.getProcessDefinition().getTimers()).isEmpty(); assertThat(summary.getNodeInstances()).isEmpty(); assertThat(summary.getTimerInstances()).isEmpty(); verify(queryServicesClient, never()).findActiveNodeInstances(any(), any(), any()); verify(queryServicesClient, never()).findCompletedNodeInstances(any(), any(), any()); verify(processAdminServicesClient, never()).getTimerInstances(any(), any()); }