diff --git a/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json b/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json index 686f5f5..50a7ad8 100644 --- a/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json +++ b/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json @@ -114,7 +114,8 @@ "in.processAnalyzerBean.selectedAnalyzer.tasks = in.processAnalyzerBean.getDetectedTask();", "in.processAnalyzerBean.selectedAnalyzer.totalDuration = in.processAnalyzerBean.getDetectedTaskCalculate();" ] - } + }, + "sudo" : true }, "visual" : { "at" : { "x" : 288, "y" : 360 } diff --git a/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowExampleErrorTest.java b/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowExampleErrorTest.java index d266b01..fc2495e 100644 --- a/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowExampleErrorTest.java +++ b/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowExampleErrorTest.java @@ -42,7 +42,7 @@ void shouldThrowExceptionWhenFindTasksOnPathAtStartWithFlowNameNull() { processAnalyzer.findTasksOnPath(start, null, null); }); - String expectedMessage = "Not found path after element alter1-18DD16F8AA39F5DE-f7"; + String expectedMessage = "Not found path after element: \"alter1-18DD16F8AA39F5DE-f7\""; String actualMessage = exception.getMessage(); assertEquals(expectedMessage, actualMessage); diff --git a/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowSubProcessCaseTest.java b/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowSubProcessCaseTest.java index d6fedca..cb66990 100644 --- a/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowSubProcessCaseTest.java +++ b/process-analyzer-test/src_test/com/axonivy/utils/process/analyzer/test/FlowSubProcessCaseTest.java @@ -1,8 +1,9 @@ package com.axonivy.utils.process.analyzer.test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; +import java.time.Duration; import org.assertj.core.util.Arrays; import org.junit.jupiter.api.BeforeEach; @@ -15,7 +16,6 @@ import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; import ch.ivyteam.ivy.workflow.ICase; -import ch.ivyteam.ivy.workflow.ITask; @IvyProcessTest public class FlowSubProcessCaseTest extends FlowExampleTest { @@ -27,11 +27,9 @@ public void setupForEach() { } @Test - void shouldshouldFindAllTasksAtStart3(BpmClient bpmClient) throws Exception { + void shouldFindAllTasksAtStart3(BpmClient bpmClient) throws Exception { ExecutionResult result = bpmClient.start().process(FLOW_SUB_PROCESS.elementName("start3")).execute(); ICase icase = result.workflow().activeCase(); - - List parallelTasks = result.workflow().activeTasks(); var detectedTasks = processAnalyzer.findAllTasks(icase, null); @@ -41,16 +39,24 @@ void shouldshouldFindAllTasksAtStart3(BpmClient bpmClient) throws Exception { } @Test - void shouldshouldFindAllTasksAtStart(BpmClient bpmClient) throws Exception { + void shouldFindAllTasksAtStart(BpmClient bpmClient) throws Exception { ExecutionResult result = bpmClient.start().process(FLOW_SUB_PROCESS.elementName("start")).execute(); ICase icase = result.workflow().activeCase(); - List parallelTasks = result.workflow().activeTasks(); - var detectedTasks = processAnalyzer.findAllTasks(icase, null); var expected = Arrays.array("Task A", "Task B"); var taskNames = getTaskNames(detectedTasks); assertArrayEquals(expected, taskNames); } + + @Test + void shouldCalculateWorstCaseDuration(BpmClient bpmClient) throws Exception { + ExecutionResult result = bpmClient.start().process(FLOW_SUB_PROCESS.elementName("start")).execute(); + ICase icase = result.workflow().activeCase(); + + var total = processAnalyzer.calculateWorstCaseDuration(icase, UseCase.BIGPROJECT); + + assertEquals(Duration.ofHours(9), total); + } } diff --git a/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/PathFinder.java b/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/PathFinder.java index 3aaebc1..344fe5f 100644 --- a/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/PathFinder.java +++ b/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/PathFinder.java @@ -433,7 +433,8 @@ private Map> findAnalysisPathForNextNode(Proces List outs = getSequenceFlows((NodeElement) from.getElement(), flowName, findType); if (from.getElement() instanceof Alternative && outs.isEmpty()) { - throw new Exception("Not found path after element " + processGraph.getAlternativeNameId(from.getElement())); + String mgs = String.format("Not found path after element: \"%s\"", processGraph.getAlternativeNameId(from.getElement())); + throw new Exception(mgs); } Map> pathOptions = new LinkedHashMap<>(); diff --git a/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/ProcessAnalyzer.java b/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/ProcessAnalyzer.java index 3854894..afeaac8 100644 --- a/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/ProcessAnalyzer.java +++ b/process-analyzer/src/com/axonivy/utils/process/analyzer/internal/ProcessAnalyzer.java @@ -4,12 +4,12 @@ import static java.util.Optional.ofNullable; import java.time.Duration; +import java.util.ArrayList; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.stream.Stream; import org.apache.commons.lang3.ArrayUtils; @@ -207,7 +207,14 @@ private Map getStartElementsWithSpentDuration(ICase ic private List getStartElements(ICase icase) { List tasks = getCaseITasks(icase); - List elements = tasks.stream().map(task -> TaskHelper.getBaseElementOf(task)).toList(); + List elements = new ArrayList<>(); + for (ITask task : tasks) { + BaseElement element = TaskHelper.getBaseElementOf(task); + if (isTaskInCallableSub(element)) { + element = getOriginalCallerElement(task); + } + elements.add(element); + } return elements; }