Skip to content

Commit

Permalink
TE-614: Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
trungmaihova committed Jun 25, 2024
1 parent 3ac1ae8 commit 32c8824
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 57 deletions.
62 changes: 33 additions & 29 deletions process-analyzer-demo/.classpath
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src_wsproc">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src_dataClasses">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="IVY_CONTAINER"/>
<classpathentry kind="con" path="WEBAPP_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src_wsproc">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src_dataClasses">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="IVY_CONTAINER"/>
<classpathentry exported="true" kind="con" path="WEBAPP_CONTAINER"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry exported="true" kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
11 changes: 11 additions & 0 deletions process-analyzer-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
<artifactId>process-analyzer</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.axonivy.cloud.storage</groupId>
<artifactId>azure-blob-connector</artifactId>
<version>10.0.21-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.axonivy.portal</groupId>
<artifactId>portal-components</artifactId>
<version>11.2.1</version>
<type>iar</type>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.primefaces.component.selectoneradio.SelectOneRadio;
import org.primefaces.model.FilterMeta;

import com.axonivy.portal.components.util.CaseUtils;
import com.axonivy.utils.process.analyzer.AdvancedProcessAnalyzer;
import com.axonivy.utils.process.analyzer.demo.constant.FindType;
import com.axonivy.utils.process.analyzer.demo.constant.UseCase;
Expand All @@ -40,11 +41,13 @@
import ch.ivyteam.ivy.process.rdm.IProcess;
import ch.ivyteam.ivy.process.rdm.IProcessManager;
import ch.ivyteam.ivy.process.viewer.api.ProcessViewer;
import ch.ivyteam.ivy.workflow.ICase;
import ch.ivyteam.ivy.workflow.start.IProcessWebStartable;
import ch.ivyteam.ivy.workflow.start.IWebStartable;

public class ProcessAnalyzerBean {

private static final String CASE_ID = "d3419722-b39c-4459-92bc-a215cb015322";
private List<Analyzer> analyzers = new ArrayList<>();

private List<Process> processes = emptyList();
Expand Down Expand Up @@ -137,15 +140,16 @@ public void onSelectSequenceFlow(AjaxBehaviorEvent event) {
public List<DetectedElement> getDetectedTask() throws Exception {
UseCase useCase = selectedAnalyzer.getUseCase();
String flowName = selectedAnalyzer.getFlowName();
ICase iCase = CaseUtils.findCase(CASE_ID);
SingleTaskCreator startElement = selectedAnalyzer.getStartElement();
processAnalyzer = updateProcessAnalyzer(selectedAnalyzer);

long startTime = System.currentTimeMillis();
List<?> detectedElements = null;
if (FindType.ALL_TASK.equals(selectedAnalyzer.getFindType())) {
detectedElements = processAnalyzer.findAllTasks(startElement, useCase);
detectedElements = processAnalyzer.findAllTasks(iCase, useCase);
} else {
detectedElements = processAnalyzer.findTasksOnPath(startElement, useCase, flowName);
detectedElements = processAnalyzer.findTasksOnPath(iCase, useCase, flowName);
}

long executionTime = System.currentTimeMillis() - startTime;
Expand All @@ -158,12 +162,13 @@ public Duration getDetectedTaskCalculate() throws Exception {
UseCase useCase = selectedAnalyzer.getUseCase();
String flowName = selectedAnalyzer.getFlowName();
SingleTaskCreator startElement = selectedAnalyzer.getStartElement();
processAnalyzer = updateProcessAnalyzer(selectedAnalyzer);
ICase iCase = CaseUtils.findCase(CASE_ID);
processAnalyzer = updateProcessAnalyzer(selectedAnalyzer);
Duration total = Duration.ZERO;
if (FindType.ALL_TASK.equals(selectedAnalyzer.getFindType())) {
total = processAnalyzer.calculateWorstCaseDuration(startElement, useCase);
total = processAnalyzer.calculateWorstCaseDuration(iCase, useCase);
} else {
total = processAnalyzer.calculateDurationOfPath(startElement, useCase, flowName);
total = processAnalyzer.calculateDurationOfPath(iCase, useCase, flowName);
}

return total;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.axonivy.utils.process.analyzer.demo.constant;

public enum UseCase {
BIGPROJECT, MEDIUMPROJECT, SMALLPROJECT
BIGPROJECT, MEDIUMPROJECT, SMALLPROJECT, LARGE
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.SetUtils;

import com.axonivy.utils.process.analyzer.internal.constant.FindType;
import com.axonivy.utils.process.analyzer.internal.helper.AnalysisPathHelper;
import com.axonivy.utils.process.analyzer.internal.model.AnalysisPath;
import com.axonivy.utils.process.analyzer.internal.model.CommonElement;
Expand All @@ -42,16 +43,13 @@
import ch.ivyteam.ivy.process.model.diagram.value.Label;
import ch.ivyteam.ivy.process.model.element.EmbeddedProcessElement;
import ch.ivyteam.ivy.process.model.element.event.end.TaskEnd;
import ch.ivyteam.ivy.process.model.element.event.start.EmbeddedStart;
import ch.ivyteam.ivy.process.model.element.event.start.RequestStart;
import ch.ivyteam.ivy.process.model.element.gateway.Alternative;
import ch.ivyteam.ivy.process.model.element.gateway.TaskSwitchGateway;

public class PathFinder {

private enum FindType {
ALL_TASKS, TASKS_ON_PATH
};

private ProcessGraph processGraph;
private List<ProcessElement> froms;
private String flowName;
Expand Down Expand Up @@ -506,7 +504,7 @@ private SubProcessGroup findPathOfSubProcess(ProcessElement subProcessElement, S
.map(ProcessElement::getElement)
.map(SequenceFlow.class::cast).orElse(null);

BaseElement start = processGraph.findStartElementOfProcess((SequenceFlow)lastElement, processElement);
EmbeddedStart start = processGraph.findStartElementOfProcess((SequenceFlow)lastElement, processElement);
List<AnalysisPath> path = findAnalysisPaths(new CommonElement(start), flowName, findType, emptyList());

SubProcessGroup subProcessGroup = new SubProcessGroup(processElement, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public List<String> getParentElementNamesEmbeddedProcessElement(BaseElement pare
return result;
}

public BaseElement findStartElementOfProcess(SequenceFlow sequenceFlow, EmbeddedProcessElement embeddedProcessElement) {
BaseElement start = findStartElementOfProcess(embeddedProcessElement).stream()
public EmbeddedStart findStartElementOfProcess(SequenceFlow sequenceFlow, EmbeddedProcessElement embeddedProcessElement) {
EmbeddedStart start = findStartElementOfProcess(embeddedProcessElement).stream()
.filter(it -> sequenceFlow == null || ((EmbeddedStart) it).getConnectedOuterSequenceFlow().equals(sequenceFlow))
.findFirst()
.map(EmbeddedStart.class::cast)
.orElse(null);
return start;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,30 @@ private ProcessElement correctStartElement(ProcessElement startElement, Analysis
return startElement;
}

private List<DetectedElement> convertPathToDetectedElements(ProcessElement startElement, AnalysisPath path,
Enum<?> useCase, Map<ProcessElement, Duration> timeUntilStarts) {
private List<DetectedElement> convertPathToDetectedElements(ProcessElement startElement, AnalysisPath path, Enum<?> useCase, Map<ProcessElement, Duration> timeUntilStarts) {
List<DetectedElement> result = new ArrayList<>();
Duration timeUntilStart = timeUntilStarts.get(startElement);
Duration durationStart = timeUntilEnd(result, timeUntilStart);
int lengh = path.getElements().size();

for (ProcessElement element : path.getElements()) {
// CommonElement(RequestStart)
for (int i = 0; i < lengh; i++) {
ProcessElement element = path.getElements().get(i);
ProcessElement nextElement = i < lengh - 1 ? path.getElements().get(i + 1) : null;

//It is start node -> Ignored
if (processGraph.isRequestStart(element.getElement())) {
continue;
}

//It is system task -> Ignored
if (element instanceof CommonElement
&& processGraph.isTaskAndCaseModifier(element.getElement())
&& processGraph.isSystemTask(element.getElement())) {
continue;
}

// CommonElement(Alternative)
if (processGraph.isAlternative(element.getElement()) && this.isEnableDescribeAlternative) {
//It is alternative -> base on this.isEnableDescribeAlternative to decide
if (this.isEnableDescribeAlternative && processGraph.isAlternative(element.getElement())) {
var detectedAlternative = createDetectedAlternative(element);
if (detectedAlternative != null) {
result.add(detectedAlternative);
Expand All @@ -152,16 +156,15 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
if (processGraph.isSubProcessCall(element.getElement())) {
SubProcessCall subProcessCall = (SubProcessCall) element.getElement();
if (processGraph.isHandledAsTask(subProcessCall)) {
var detectedSubProcessCall = createDetectedTaskFromSubProcessCall(subProcessCall, useCase,
durationStart);
var detectedSubProcessCall = createDetectedTask(subProcessCall, useCase, durationStart);
if (detectedSubProcessCall != null) {
result.add(detectedSubProcessCall);
durationStart = timeUntilEnd(result, timeUntilStart);
}
}
}

// CommonElement(SingleTaskCreator)
// It is User Task - CommonElement(SingleTaskCreator)
if (processGraph.isSingleTaskCreator(element.getElement())) {
SingleTaskCreator singleTask = (SingleTaskCreator) element.getElement();
var detectedTask = createDetectedTask(singleTask, useCase, durationStart);
Expand All @@ -172,8 +175,9 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
continue;
}

// It is EmbeddedProcessElement
if (element instanceof SubProcessGroup) {
List<AnalysisPath> subPaths = ((SubProcessGroup) element).getInternalPaths();
List<AnalysisPath> subPaths = ((SubProcessGroup) element).getInternalPaths();
List<DetectedElement> allTaskFromSubPath = new ArrayList<>();
for(AnalysisPath subPath : subPaths) {
ProcessElement startSubElement = subPath.getElements().get(0);
Expand All @@ -192,6 +196,7 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
continue;
}

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

Expand All @@ -203,7 +208,8 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
}
continue;
}


// It is TaskSwitchGateway
if (element instanceof CommonElement && processGraph.isSequenceFlow(element.getElement())) {
SequenceFlow sequenceFlow = (SequenceFlow) element.getElement();
if (sequenceFlow.getSource() instanceof TaskSwitchGateway) {
Expand All @@ -219,8 +225,7 @@ private List<DetectedElement> convertPathToDetectedElements(ProcessElement start
return result;
}

private List<DetectedElement> convertTaskParallelGroupToDetectedElement(TaskParallelGroup group, Enum<?> useCase,
Map<ProcessElement, Duration> timeUntilStartAts) {
private List<DetectedElement> convertTaskParallelGroupToDetectedElement(TaskParallelGroup group, Enum<?> useCase, Map<ProcessElement, Duration> timeUntilStartAts) {
List<DetectedElement> tasksWithTaskEnd = convertTaskParallelGroupToDetectedElement(group, useCase,
timeUntilStartAts, true);
List<DetectedElement> tasksInternal = convertTaskParallelGroupToDetectedElement(group, useCase,
Expand Down Expand Up @@ -318,8 +323,7 @@ private DetectedAlternative createDetectedAlternative(ProcessElement processElem
return null;
}

private DetectedElement createDetectedTaskFromSubProcessCall(SubProcessCall subProcessCall, Enum<?> useCase,
Duration timeUntilStartAt) {
private DetectedElement createDetectedTask(SubProcessCall subProcessCall, Enum<?> useCase, Duration timeUntilStartAt) {
String pid = subProcessCall.getPid().getRawPid();
String elementName = subProcessCall.getName();

Expand Down Expand Up @@ -464,4 +468,6 @@ private String getTaskName(TaskConfig taskConfig) {

return defaultIfBlank(taskNameFromRawMacro, taskIdentifier);
}

//private List<AnalysisPath> get
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.axonivy.utils.process.analyzer.internal.constant;

public enum FindType {
ALL_TASKS, TASKS_ON_PATH
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.axonivy.utils.process.analyzer.internal.model;

import java.util.List;

import com.axonivy.utils.process.analyzer.internal.constant.FindType;

public class FindPathProcessor {
private final ProcessElement from;
private final String flowName;
private final FindType findType;
private final List<AnalysisPath> currentPath;

public ProcessElement getFrom() {
return from;
}

public String getFlowName() {
return flowName;
}

public FindType getFindType() {
return findType;
}

public List<AnalysisPath> getCurrentPath() {
return currentPath;
}

public FindPathProcessor(FindPathProcessorBuilder builder) {
this.from = builder.getFrom();
this.flowName = builder.getFlowName();
this.findType = builder.getFindType();
this.currentPath = builder.getCurrentPath();
}

public static class FindPathProcessorBuilder {
private ProcessElement from;
private String flowName;
private FindType findType;
private List<AnalysisPath> currentPath;

public FindPathProcessorBuilder builder() {
return new FindPathProcessorBuilder();
}

public FindPathProcessorBuilder from(ProcessElement from) {
this.from = from;
return this;
}

public FindPathProcessorBuilder flowName(String flowName) {
this.flowName = flowName;
return this;
}

public FindPathProcessorBuilder findType(FindType findType) {
this.findType = findType;
return this;
}

public FindPathProcessorBuilder currentPath(List<AnalysisPath> currentPath) {
this.currentPath = currentPath;
return this;
}

public FindPathProcessor build() {
return new FindPathProcessor(this);
}

public ProcessElement getFrom() {
return from;
}

public String getFlowName() {
return flowName;
}

public FindType getFindType() {
return findType;
}

public List<AnalysisPath> getCurrentPath() {
return currentPath;
}
}
}

0 comments on commit 32c8824

Please sign in to comment.