Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IVYPORTAL-17923: Added Portal AI functions #1181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
0e6cc0e
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 11, 2024
d494c03
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 12, 2024
124baab
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 16, 2024
72ebd41
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 16, 2024
967b6d5
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 17, 2024
4ce4b40
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 17, 2024
bd1935c
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 18, 2024
10aa367
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 25, 2024
484c701
IVYPORTAL-16295 SPIKE UI-PoC for Portal Chatbot
Jan 25, 2024
cde82c1
IVYPORTAL-16295: SPIKE UI-PoC for Portal Chatbot
Jan 25, 2024
3d2ba34
IVYPORTAL-16297 Interactive function: List tasks/cases
Mar 8, 2024
0a1eebf
IVYPORTAL-16297 Interactive function: List tasks/cases
Mar 13, 2024
d573a5c
IVYPORTAL-16297 Interactive function: List tasks/cases
Mar 15, 2024
f902a79
IVYPORTAL-16297 Interactive function: List tasks/cases
Mar 20, 2024
07a2c0d
IVYPORTAL-16297: Interactive function: List tasks/cases
Mar 21, 2024
9e0e0cb
IVYPORTAL-16297: Interactive function: List tasks/cases
Mar 21, 2024
b1e7695
Merge branch 'master' into feature/IVYPORTAL-16295-SPIKE-UI-PoC-for-P…
ntloc-axonivy Apr 10, 2024
cca75a6
IVYPORTAL-16295-SPIKE-UI-PoC-for-Portal-Chatbot - Fix portalstart
ntloc-axonivy Apr 10, 2024
1ebb873
Rename
ntloc-axonivy Apr 11, 2024
dc7d317
Merge branch 'master' of https://github.com/axonivy-market/portal int…
May 18, 2024
b039653
Merge branch 'master' of https://github.com/axonivy-market/portal int…
May 21, 2024
53091bc
IVYPORTAL-16297: Interactive function: List tasks/cases
May 23, 2024
24f13da
Merge branch 'master' of https://github.com/axonivy-market/portal int…
May 23, 2024
5fb950e
Merge branch 'master' of https://github.com/axonivy-market/portal int…
May 24, 2024
122a3bb
IVYPORTAL-16297 Interactive function: List tasks/cases
May 24, 2024
08e19f0
IVYPORTAL-16958 Various or urgent requests in IVYPORTAL - S259 > Upda…
lttung-axonivy May 24, 2024
17741ed
IVYPORTAL-16297 Interactive function: List tasks/cases
May 28, 2024
681ece9
Merge branch 'master' of https://github.com/axonivy-market/portal int…
May 28, 2024
2e743d8
Merge branch 'master' of https://github.com/axonivy-market/portal int…
May 29, 2024
1aa3e83
Implement partly
Jul 3, 2024
8e96318
IVYPORTAL-17132 Stage 1: Move Python AI application to Java (ivy proj…
mnhnam-axonivy Jul 4, 2024
32c42a3
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Jul 5, 2024
2d242cf
Merge branch 'feature/IVYPORTAL-16295-SPIKE-UI-PoC-for-Portal-Chatbot…
mnhnam-axonivy Jul 5, 2024
c72e3f9
IVYPORTAL-17132 Stage 1: Move Python AI application to Java (ivy proj…
Jul 8, 2024
1b47133
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Jul 9, 2024
2409b74
Merge branch 'feature/IVYPORTAL-16295-SPIKE-UI-PoC-for-Portal-Chatbot…
mnhnam-axonivy Jul 9, 2024
cd35668
Merge branch 'feature/IVYPORTAL-17132-Stage-1-Move-Python-AI-applicat…
mnhnam-axonivy Jul 9, 2024
1d77a88
IVYPORTAL-17132 Stage 1: Move Python AI application to Java (ivy proj…
mnhnam-axonivy Jul 9, 2024
fd9453e
IVYPORTAL-17132 Stage 1: Move Python AI application to Java (ivy proj…
mnhnam-axonivy Jul 9, 2024
25e8257
IVYPORTAL-17132 Stage 1: Move Python AI application to Java (ivy proj…
mnhnam-axonivy Jul 11, 2024
35670bd
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 12, 2024
c9c1b36
IVYPORTAL-17134 Stage 1: find processes by name or description
Jul 14, 2024
ffab43f
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 15, 2024
43392f3
IVYPORTAL-17134 Stage 1: find processes by name or description
Jul 16, 2024
d0f9b08
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 17, 2024
2348d96
feature/IVYPORTAL-17134-Stage-1-find-processes-by-name-or-description
lmluat-axonivy Jul 18, 2024
40ec53f
Merge branch 'feature/IVYPORTAL-17134-Stage-1-find-processes-by-name-…
lmluat-axonivy Jul 18, 2024
e069d14
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 18, 2024
54d2f97
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 18, 2024
e64fe07
find-process
lmluat-axonivy Jul 18, 2024
87491b9
Merge branch 'feature/IVYPORTAL-17134-Stage-1-find-processes-by-name-…
lmluat-axonivy Jul 18, 2024
8a0ce66
IVYPORTAL-17134 Stage 1: find processes by name or description
Jul 21, 2024
110f15b
find-process
lmluat-axonivy Jul 22, 2024
e18c925
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 22, 2024
87a9707
find-process
lmluat-axonivy Jul 22, 2024
b357416
Merge branch 'feature/IVYPORTAL-17134-Stage-1-find-processes-by-name-…
lmluat-axonivy Jul 22, 2024
6b18cc9
find-process
lmluat-axonivy Jul 23, 2024
da46ad0
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 23, 2024
5f9463d
find-process
lmluat-axonivy Jul 23, 2024
82ef0f7
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 23, 2024
fe84faf
find-process
lmluat-axonivy Jul 24, 2024
307b8c9
Merge branch 'feature/IVYPORTAL-17134-Stage-1-find-processes-by-name-…
lmluat-axonivy Jul 24, 2024
1fcb9aa
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 25, 2024
ab8da39
IVYPORTAL-17134 Stage 1: find processes by name or description
Jul 29, 2024
7448eee
IVYPORTAL-17170 Stage 1: Start process by name or description
mnhnam-axonivy Jul 30, 2024
2e22230
IVYPORTAL-17170 Stage 1: Start process by name or description
mnhnam-axonivy Jul 30, 2024
674348d
IVYPORTAL-17134 Stage 1: find processes by name or description
mnhnam-axonivy Jul 30, 2024
57744fd
IVYPORTAL-17170 Stage 1: Start process by name or description
mnhnam-axonivy Jul 31, 2024
8f9a75a
IVYPORTAL-17170 Stage 1: Start process by name or description
Jul 31, 2024
2c9a361
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Aug 5, 2024
9b20eea
IVYPORTAL-17170 Stage 1: Start process by name or description
mnhnam-axonivy Aug 5, 2024
8fd3e1e
IVYPORTAL-17139 Stage 2: Assistant Details - General settings
mnhnam-axonivy Aug 8, 2024
a63bbc9
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Aug 19, 2024
4bed6ee
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Aug 19, 2024
b56ec3e
IVYPORTAL-17170 Stage 1: Start process by name or description
mnhnam-axonivy Aug 19, 2024
35af391
IVYPORTAL-17139 Stage 2: Assistant Details - General settings
mnhnam-axonivy Aug 23, 2024
dd3110b
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Aug 26, 2024
9a007f8
IVYPORTAL-17137 Stage 2: Assistant Configuration
mnhnam-axonivy Aug 27, 2024
830b292
IVYPORTAL-17137 Stage 2: Assistant Configuration
mnhnam-axonivy Aug 28, 2024
c526010
IVYPORTAL-17432 Stage 1: Create a Marketplace item for Portal Assista…
Aug 29, 2024
ebcaf1d
Merge branch 'feature/IVYPORTAL-17170-Stage-1-Start-process-by-name-o…
Aug 29, 2024
b86ff61
IVYPORTAL-17432 Stage 1: Create a Marketplace item for Portal Assista…
mnhnam-axonivy Aug 30, 2024
bd422fc
IVYPORTAL-17432 Stage 1: Create a Marketplace item for Portal Assista…
mnhnam-axonivy Sep 12, 2024
e58404e
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Sep 16, 2024
48f443c
Revert "Merge branch 'master' of https://github.com/axonivy-market/po…
mnhnam-axonivy Sep 16, 2024
1bb38b5
Revert "Revert "Merge branch 'master' of https://github.com/axonivy-m…
mnhnam-axonivy Sep 16, 2024
05424e1
IVYPORTAL-17432 Stage 1: Create a Marketplace item for Portal Assista…
mnhnam-axonivy Sep 16, 2024
c458215
IVYPORTAL-17537 Stage 1 - AI Assistant UX Improvement
Sep 17, 2024
9764864
IVYPORTAL-17537 Stage 1 - AI Assistant UX Improvement
mnhnam-axonivy Sep 17, 2024
57b713e
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Sep 18, 2024
51023df
IVYPORTAL-17432 Stage 1: Create a Marketplace item for Portal Assista…
mnhnam-axonivy Sep 23, 2024
b9cd01b
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Sep 23, 2024
806c2af
IVYPORTAL-17352 Stage 1 - Make Portal Adaptions documented
mnhnam-axonivy Sep 24, 2024
6ed13b1
IVYPORTAL-17432 Stage 1: Create a Marketplace item for Portal Assista…
mnhnam-axonivy Sep 24, 2024
31403fc
IVYPORTAL-17432 Stage 1: Create a Marketplace item for Portal Assista…
mnhnam-axonivy Sep 26, 2024
e8a7891
IVYPORTAL-17352 Stage 1 - Make Portal Adaptions documented
mnhnam-axonivy Oct 1, 2024
240d867
Merge pull request #1080 from axonivy-market/Document/IVYPORTAL-17352…
mnhnam-axonivy Oct 1, 2024
44e245a
IVYPORTAL-16305 Stage 2: Assistant Details - Function list
mnhnam-axonivy Oct 8, 2024
b1d00a2
Merge branch 'feature/IVYPORTAL-17170-Stage-1-Start-process-by-name-o…
mnhnam-axonivy Oct 8, 2024
ce23e8e
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Oct 8, 2024
2458584
IVYPORTAL-16305 Stage 2: Assistant Details - Function list
mnhnam-axonivy Oct 8, 2024
b81b274
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Oct 15, 2024
d358198
IVYPORTAL-17131 Stage 1: Create a Marketplace item for Portal Assistant
mnhnam-axonivy Oct 15, 2024
c6e96d2
IVYPORTAL-17131 Stage 1: Create a Marketplace item for Portal Assistant
mnhnam-axonivy Oct 15, 2024
265bc6e
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Oct 23, 2024
8b10ba5
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Oct 28, 2024
4aa7df2
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Oct 31, 2024
e40f881
Merge branch 'feature/IVYPORTAL-17170-Stage-1-Start-process-by-name-o…
mnhnam-axonivy Oct 31, 2024
313b1d8
IVYPORTAL-17135 Stage 2: Improve the quality of answers from OpenSearch
mnhnam-axonivy Nov 12, 2024
3e7f78c
IVYPORTAL-17135 Stage 2: Improve the quality of answers from OpenSearch
mnhnam-axonivy Nov 12, 2024
e22c179
IVYPORTAL-17982 Various or urgent requests in IVYPORTAL - S268 > IVYP…
mnhnam-axonivy Nov 19, 2024
b77ab49
Merge branch 'master' of https://github.com/axonivy-market/portal int…
mnhnam-axonivy Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AxonIvyPortal/portal-components/cms/cms_de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ Dialogs:
IVY_PROCESS: Geschäftsprozess
ProcessViewerIFrameTitle: Prozessbetrachterrahmen
Labels:
AI:
Error:
CanceledFlow: You have canceled the flow. If you have any requests, please let me know.
ErrorWhenProceedRequest: An error has occurred while trying to process your request. Please try again later.
SomethingWentWrong: Something went wrong when proceed your request. Please try again later.
DisabledUserPrefix: (inaktiv)
NoName: kein Name
NoResults: Keine Ergebnisse
Expand Down
5 changes: 5 additions & 0 deletions AxonIvyPortal/portal-components/cms/cms_en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Dialogs:
IVY_PROCESS: Business Process
ProcessViewerIFrameTitle: Process viewer frame
Labels:
AI:
Error:
CanceledFlow: You have canceled the flow. If you have any requests, please let me know.
ErrorWhenProceedRequest: An error has occurred while trying to process your request. Please try again later.
SomethingWentWrong: Something went wrong when proceed your request. Please try again later.
DisabledUserPrefix: (disabled)
NoName: no name
NoResults: No results
Expand Down
5 changes: 5 additions & 0 deletions AxonIvyPortal/portal-components/cms/cms_es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Dialogs:
IVY_PROCESS: Proceso de negocio
ProcessViewerIFrameTitle: Marco del visor de procesos
Labels:
AI:
Error:
CanceledFlow: You have canceled the flow. If you have any requests, please let me know.
ErrorWhenProceedRequest: An error has occurred while trying to process your request. Please try again later.
SomethingWentWrong: Something went wrong when proceed your request. Please try again later.
DisabledUserPrefix: (inactivo)
NoName: Sin nombre
NoResults: Sin resultados
Expand Down
5 changes: 5 additions & 0 deletions AxonIvyPortal/portal-components/cms/cms_fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Dialogs:
IVY_PROCESS: Processus d'entreprise
ProcessViewerIFrameTitle: Cadre de visualisation du processus
Labels:
AI:
Error:
CanceledFlow: You have canceled the flow. If you have any requests, please let me know.
ErrorWhenProceedRequest: An error has occurred while trying to process your request. Please try again later.
SomethingWentWrong: Something went wrong when proceed your request. Please try again later.
DisabledUserPrefix: (désactivé)
NoName: Aucun nom
NoResults: Aucun résultat
Expand Down
1 change: 0 additions & 1 deletion AxonIvyPortal/portal-components/config/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# please add a 'variables.yaml' in the sub directory '_<environment>'.
#
Variables:
#myVariable: value
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

import com.axonivy.portal.components.dto.SecurityMemberDTO;
import com.axonivy.portal.components.dto.UserDTO;
import com.axonivy.portal.components.util.SecurityMemberDisplayNameUtils;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.security.ISecurityMember;

@ManagedBean
Expand All @@ -19,6 +21,15 @@ public String generateBriefDisplayNameForSecurityMember(ISecurityMember member,
return SecurityMemberDisplayNameUtils.generateBriefDisplayNameForSecurityMember(member, securityMemberName);
}

public String generateBriefDisplayNameForSecurityMember(
SecurityMemberDTO memberDTO) {
ISecurityMember member = Ivy.security().members()
.findById(memberDTO.getSecurityMemberId());
return SecurityMemberDisplayNameUtils
.generateBriefDisplayNameForSecurityMember(member,
member.getMemberName());
}

public String getDisplayNameForUserDTO(UserDTO user) {
return SecurityMemberDisplayNameUtils.generateDisplayNameForUserDTO(user);
}
Expand Down
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;
}
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ private List<UserDTO> queryUsers(String query, int startIndex, int count, List<S

if (CollectionUtils.isNotEmpty(fromRoles)) {
UserQuery hasRolesQuery = queryHasRoles(fromRoles);
filterQuery.andOverall(hasRolesQuery);
if (hasRolesQuery != null) {
filterQuery.andOverall(hasRolesQuery);
}
}
excludeUsername(excludedUsernames, filterQuery);

Expand Down Expand Up @@ -99,6 +101,10 @@ private UserQuery queryHasRoles(List<String> fromRoles) {
}
}

if (CollectionUtils.isEmpty(roles)) {
return null;
}

UserQuery hasRolesQuery = UserQuery.create();
IFilterQuery hasRolesFilter = hasRolesQuery.where();
for (IRole role : roles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,78 @@
import com.axonivy.portal.components.service.exception.PortalException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* This class provides method to convert Business entity object into Json value
* and reverse
*/
public final class BusinessEntityConverter {
public static ObjectMapper objectMapper;
public static ObjectMapper objectMapper;

private BusinessEntityConverter() {
}
private BusinessEntityConverter() {
}

public static String entityToJsonValue(BusinessEntity entity) {
try {
return getObjectMapper().writeValueAsString(entity);
} catch (JsonProcessingException e) {
throw new PortalException(e);
}
}
public static String entityToJsonValue(BusinessEntity entity) {
try {
return getObjectMapper().writeValueAsString(entity);
} catch (JsonProcessingException e) {
throw new PortalException(e);
}
}

public static <T> T jsonValueToEntity(String jsonValue, Class<T> classType) {
try {
return getObjectMapper().readValue(jsonValue, classType);
} catch (IOException e) {
throw new PortalException(e);
}
}
public static <T> T jsonValueToEntity(String jsonValue, Class<T> classType) {
try {
return getObjectMapper().readValue(jsonValue, classType);
} catch (IOException e) {
throw new PortalException(e);
}
}

public static String entityToJsonValue(Object entity) {
try {
return getObjectMapper().writeValueAsString(entity);
} catch (JsonProcessingException e) {
throw new PortalException(e);
}
}
public static String entityToJsonValue(Object entity) {
try {
return getObjectMapper().writeValueAsString(entity);
} catch (JsonProcessingException e) {
throw new PortalException(e);
}
}

public static <T> List<T> jsonValueToEntities(String jsonValue, Class<T> classType) {
if (StringUtils.isBlank(jsonValue)) {
return new ArrayList<>();
}
try {
return getObjectMapper().readValue(jsonValue,
getObjectMapper().getTypeFactory().constructCollectionType(List.class, classType));
} catch (IOException e) {
throw new PortalException(e);
}
}
public static JsonNode entityToJsonNode(Object entity) {
try {
return getObjectMapper().readTree(entityToJsonValue(entity));
} catch (JsonProcessingException e) {
throw new PortalException(e);
}
}

public static ObjectMapper getObjectMapper() {
if (objectMapper == null) {
objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
return objectMapper;
}
public static <T> List<T> jsonValueToEntities(String jsonValue,
Class<T> classType) {
if (StringUtils.isBlank(jsonValue)) {
return new ArrayList<>();
}
try {
return getObjectMapper().readValue(jsonValue, getObjectMapper()
.getTypeFactory().constructCollectionType(List.class, classType));
} catch (IOException e) {
throw new PortalException(e);
}
}

public static ObjectMapper getObjectMapper() {
if (objectMapper == null) {
objectMapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
return objectMapper;
}

public static String prettyPrintEntityToJsonValue(Object entity) {
try {
return getObjectMapper().writerWithDefaultPrettyPrinter()
.writeValueAsString(entity);
} catch (JsonProcessingException e) {
throw new PortalException(e);
}
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;


import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.security.exec.Sudo;
import ch.ivyteam.ivy.workflow.IWorkflowSession;
Expand All @@ -37,6 +36,14 @@ public List<IWebStartable> findProcesses() {
});
}

public List<IWebStartable> findAllProcesses() {
return Sudo.get(() -> {
return Ivy.session().getAllStartables()
.filter(process -> isNotPortalHomeAndMSTeamsProcess(process))
.collect(Collectors.toList());
});
}

private List<IWebStartable> findStartablesWithoutPortalHomeAndMSTeamsProcess(IWorkflowSession session) {
return session.getStartables().stream().filter(process -> isNotPortalHomeAndMSTeamsProcess(process))
.collect(Collectors.toList());
Expand All @@ -55,4 +62,4 @@ public List<IWebStartable> findCustomDashboardProcesses() {
private Predicate<? super IWebStartable> filterByCustomDashboardProcess() {
return start -> BooleanUtils.toBoolean(start.customFields().value(IS_DASHBOARD_PROCESS));
}
}
}
Loading
Loading