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

Feature/ivyportal 17132 stage 1 move python ai application to java ivy project #852

Open
wants to merge 9 commits into
base: feature/IVYPORTAL-16295-SPIKE-UI-PoC-for-Portal-Chatbot
Choose a base branch
from
Open
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public enum PortalVariable {
DASHBOARD("Portal.Dashboard"),
DASHBOARD_ORDER("Portal.Dashboard.Order"),
DASHBOARD_TEMPLATES("Portal.DashboardTemplates"),
USER_MENU("Portal.UserMenu"),
CHATBOT_ENDPOINT("PortalAiUrl");
USER_MENU("Portal.UserMenu");

public String key;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package com.axonivy.portal.components.util;
package com.axonivy.portal.components.publicapi;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.axonivy.portal.components.enums.ai.IvyToolResultType;
import com.axonivy.portal.components.service.impl.ProcessService;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.workflow.start.IWebStartable;

public class AssistantUtils {
public class AiAssistantAPI {
private static final String IFRAME_RESULT_PATTERN = "<iframe>%s</iframe>";
private static final String ERROR_RESULT_PATTERN = "<error>%s</error>";

public static String generateLinkToIvyProcess(String link,
Map<String, String> params) {
try {
IWebStartable process = initWebStartable(link);
return IvyToolResultType.IFRAME
.format(process.getLink().queryParams(params).getRelative());
return String.format(IFRAME_RESULT_PATTERN,
process.getLink().queryParams(params).getRelative());
} catch (Exception e) {
return IvyToolResultType.ERROR
.format(Ivy.cms().co("/Labels/AI/Error/ErrorWhenProceedRequest"));
return String.format(ERROR_RESULT_PATTERN,
Ivy.cms().co("/Labels/AI/Error/ErrorWhenProceedRequest"));
}
}

Expand All @@ -38,6 +39,6 @@ public static String generateErrorResult(String error) {
if (StringUtils.isBlank(error)) {
return "";
}
return IvyToolResultType.ERROR.format(error);
return String.format(ERROR_RESULT_PATTERN, error);
}
}
14 changes: 0 additions & 14 deletions AxonIvyPortal/portal/config/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ Variables:
# [enum: 1, 2, 3, 4, 5]
MaxConnection: 3

# Endpoint URL for the RESTful service of Portal chatbot
ChatBotEndpoint: localhost:8018

Histories:
# If true, case note does not display any system tasks for non-administrator users.
HideSystemTasks: true
Expand Down Expand Up @@ -302,17 +299,6 @@ Variables:
# Set this property to true to enable the DeepL translation support
Enable: false

# You can define AI assistants here
# [file: json]
Assistant:

# You can define AI Tools
# [file: json]
AiTool:

#URL to the REST service endpoint of Portal AI
PortalAiUrl: 'http://localhost:8018'

# You can define the application name via this JSON file.
# It will be shown with the page title
ApplicationName: Axon Ivy
Expand Down
71 changes: 0 additions & 71 deletions AxonIvyPortal/portal/config/variables/Portal/AiTool.json

This file was deleted.

7 changes: 0 additions & 7 deletions AxonIvyPortal/portal/config/variables/Portal/Assistant.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
PortalToolsData #class
portalkit #namespace
tool ch.ivy.addon.portalkit.dto.ai.IvyTool #field
taskDashboardWidget ch.ivy.addon.portalkit.dto.dashboard.TaskDashboardWidget #field
name String #field
description String #field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"config" : {
"output" : {
"code" : [
"import com.axonivy.portal.components.util.AssistantUtils;",
"import com.axonivy.portal.components.publicapi.AiAssistantAPI;",
"import org.apache.commons.collections4.CollectionUtils;",
"import com.axonivy.portal.components.persistence.converter.BusinessEntityConverter;",
"import org.apache.commons.lang3.StringUtils;",
Expand All @@ -65,7 +65,7 @@
"if (CollectionUtils.isNotEmpty(in.users)) {",
" in.result = BusinessEntityConverter.entityToJsonValue(in.users);",
"} else {",
" in.result = AssistantUtils.generateErrorResult(ivy.cms.co(\"/Labels/AI/Error/CannotFindUser\"));",
" in.result = AiAssistantAPI.generateErrorResult(ivy.cms.co(\"/Labels/AI/Error/CannotFindUser\"));",
"}"
]
},
Expand Down Expand Up @@ -126,8 +126,8 @@
"config" : {
"output" : {
"code" : [
"import com.axonivy.portal.components.publicapi.AiAssistantAPI;",
"import ch.ivyteam.ivy.application.IApplication;",
"import com.axonivy.portal.components.util.AssistantUtils;",
"import java.util.HashMap;",
"import java.util.Map;",
"",
Expand All @@ -137,7 +137,7 @@
"params.put(\"taskState\", in.taskState);",
"params.put(\"taskPriority\", in.taskPriority);",
"",
"in.result = AssistantUtils.generateLinkToIvyProcess(IApplication.current().getName() + \"/portal/AI Tool Processes/PortalTools/findTasksTool.ivp\", params);"
"in.result = AiAssistantAPI.generateLinkToIvyProcess(IApplication.current().getName() + \"/portal/AI Tool Processes/PortalTools/findTasksTool.ivp\", params);"
]
}
},
Expand All @@ -154,8 +154,8 @@
"config" : {
"output" : {
"code" : [
"import com.axonivy.portal.components.publicapi.AiAssistantAPI;",
"import org.apache.commons.lang3.StringUtils;",
"import com.axonivy.portal.components.util.AssistantUtils;",
"import com.axonivy.portal.util.AiToolUtils;",
"",
"in.validationError = AiToolUtils.validateTaskState(in.taskState);",
Expand All @@ -164,7 +164,7 @@
"}",
"",
"if(StringUtils.isNotBlank(in.validationError)) {",
" in.result = AssistantUtils.generateErrorResult(in.validationError);",
" in.result = AiAssistantAPI.generateErrorResult(in.validationError);",
"}"
]
}
Expand Down Expand Up @@ -247,13 +247,13 @@
"config" : {
"output" : {
"code" : [
"import com.axonivy.portal.components.publicapi.AiAssistantAPI;",
"import org.apache.commons.lang3.StringUtils;",
"import com.axonivy.portal.util.AiToolUtils;",
"import com.axonivy.portal.components.util.AssistantUtils;",
"",
"in.validationError = AiToolUtils.validateCaseState(in.taskState);",
"if(StringUtils.isNotBlank(in.validationError)) {",
" in.result = AssistantUtils.generateErrorResult(in.validationError);",
" in.result = AiAssistantAPI.generateErrorResult(in.validationError);",
"}"
]
}
Expand Down Expand Up @@ -293,8 +293,8 @@
"config" : {
"output" : {
"code" : [
"import com.axonivy.portal.components.publicapi.AiAssistantAPI;",
"import ch.ivyteam.ivy.application.IApplication;",
"import com.axonivy.portal.components.util.AssistantUtils;",
"import java.util.HashMap;",
"import java.util.Map;",
"",
Expand All @@ -303,7 +303,7 @@
"params.put(\"caseDescription\", in.taskDescription);",
"params.put(\"caseState\", in.taskState);",
"",
"in.result = AssistantUtils.generateLinkToIvyProcess(IApplication.current().getName() + \"/portal/AI Tool Processes/PortalTools/findCasesTool.ivp\", params);"
"in.result = AiAssistantAPI.generateLinkToIvyProcess(IApplication.current().getName() + \"/portal/AI Tool Processes/PortalTools/findCasesTool.ivp\", params);"
]
}
},
Expand Down
32 changes: 0 additions & 32 deletions AxonIvyPortal/portal/processes/Start Processes/PortalStart.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -4906,37 +4906,5 @@
"connect" : [
{ "id" : "f294", "to" : "f271" }
]
}, {
"id" : "f282",
"type" : "RequestStart",
"name" : "PortalChatDashboard",
"config" : {
"signature" : "PortalChatDashboard"
},
"visual" : {
"at" : { "x" : 96, "y" : 4192 }
},
"connect" : [
{ "id" : "f287", "to" : "f285" }
]
}, {
"id" : "f285",
"type" : "DialogCall",
"name" : "ChatDashboard",
"config" : {
"dialog" : "com.axonivy.portal.component.ChatDashboard:start()"
},
"visual" : {
"at" : { "x" : 280, "y" : 4192 }
},
"connect" : [
{ "id" : "f290", "to" : "f286" }
]
}, {
"id" : "f286",
"type" : "TaskEnd",
"visual" : {
"at" : { "x" : 464, "y" : 4192 }
}
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.Map;
import java.util.Optional;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
Expand All @@ -12,9 +13,11 @@
import com.axonivy.portal.components.service.IvyAdapterService;

import ch.ivy.addon.portalkit.enums.GlobalVariable;
import ch.ivy.addon.portalkit.enums.PortalVariable;
import ch.ivy.addon.portalkit.service.AiProcessService;
import ch.ivy.addon.portalkit.service.GlobalSettingService;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.model.value.WebLink;
import ch.ivyteam.ivy.workflow.IProcessStart;

@ManagedBean
@ViewScoped
Expand All @@ -25,6 +28,7 @@ public class ChatRendererBean implements Serializable {

private Boolean isGroupChatRendered;
private Boolean isPrivateChatRendered;
private IProcessStart assistantDashboardProcess;

public boolean getIsChatRendered() {
return getIsGroupChatRendered() || getIsPrivateChatRendered();
Expand Down Expand Up @@ -62,7 +66,14 @@ public boolean isExpressCreationTask() {
return Ivy.wfTask().customFields().stringField(EXPRESS_CREATION_TASK).get().isPresent();
}

public boolean getIsChatbotRendered() {
return !StringUtils.isBlank(Ivy.var().get(PortalVariable.CHATBOT_ENDPOINT.key));
public boolean getIsAssistantDashboardRendered() {
if (this.assistantDashboardProcess == null) {
this.assistantDashboardProcess = AiProcessService.getInstance()
.findAssistantDashboardProcess();
}
return StringUtils.isNotBlank(Optional.ofNullable(assistantDashboardProcess)
.map(IProcessStart::getLinkEmbedded).map(WebLink::getRelative)
.orElse(""));
}

}
Loading