From b5b8dd31677f6db684244bfe980f66e8908cd350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20V=C4=A9nh=20Thi=E1=BB=87n=20Ph=C3=BAc?= Date: Fri, 6 Dec 2024 14:10:19 +0700 Subject: [PATCH] MARP-1546 Handle Feedbacks --- .../vertexai/managedBean/GeminiDataBean.java | 6 +-- .../vertexai/chatWithAi/chatWithAi.xhtml | 54 +++++++++---------- .../webContent/layouts/styles/chatwithai.css | 5 ++ .../GeminiDataRequestServiceUtilTest.java | 44 +++++++++++++++ 4 files changed, 77 insertions(+), 32 deletions(-) diff --git a/vertexai-google-demo/src/com/axonivy/connector/vertexai/managedBean/GeminiDataBean.java b/vertexai-google-demo/src/com/axonivy/connector/vertexai/managedBean/GeminiDataBean.java index 8f00440..974a302 100644 --- a/vertexai-google-demo/src/com/axonivy/connector/vertexai/managedBean/GeminiDataBean.java +++ b/vertexai-google-demo/src/com/axonivy/connector/vertexai/managedBean/GeminiDataBean.java @@ -13,7 +13,7 @@ import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.primefaces.PrimeFaces; +import org.primefaces.PF; import com.axonivy.connector.vertexai.entities.*; import com.axonivy.connector.vertexai.enums.Model; @@ -42,14 +42,14 @@ public void init() { geminiDataRequestService.cleanData(); } - public void onSendRequest() throws Exception { + public void onSendRequest() { try { conversations = geminiDataRequestService.sendRequestToGemini(inputtedMessage, model); addCodesToPreTagIfPresent(conversations); inputtedMessage = StringUtils.EMPTY; } catch (Exception e) { errorMessage = e.getMessage(); - PrimeFaces.current().executeScript(OPEN_ERROR_DIALOG_SCRIPT); + PF.current().executeScript(OPEN_ERROR_DIALOG_SCRIPT); } } diff --git a/vertexai-google-demo/src_hd/com/axonivy/connector/vertexai/chatWithAi/chatWithAi.xhtml b/vertexai-google-demo/src_hd/com/axonivy/connector/vertexai/chatWithAi/chatWithAi.xhtml index d37c4d5..81ea0da 100644 --- a/vertexai-google-demo/src_hd/com/axonivy/connector/vertexai/chatWithAi/chatWithAi.xhtml +++ b/vertexai-google-demo/src_hd/com/axonivy/connector/vertexai/chatWithAi/chatWithAi.xhtml @@ -17,9 +17,9 @@ showEffect="fade" hideEffect="fade" closable="true" responsive="true">
- - + +

@@ -82,32 +82,28 @@
- diff --git a/vertexai-google-demo/webContent/layouts/styles/chatwithai.css b/vertexai-google-demo/webContent/layouts/styles/chatwithai.css index 86ee067..3f55c77 100644 --- a/vertexai-google-demo/webContent/layouts/styles/chatwithai.css +++ b/vertexai-google-demo/webContent/layouts/styles/chatwithai.css @@ -70,4 +70,9 @@ .error-message { font-size: 14px; +} + +i { + font-size: 24px !important; + color: orange; } \ No newline at end of file diff --git a/vertexai-google-test/src_test/com/axonivy/connector/vertexai/test/utils/GeminiDataRequestServiceUtilTest.java b/vertexai-google-test/src_test/com/axonivy/connector/vertexai/test/utils/GeminiDataRequestServiceUtilTest.java index 5530dd1..6a06bff 100644 --- a/vertexai-google-test/src_test/com/axonivy/connector/vertexai/test/utils/GeminiDataRequestServiceUtilTest.java +++ b/vertexai-google-test/src_test/com/axonivy/connector/vertexai/test/utils/GeminiDataRequestServiceUtilTest.java @@ -1,10 +1,20 @@ package com.axonivy.connector.vertexai.test.utils; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + import com.axonivy.connector.vertexai.entities.Content; import com.axonivy.connector.vertexai.utils.GeminiDataRequestServiceUtils; import com.google.gson.Gson; @@ -15,8 +25,12 @@ public class GeminiDataRequestServiceUtilTest { public static final String IMG_TAG_PATTERN = "]*>"; public static final String IMG_SRC_ATTR_PATTERN = "data:image\\/[^;]+;base64,([^\"]+)"; + private GeminiDataRequestServiceUtils geminiDataRequestServiceUtils = new GeminiDataRequestServiceUtils(); + + @TempDir + Path tempDir; @BeforeEach void beforeEach(AppFixture fixture) { @@ -83,5 +97,35 @@ public void formatRequest_test() { assertThat(result).usingRecursiveComparison().ignoringFields("id") .isEqualTo(new Gson().fromJson(expectedResult, Content.class)); } + + @Test + void testGetInputStream_BlankKeyFilePath() { + IOException exception = assertThrows(IOException.class, () -> { + GeminiDataRequestServiceUtils.getInputStream(""); + }); + assertEquals("Vertex AI credential file path is missing. Please provide it and try again!", exception.getMessage()); + } + + @Test + void testGetInputStream_FileNotFound() { + String invalidFilePath = tempDir.resolve("nonexistent-file.txt").toString(); + + IOException exception = assertThrows(IOException.class, () -> { + GeminiDataRequestServiceUtils.getInputStream(invalidFilePath); + }); + assertEquals("Could not find VertexAi credential file by path " + invalidFilePath, exception.getMessage()); + } + + @Test + void testGetInputStream_ValidKeyFilePath() throws IOException { + // Create a temporary file + Path tempFile = tempDir.resolve("valid-file.txt"); + File file = tempFile.toFile(); + assertTrue(file.createNewFile()); + + try (InputStream inputStream = GeminiDataRequestServiceUtils.getInputStream(tempFile.toString())) { + assertNotNull(inputStream); + } + } }