From da59e63a0190316673b4b9ef133ff65129dfeab0 Mon Sep 17 00:00:00 2001 From: "AAVN\\ntnchuong" Date: Tue, 28 May 2024 15:23:12 +0700 Subject: [PATCH] TE-588: handle to load right workflow or all start process --- .../FlowParallelInOrder.p.json | 2 +- .../analyzer/demo/ProcessAnalyzerBean.java | 29 +++++++++++++++++-- .../AnalyzerSelection/AnalyzerSelection.xhtml | 4 +-- .../AnalyzerSelectionProcess.p.json | 6 ++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/process-analyzer-demo/processes/Analysis Processes/FlowParallelInOrder.p.json b/process-analyzer-demo/processes/Analysis Processes/FlowParallelInOrder.p.json index eff6b97b..9f52547e 100644 --- a/process-analyzer-demo/processes/Analysis Processes/FlowParallelInOrder.p.json +++ b/process-analyzer-demo/processes/Analysis Processes/FlowParallelInOrder.p.json @@ -1,6 +1,6 @@ { "$schema" : "https://json-schema.axonivy.com/process/11.2.2/process.json", - "id" : "18E3BEFFB97FCA4D", + "id" : "18E3BEFFB97FCA4E", "config" : { "data" : "com.axonivy.utils.process.analyzer.demo.Data" }, diff --git a/process-analyzer-demo/src/com/axonivy/utils/process/analyzer/demo/ProcessAnalyzerBean.java b/process-analyzer-demo/src/com/axonivy/utils/process/analyzer/demo/ProcessAnalyzerBean.java index db7ddfb7..cf66159c 100644 --- a/process-analyzer-demo/src/com/axonivy/utils/process/analyzer/demo/ProcessAnalyzerBean.java +++ b/process-analyzer-demo/src/com/axonivy/utils/process/analyzer/demo/ProcessAnalyzerBean.java @@ -32,6 +32,7 @@ import ch.ivyteam.ivy.process.model.element.EmbeddedProcessElement; import ch.ivyteam.ivy.process.model.element.ProcessElement; import ch.ivyteam.ivy.process.model.element.SingleTaskCreator; +import ch.ivyteam.ivy.process.model.element.event.start.RequestStart; import ch.ivyteam.ivy.process.model.element.gateway.Alternative; import ch.ivyteam.ivy.process.rdm.IProcess; import ch.ivyteam.ivy.process.rdm.IProcessManager; @@ -161,10 +162,28 @@ public String getDisplayDetectedElement(DetectedElement element) { return String.format("%s (%s)", elementName, shortPid); } - public String getProcessWebLink() { + public String getProcessWebLink(SingleTaskCreator startElement) throws Exception { + IWebStartable webStartable = null; String guid = this.selectedAnalyzer.getProcess().getPid().getProcessGuid(); - IWebStartable webStartable = Ivy.session().getStartables().stream() - .filter(it -> it.getLink().toRelativeUri().getPath().contains(guid)).findFirst().orElse(null); + List listStartElement = getStartElementsOfProcess(this.selectedAnalyzer.getProcess()); + + List startElementNames = listStartElement.stream().map(BaseElement::getName).toList(); + String elementName = startElementNames.stream().filter(name -> name.equals(startElement.getName())).findFirst() + .orElse(null); + + for (BaseElement startNode : listStartElement) { + List listElements = this.processAnalyzer.findAllTasks(startNode, null); + boolean isExist = listElements.stream().anyMatch(it -> it.getElementName().equals(startElement.getName())); + if (isExist) { + elementName = startNode.getName(); + break; + } + } + + final String startName = elementName; + webStartable = Ivy.session().getStartables().stream() + .filter(it -> it.getLink().toRelativeUri().getPath().contains(guid + "/" + startName)).findFirst() + .orElse(null); if (webStartable != null) { return ProcessViewer.of((IProcessWebStartable) webStartable).url().toWebLink().getRelative(); @@ -211,6 +230,10 @@ private static List getElementOfProcess(Process process) { return elements; } + private List getStartElementsOfProcess(Process process) { + return getElementOfProcess(process).stream().filter(item -> item instanceof RequestStart).toList(); + } + private static List getElementOfProcesses(List processElements) { if (processElements.isEmpty()) { return emptyList(); diff --git a/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelection.xhtml b/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelection.xhtml index 45663a7d..ece7a525 100644 --- a/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelection.xhtml +++ b/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelection.xhtml @@ -27,7 +27,7 @@ @@ -40,7 +40,7 @@ value="#{data.processAnalyzerBean.selectedAnalyzer.elements}" var="element" itemLabel="#{element.name}" itemValue="#{element}" /> diff --git a/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json b/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json index b6544522..686f5f55 100644 --- a/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json +++ b/process-analyzer-demo/src_hd/com/axonivy/utils/process/analyzer/demo/component/AnalyzerSelection/AnalyzerSelectionProcess.p.json @@ -75,7 +75,6 @@ "code" : [ "if(in.processAnalyzerBean.selectedAnalyzer is initialized) {", " in.processAnalyzerBean.selectedAnalyzer.elements = in.processAnalyzerBean.getAllTaskModifier();", - " in.processAnalyzerBean.selectedAnalyzer.processPath = in.processAnalyzerBean.getProcessWebLink();", "}" ] } @@ -192,7 +191,10 @@ "name" : "init alternative", "config" : { "output" : { - "code" : "in.processAnalyzerBean.selectedAnalyzer.alternatives = in.processAnalyzerBean.getALternativeWithMoreThanOneOutgoing();" + "code" : [ + "in.processAnalyzerBean.selectedAnalyzer.alternatives = in.processAnalyzerBean.getALternativeWithMoreThanOneOutgoing();", + "in.processAnalyzerBean.selectedAnalyzer.processPath = in.processAnalyzerBean.getProcessWebLink(in.processAnalyzerBean.selectedAnalyzer.startElement);" + ] } }, "visual" : {