Skip to content

Commit

Permalink
Merge pull request #24 from axonivy-market/TE-607-embedded-start
Browse files Browse the repository at this point in the history
TE-607: Handle parallel task in sub process
  • Loading branch information
trungmaihova authored Jun 14, 2024
2 parents 952cbd3 + 629d544 commit 98a945d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
80 changes: 76 additions & 4 deletions process-analyzer-test/processes/FlowSubprocess.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@
},
"parentConnector" : "f11",
"connect" : [
{ "id" : "S30-f0", "to" : "S30-f1" }
{ "id" : "S30-f0", "to" : "S30-f5", "var" : "in1" }
]
}, {
"id" : "S30-g1",
"type" : "EmbeddedEnd",
"visual" : {
"at" : { "x" : 496, "y" : 256 }
"at" : { "x" : 672, "y" : 256 }
},
"parentConnector" : "f13"
}, {
Expand All @@ -267,7 +267,7 @@
}
},
"visual" : {
"at" : { "x" : 208, "y" : 256 }
"at" : { "x" : 424, "y" : 256 }
},
"connect" : [
{ "id" : "S30-f2", "to" : "S30-f3" }
Expand All @@ -283,11 +283,83 @@
}
},
"visual" : {
"at" : { "x" : 368, "y" : 256 }
"at" : { "x" : 568, "y" : 256 }
},
"connect" : [
{ "id" : "S30-f4", "to" : "S30-g1" }
]
}, {
"id" : "S30-f5",
"type" : "TaskSwitchGateway",
"config" : {
"tasks" : [ {
"id" : "TaskA",
"responsible" : {
"activator" : "SYSTEM"
}
}, {
"id" : "TaskB",
"responsible" : {
"activator" : "SYSTEM"
}
} ]
},
"visual" : {
"at" : { "x" : 136, "y" : 256 }
},
"connect" : [
{ "id" : "S30-f6", "to" : "S30-f7", "via" : [ { "x" : 136, "y" : 208 } ], "condition" : "ivp==\"TaskA.ivp\"" },
{ "id" : "S30-f12", "to" : "S30-f11", "via" : [ { "x" : 136, "y" : 304 } ], "condition" : "ivp==\"TaskB.ivp\"" }
]
}, {
"id" : "S30-f7",
"type" : "UserTask",
"name" : "SubA-TaskA",
"config" : {
"dialog" : "com.axonivy.utils.process.analyzer.test.Dummy:start()",
"task" : {
"name" : "SubA-TaskA"
}
},
"visual" : {
"at" : { "x" : 232, "y" : 208 }
},
"connect" : [
{ "id" : "S30-f8", "to" : "S30-f9", "via" : [ { "x" : 320, "y" : 208 } ], "var" : "in1" }
]
}, {
"id" : "S30-f9",
"type" : "TaskSwitchGateway",
"config" : {
"tasks" : [ {
"id" : "TaskA",
"responsible" : {
"activator" : "SYSTEM"
}
} ]
},
"visual" : {
"at" : { "x" : 320, "y" : 256 }
},
"connect" : [
{ "id" : "S30-f10", "to" : "S30-f1", "condition" : "ivp==\"TaskA.ivp\"" }
]
}, {
"id" : "S30-f11",
"type" : "UserTask",
"name" : "SubA-TaskB",
"config" : {
"dialog" : "com.axonivy.utils.process.analyzer.test.Dummy:start()",
"task" : {
"name" : "SubA-TaskB"
}
},
"visual" : {
"at" : { "x" : 232, "y" : 304 }
},
"connect" : [
{ "id" : "S30-f13", "to" : "S30-f9", "via" : [ { "x" : 320, "y" : 304 } ], "var" : "in2" }
]
} ],
"visual" : {
"at" : { "x" : 288, "y" : 312 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.Duration;
import java.util.List;

import org.assertj.core.util.Arrays;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -16,6 +17,7 @@
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 @@ -29,11 +31,17 @@ public void setupForEach() {
@Test
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();

for (ITask task : parallelTasks) {
result = bpmClient.start().task(task).as().systemUser().execute();
}

ICase icase = result.workflow().activeCase();
var detectedTasks = processAnalyzer.findAllTasks(icase, null);

var expected = Arrays.array("CallSubProcess A", "TaskC", "TaskB");
var expected = Arrays.array("SubA-TaskA", "SubA-TaskB", "CallSubProcess A", "TaskC", "TaskB");
var taskNames = getTaskNames(detectedTasks);
assertArrayEquals(expected, taskNames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,13 @@ private List<AnalysisPath> findAnalysisPaths(ProcessElement startElement, String
}
}

// Call recursion for next normal node

var newPath = addToPath(currentPath, path);
//It stop finding tasks when the end node is TaskEnd for TASKS_ON_PATH case
if (shouldStopFindTask(newPath, findType)) {
return path;
}
// Call recursion for next normal node
var pathOptions = findAnalysisPathForNextNode(from, flowName, findType, newPath);
path = addAllToPath(path, pathOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;

import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.lang3.StringUtils;

import com.axonivy.utils.process.analyzer.internal.model.AnalysisPath;
Expand Down Expand Up @@ -83,8 +84,7 @@ protected List<DetectedElement> findTaskOnPath(Map<ProcessElement, Duration> tim
return detectedTasks;
}

protected List<DetectedElement> convertToDetectedElements(Map<ProcessElement, List<AnalysisPath>> allPaths,
Enum<?> useCase, Map<ProcessElement, Duration> timeUntilStarts) {
protected List<DetectedElement> convertToDetectedElements(Map<ProcessElement, List<AnalysisPath>> allPaths, Enum<?> useCase, Map<ProcessElement, Duration> timeUntilStarts) {
List<DetectedElement> result = new ArrayList<>();
for (Entry<ProcessElement, List<AnalysisPath>> path : allPaths.entrySet()) {
List<DetectedElement> elements = convertPathToDetectedElements(path.getKey(), path.getValue(), useCase,
Expand Down Expand Up @@ -177,7 +177,9 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
List<DetectedElement> allTaskFromSubPath = new ArrayList<>();
for(AnalysisPath subPath : subPaths) {
ProcessElement startSubElement = subPath.getElements().get(0);
var startedForSubProcess = Map.of(startSubElement, durationStart);
var startedForSubProcess = new HashedMap<>(timeUntilStarts);
startedForSubProcess.put(startSubElement, durationStart);

List<DetectedElement> subResult = convertPathToDetectedElements(startSubElement, subPath, useCase , startedForSubProcess);
allTaskFromSubPath.addAll(subResult);
}
Expand Down

0 comments on commit 98a945d

Please sign in to comment.