Skip to content

Commit

Permalink
Merge pull request #5 from axonivy-market/TE-585-restructure-for-sub-…
Browse files Browse the repository at this point in the history
…process

TE-585: Restructure SubProcess Elements
  • Loading branch information
trungmaihova authored May 23, 2024
2 parents 7f08b5e + c743bb3 commit e660f3f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 19 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
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,20 @@
title="#{task.pid}" />
</p:column>

<p:column headerText="Task Name">
<h:outputText value="#{task.taskName}" />
<p:column headerText="Task Name" styleClass="text-overflow">
<h:outputText value="#{task.taskName}" title="#{task.taskName}" />
</p:column>

<p:column headerText="Element Name">
<h:outputText value="#{task.elementName}" />
<p:column headerText="Element Name" styleClass="text-overflow">
<h:outputText value="#{task.elementName}" title="#{task.elementName}" />
</p:column>

<p:column headerText="Estimated Duration">
<h:outputText
value="#{data.processAnalyzerBean.getDisplayDuration(task.estimatedDuration)}" />
</p:column>

<p:column headerText="Parent Element Names"
styleClass="text-overflow">
<p:column headerText="Parent Element Names" styleClass="text-overflow">
<h:outputText value="#{task.displayParentElementNames}"
title="#{task.displayParentElementNames}" />
</p:column>
Expand Down
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,12 +21,14 @@
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;
import com.axonivy.utils.process.analyzer.model.DetectedTask;
import com.axonivy.utils.process.analyzer.model.ElementTask;

import ch.ivyteam.ivy.process.model.HierarchicElement;
import ch.ivyteam.ivy.process.model.connector.SequenceFlow;
import ch.ivyteam.ivy.process.model.element.EmbeddedProcessElement;
import ch.ivyteam.ivy.process.model.element.SingleTaskCreator;
Expand Down Expand Up @@ -132,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 @@ -169,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 Expand Up @@ -296,9 +317,10 @@ private DetectedElement createDetectedTaskFromSubProcessCall(SubProcessCall subP
String taskName = getTaskNameByCode(script);
String customerInfo = getCustomInfoByCode(script);
Duration duration = this.workflowDuration().getDuration(ElementTask.createSingle(pid), script, useCase);

List<String> parentElementNames = getParentElementNames(subProcessCall);

DetectedTask detectedTask = new DetectedTask(pid, taskName, elementName, timeUntilStartAt, duration,
customerInfo);
parentElementNames, customerInfo);
return detectedTask;
}

Expand Down Expand Up @@ -357,8 +379,9 @@ private List<DetectedElement> keepMaxTimeUtilEndDetectedElement(List<DetectedEle
return result;
}

private List<String> getParentElementNames(TaskAndCaseModifier task) {
private List<String> getParentElementNames(HierarchicElement task) {
List<String> parentElementNames = emptyList();
if(task instanceof TaskAndCaseModifier || task instanceof SubProcessCall)
if (task.getParent() instanceof EmbeddedProcessElement) {
parentElementNames = processGraph.getParentElementNamesEmbeddedProcessElement(task.getParent());
}
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 e660f3f

Please sign in to comment.