-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1181 from axonivy-market/feature/IVYPORTAL-17170-…
…Stage-1-Start-process-by-name-or-description IVYPORTAL-17923: Merge Portal AI functions to master
- Loading branch information
Showing
78 changed files
with
3,091 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,3 @@ | |
# please add a 'variables.yaml' in the sub directory '_<environment>'. | ||
# | ||
Variables: | ||
#myVariable: value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
AxonIvyPortal/portal-components/src/com/axonivy/portal/components/dto/AiResultDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.axonivy.portal.components.dto; | ||
|
||
import com.axonivy.portal.components.enums.AIState; | ||
|
||
public class AiResultDTO { | ||
private String result; | ||
private String resultForAI; | ||
private AIState state; | ||
|
||
public String getResult() { | ||
return result; | ||
} | ||
|
||
public void setResult(String result) { | ||
this.result = result; | ||
} | ||
|
||
public String getResultForAI() { | ||
return resultForAI; | ||
} | ||
|
||
public void setResultForAI(String resultForAI) { | ||
this.resultForAI = resultForAI; | ||
} | ||
|
||
public AIState getState() { | ||
return state; | ||
} | ||
|
||
public void setState(AIState state) { | ||
this.state = state; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
AxonIvyPortal/portal-components/src/com/axonivy/portal/components/enums/AIState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.axonivy.portal.components.enums; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
public enum AIState { | ||
OPEN, IN_PROGRESS, DONE, ERROR, TRIGGER; | ||
|
||
@JsonValue | ||
public String value() { | ||
return this.name().toLowerCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...yPortal/portal-components/src/com/axonivy/portal/components/publicapi/AiAssistantAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.axonivy.portal.components.publicapi; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import com.axonivy.portal.components.dto.AiResultDTO; | ||
import com.axonivy.portal.components.enums.AIState; | ||
import com.axonivy.portal.components.service.impl.ProcessService; | ||
|
||
import ch.ivyteam.ivy.environment.Ivy; | ||
import ch.ivyteam.ivy.workflow.start.IWebStartable; | ||
import ch.ivyteam.util.ExceptionUtil; | ||
|
||
public class AiAssistantAPI { | ||
private static final String IFRAME_RESULT_PATTERN = "<iframe>%s</iframe>"; | ||
private static final String EXECUTE_RESULT_PATTERN = "<execute>%s</execute>"; | ||
|
||
public static void addIframeIvyProcessLinkToAiResult(String link, | ||
Map<String, String> params, AiResultDTO result) { | ||
try { | ||
IWebStartable process = initWebStartable(link); | ||
result.setResult(String.format(IFRAME_RESULT_PATTERN, | ||
process.getLink().queryParams(params).getRelative())); | ||
} catch (Exception e) { | ||
result = generateErrorAiResult(e, | ||
Ivy.cms().co("/Labels/AI/Error/ErrorWhenProceedRequest")); | ||
} | ||
} | ||
|
||
public static String generateExecutableResult(String link) { | ||
return String.format(EXECUTE_RESULT_PATTERN, link); | ||
} | ||
|
||
private static IWebStartable initWebStartable(String processPath) { | ||
if (StringUtils.isBlank(processPath)) { | ||
return null; | ||
} | ||
|
||
return ProcessService.getInstance().findAllProcesses().stream() | ||
.filter(process -> process.getId().contentEquals(processPath)) | ||
.findFirst().orElse(null); | ||
} | ||
|
||
public static AiResultDTO generateErrorAiResult(Throwable error, | ||
String errorDescription) { | ||
AiResultDTO result = new AiResultDTO(); | ||
result.setResult(errorDescription.concat(StringUtils.LF) | ||
.concat(ExceptionUtil.getAllMessages(error))); | ||
result.setState(AIState.ERROR); | ||
|
||
return result; | ||
} | ||
|
||
public static AiResultDTO generateErrorAiResult(String error) { | ||
AiResultDTO result = new AiResultDTO(); | ||
result.setResult(error); | ||
result.setResultForAI(error); | ||
result.setState(AIState.ERROR); | ||
|
||
return result; | ||
} | ||
|
||
public static AiResultDTO createSomethingWentWrongError() { | ||
AiResultDTO result = new AiResultDTO(); | ||
result.setResult(Ivy.cms().co("/Labels/AI/Error/SomethingWentWrong")); | ||
result.setState(AIState.ERROR); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.