Skip to content

Commit

Permalink
TE-585: Restructure SubProcess Elements
Browse files Browse the repository at this point in the history
  • Loading branch information
trungmaihova committed May 23, 2024
1 parent 5626883 commit c743bb3
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 10 deletions.
4 changes: 4 additions & 0 deletions process-analyzer-demo/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
4 changes: 4 additions & 0 deletions process-analyzer-test/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
4 changes: 4 additions & 0 deletions process-analyzer/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.axonivy.utils.process.analyzer.internal.model.AnalysisPath;
import com.axonivy.utils.process.analyzer.internal.model.CommonElement;
import com.axonivy.utils.process.analyzer.internal.model.ProcessElement;
import com.axonivy.utils.process.analyzer.internal.model.SubProcessGroup;
import com.axonivy.utils.process.analyzer.internal.model.TaskParallelGroup;

import ch.ivyteam.ivy.process.model.BaseElement;
Expand Down Expand Up @@ -346,8 +347,11 @@ private List<AnalysisPath> findAnalysisPaths(ProcessElement from, String flowNam
if (from.getElement() instanceof NodeElement) {

if (from.getElement() instanceof EmbeddedProcessElement) {
List<AnalysisPath> pathFromSubProcess = findPathOfSubProcess(from, flowName, findType);
path = addToPath(path, pathFromSubProcess);
SubProcessGroup subProcessGroup = findPathOfSubProcess(from, flowName, findType);

path = removeLastElementByClassType(path, EmbeddedProcessElement.class);

path = addAllToPath(path, List.of(subProcessGroup));
}

if (isJoinTaskSwitchGateway(currentPath, from)) {
Expand All @@ -358,7 +362,7 @@ private List<AnalysisPath> findAnalysisPaths(ProcessElement from, String flowNam
var taskParallelGroup = getTaskParallelGroup(from, flowName, findType, currentPath);

// If last element is CommonElement(TaskSwitchGateway)-> We will remove it.
path = removeLastTaskSwitchGateway(path);
path = removeLastElementByClassType(path, TaskSwitchGateway.class);

path = addAllToPath(path, List.of(taskParallelGroup));
from = getJoinTaskSwithGateWay(taskParallelGroup);
Expand Down Expand Up @@ -392,22 +396,25 @@ private String getAlternativeNameId(BaseElement alternative) {
return Stream.of(alternative.getName(), alternative.getPid().getRawPid()).filter(StringUtils::isNotEmpty)
.collect(Collectors.joining("-"));
}

private List<AnalysisPath> removeLastElementByClassType(List<AnalysisPath> paths , Class clazz) {

private List<AnalysisPath> removeLastTaskSwitchGateway(List<AnalysisPath> paths) {
List<AnalysisPath> result = new ArrayList<>();
for (AnalysisPath path : paths) {
int lastIndex = getLastIndex(path.getElements());
List<ProcessElement> pathElements = new ArrayList<>(path.getElements());
if (pathElements.get(lastIndex) instanceof CommonElement
&& pathElements.get(lastIndex).getElement() instanceof TaskSwitchGateway) {
ProcessElement lastElement = pathElements.get(lastIndex);

if (lastElement instanceof CommonElement && clazz.isInstance(lastElement.getElement())) {
pathElements.remove(lastIndex);
}

result.add(new AnalysisPath(pathElements));
}

return result;
}

private List<AnalysisPath> addToPath(List<AnalysisPath> paths, List<AnalysisPath> subPaths) {
if (subPaths.isEmpty()) {
return paths;
Expand Down Expand Up @@ -499,12 +506,15 @@ private TaskParallelGroup getTaskParallelGroup(ProcessElement from, String flowN
/**
* Find path on sub process
*/
private List<AnalysisPath> findPathOfSubProcess(ProcessElement subProcessElement, String flowName,
private SubProcessGroup findPathOfSubProcess(ProcessElement subProcessElement, String flowName,
FindType findType) throws Exception {
EmbeddedProcessElement processElement = (EmbeddedProcessElement) subProcessElement.getElement();
BaseElement start = processGraph.findOneStartElementOfProcess(processElement.getEmbeddedProcess());
List<AnalysisPath> path = findAnalysisPaths(new CommonElement(start), flowName, findType, emptyList());
return path;

SubProcessGroup subProcessGroup = new SubProcessGroup(processElement);
subProcessGroup.setInternalPaths(path);
return subProcessGroup;
}

private List<SequenceFlow> getSequenceFlows(NodeElement from, String flowName, FindType findType) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.axonivy.utils.process.analyzer.internal.model.AnalysisPath;
import com.axonivy.utils.process.analyzer.internal.model.CommonElement;
import com.axonivy.utils.process.analyzer.internal.model.ProcessElement;
import com.axonivy.utils.process.analyzer.internal.model.SubProcessGroup;
import com.axonivy.utils.process.analyzer.internal.model.TaskParallelGroup;
import com.axonivy.utils.process.analyzer.model.DetectedAlternative;
import com.axonivy.utils.process.analyzer.model.DetectedElement;
Expand Down Expand Up @@ -133,7 +134,8 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
continue;
}

if (processGraph.isTaskAndCaseModifier(element.getElement())
if (element instanceof CommonElement
&& processGraph.isTaskAndCaseModifier(element.getElement())
&& processGraph.isSystemTask(element.getElement())) {
continue;
}
Expand Down Expand Up @@ -170,6 +172,24 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
continue;
}

if (element instanceof SubProcessGroup) {
List<AnalysisPath> subPaths = ((SubProcessGroup) element).getInternalPaths();
List<DetectedElement> allTaskFromSubPath = new ArrayList<>();
for(AnalysisPath subPath : subPaths) {
ProcessElement startSubElement = subPath.getElements().get(0);
var startedForSubProcess = Map.of(startSubElement, durationStart);
List<DetectedElement> subResult = convertPathToDetectedElements(startSubElement, subPath, useCase , startedForSubProcess);
allTaskFromSubPath.addAll(subResult);
}

if(isNotEmpty(allTaskFromSubPath)) {
result.addAll(allTaskFromSubPath);
durationStart = getMaxDurationUntilEnd(allTaskFromSubPath);
}

continue;
}

if (element instanceof TaskParallelGroup) {
var startedForGroup = element.getElement() == null ? timeUntilStarts : Map.of(element, durationStart);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.axonivy.utils.process.analyzer.internal.model;

import static org.apache.commons.lang3.StringUtils.EMPTY;

import java.util.List;
import java.util.Objects;

import ch.ivyteam.ivy.process.model.BaseElement;
import ch.ivyteam.ivy.process.model.value.PID;

public class SubProcessGroup implements ProcessElement {
private BaseElement element;
List<AnalysisPath> internalPaths;

public SubProcessGroup(BaseElement element) {
this.element = element;
}

public List<AnalysisPath> getInternalPaths() {
return internalPaths;
}

public void setInternalPaths(List<AnalysisPath> internalPaths) {
this.internalPaths = internalPaths;
}

@Override
public int hashCode() {
return Objects.hash(this.element, this.internalPaths);
}

@Override
public String toString() {
return String.format("%s : %s ", Objects.toString(element, EMPTY), Objects.toString(internalPaths, EMPTY));
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (!(other instanceof SubProcessGroup)) {
return false;
}
SubProcessGroup task = (SubProcessGroup) other;
return Objects.equals(task.element, this.element) && Objects.equals(task.internalPaths, this.internalPaths);
}

@Override
public PID getPid() {
return element.getPid();
}

@Override
public BaseElement getElement() {
return element;
}

}

0 comments on commit c743bb3

Please sign in to comment.