Skip to content

Commit

Permalink
TE-599: Handle task in sub process for calculate duration
Browse files Browse the repository at this point in the history
  • Loading branch information
trungmaihova committed Jun 5, 2024
1 parent 87911ed commit ba8b294
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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<ITask> parallelTasks = result.workflow().activeTasks();

var detectedTasks = processAnalyzer.findAllTasks(icase, null);

Expand All @@ -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<ITask> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ private Map<SequenceFlow, List<AnalysisPath>> findAnalysisPathForNextNode(Proces

List<SequenceFlow> 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<SequenceFlow, List<AnalysisPath>> pathOptions = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -207,7 +207,14 @@ private Map<ProcessElement, Duration> getStartElementsWithSpentDuration(ICase ic

private List<BaseElement> getStartElements(ICase icase) {
List<ITask> tasks = getCaseITasks(icase);
List<BaseElement> elements = tasks.stream().map(task -> TaskHelper.getBaseElementOf(task)).toList();
List<BaseElement> elements = new ArrayList<>();
for (ITask task : tasks) {
BaseElement element = TaskHelper.getBaseElementOf(task);
if (isTaskInCallableSub(element)) {
element = getOriginalCallerElement(task);
}
elements.add(element);
}

return elements;
}
Expand Down

0 comments on commit ba8b294

Please sign in to comment.