From adeeb6cedb9d3a99df02b99737fcdce882c971cd Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Thu, 29 Jun 2023 11:14:14 +0530 Subject: [PATCH 1/6] Cache cassandra result in conversation history --- pom.xml | 2 +- .../cache/service/RedisCacheService.java | 122 ++++++++++++++---- 2 files changed, 99 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 57f2dd1..52613a7 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.uci utils - 2.2.5 + 2.2.5-SNAPSHOT diff --git a/src/main/java/com/uci/utils/cache/service/RedisCacheService.java b/src/main/java/com/uci/utils/cache/service/RedisCacheService.java index 2eb67ad..9804553 100644 --- a/src/main/java/com/uci/utils/cache/service/RedisCacheService.java +++ b/src/main/java/com/uci/utils/cache/service/RedisCacheService.java @@ -25,58 +25,64 @@ @Setter @Slf4j public class RedisCacheService { - private RedisTemplate redisTemplate; + private RedisTemplate redisTemplate; public Integer redisKeyTimeout; /** * Get is redis cache enabled or disabled + * * @return */ private Boolean enabledRedis() { - if(System.getenv("REDIS_ENABLED") != null && System.getenv("REDIS_ENABLED").equalsIgnoreCase("false")) { + if (System.getenv("REDIS_ENABLED") != null && System.getenv("REDIS_ENABLED").equalsIgnoreCase("false")) { return false; } return true; } - - /** + + /** * Get XMessageDao Object from cache by key + * * @param key * @return */ public Object getMinioCDNCache(String key) { return getCache(redisKeyWithPrefix(RedisCachePrefix.MinioCDN.name(), key)); } - + /** * Set XMessageDao Object in cache by key + * * @param key * @param value */ public void setMinioCDNCache(String key, Object value) { setCache(redisKeyWithPrefix(RedisCachePrefix.MinioCDN.name(), key), value); } - + /** * Get Fusion Auth User ID Object from cache by key + * * @param key * @return */ public Object getFAUserIDForAppCache(String key) { return getCache(redisKeyWithPrefix(RedisCachePrefix.FAUserID.name(), key)); } - + /** * Set Fusion Auth User ID Object in cache by key + * * @param key * @param value */ public void setFAUserIDForAppCache(String key, Object value) { setCache(redisKeyWithPrefix(RedisCachePrefix.FAUserID.name(), key), value); } - + /** * Delete Fusion Auth User ID Object in cache by key + * * @param key */ public void deleteFAUserIDForAppCache(String key) { @@ -85,50 +91,56 @@ public void deleteFAUserIDForAppCache(String key) { /** * Get Language Object from cache by name + * * @param name * @return */ public Object getLanguageCache(String name) { return getCache(redisKeyWithPrefix(RedisCachePrefix.Language.name(), name)); } - + /** * Set Language Object in cache by name + * * @param name * @param value */ public void setLanguageCache(String name, Object value) { setCache(redisKeyWithPrefix(RedisCachePrefix.Language.name(), name), value); } - + /** * Delete Language Object in cache by name + * * @param name */ public void deleteLanguageCache(String name) { deleteCache(redisKeyWithPrefix(RedisCachePrefix.Language.name(), name)); } - + /** * Get XMessageDao Object from cache by key + * * @param key * @return */ public Object getXMessageDaoCache(String key) { return getCache(redisKeyWithPrefix(RedisCachePrefix.XMessageDao.name(), key)); } - + /** * Set XMessageDao Object in cache by key + * * @param key * @param value */ public void setXMessageDaoCache(String key, Object value) { setCache(redisKeyWithPrefix(RedisCachePrefix.XMessageDao.name(), key), value); } - + /** * Delete XMessageDao Object in cache by key + * * @param key */ public void deleteXMessageDaoCache(String key) { @@ -137,15 +149,16 @@ public void deleteXMessageDaoCache(String key) { /** * Get all cache keys by prefix + * * @param prefix * @return */ public ArrayList getAllCacheKeys(String prefix) { - if(enabledRedis()) { + if (enabledRedis()) { ArrayList keysList = new ArrayList(); Set redisKeys = redisTemplate.keys(prefix); Iterator redisIt = redisKeys.iterator(); - while(redisIt.hasNext()) { + while (redisIt.hasNext()) { keysList.add(redisIt.next()); } return keysList; @@ -155,18 +168,19 @@ public ArrayList getAllCacheKeys(String prefix) { /** * Get all cache keys by prefix + * * @param prefix * @return */ public ArrayList> getAllCacheKeyValuesByPattern(String prefix) { - if(enabledRedis()) { + if (enabledRedis()) { ArrayList> list = new ArrayList(); String pattern = redisKeyPatternWithPrefix(prefix); RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection(); Set redisKeys = redisConnection.keys(pattern.getBytes()); Iterator redisIt = redisKeys.iterator(); ValueOperations valOperations = redisTemplate.opsForValue(); - while(redisIt.hasNext()) { + while (redisIt.hasNext()) { byte[] data = redisIt.next(); String key = new String(data, 0, data.length); Object result = valOperations.get(key); @@ -179,11 +193,12 @@ public ArrayList> getAllCacheKeyValuesByPattern(String pref /** * Get cache by key + * * @param redisKey * @return */ public Object getCache(String redisKey) { - if(enabledRedis()) { + if (enabledRedis()) { ValueOperations valOperations = redisTemplate.opsForValue(); Object result = valOperations.get(redisKey); @@ -194,14 +209,15 @@ public Object getCache(String redisKey) { } catch (JsonProcessingException e) { e.printStackTrace(); } - log.info("Find redis cache by key: "+redisKey+", val: "+val); + log.info("Find redis cache by key: " + redisKey + ", val: " + val); return result; } return null; } - + /** * Set cache value by redisKey + * * @param redisKey * @param value */ @@ -220,7 +236,7 @@ public void setCache(String redisKey, Object value) { } catch (JsonProcessingException e) { e.printStackTrace(); } - log.info("Set redis cache for key: " + redisKey+", val: "+redisVal); + log.info("Set redis cache for key: " + redisKey + ", val: " + redisVal); } catch (Exception e) { /* If redis cache not able to set, delete cache */ redisTemplate.delete(redisKey); @@ -233,6 +249,7 @@ public void setCache(String redisKey, Object value) { /** * Set cache value by redisKey + * * @param redisKey */ public void deleteCache(String redisKey) { @@ -248,27 +265,30 @@ public void deleteCache(String redisKey) { } } } - + /** * Add env prefix with cache key + * * @param key * @return */ private String redisKeyWithPrefix(String prefix, String key) { - return System.getenv("ENV")+"-"+prefix+":"+key; + return System.getenv("ENV") + "-" + prefix + ":" + key; } /** * Add env prefix + * * @param prefix * @return */ private String redisKeyPatternWithPrefix(String prefix) { - return System.getenv("ENV")+"-"+prefix+":*"; + return System.getenv("ENV") + "-" + prefix + ":*"; } /** * Get Cache Expiry time in seconds + * * @return */ private Integer getExpireTimeInSeconds() { @@ -277,6 +297,7 @@ private Integer getExpireTimeInSeconds() { /** * Check isKeyExists in Cache + * * @param key * @return */ @@ -284,4 +305,57 @@ public boolean isKeyExists(String key) { RedisOperations operations = redisTemplate.opsForValue().getOperations(); return operations.hasKey(key); } + + /** + * Set Conversation History in Redis Cache + * @param redisKey + * @param value + */ + public void setConversationHistoryCache(String redisKey, Object value) { + if (enabledRedis()) { + ValueOperations valOperations = redisTemplate.opsForValue(); + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + try { + valOperations.set(redisKey, value); + /* Set Expire time for key */ + redisTemplate.expire(redisKey, getExpireTimeInSeconds(), TimeUnit.SECONDS); + + String redisVal = ""; + try { + redisVal = ow.writeValueAsString(value); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + log.info("Set Conversation-History redis cache for key: " + redisKey); + } catch (Exception e) { + /* If redis cache not able to set, delete cache */ + redisTemplate.delete(redisKey); + e.printStackTrace(); + log.info("Exception in redis setCache: " + e.getMessage()); + } + } + } + + /** + * Get Conversation History from Redis Cache + * @param redisKey + * @return + */ + public Object getConversationHistoryFromCache(String redisKey) { + if (enabledRedis()) { + ValueOperations valOperations = redisTemplate.opsForValue(); + Object result = valOperations.get(redisKey); + + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String val = ""; + try { + val = ow.writeValueAsString(result); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + log.info("Get Conversation-History cache by key: " + redisKey); + return result; + } + return null; + } } From 334ef4b619a3600f13a8a7c45012eb6613184d3c Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Thu, 13 Jul 2023 16:54:57 +0530 Subject: [PATCH 2/6] Build Version Updated to 2.2.6-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 52613a7..1c6ed01 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.uci utils - 2.2.5-SNAPSHOT + 2.2.6-SNAPSHOT From ed8faead92efb38891e620c71192505e33b29e02 Mon Sep 17 00:00:00 2001 From: SoumyoNathTripathy Date: Fri, 21 Jul 2023 01:14:36 +0530 Subject: [PATCH 3/6] graal_compatible code --- .idea/.gitignore | 8 ++++ .idea/compiler.xml | 19 ++++++++++ .idea/encodings.xml | 6 +++ .idea/jarRepositories.xml | 20 ++++++++++ .idea/misc.xml | 12 ++++++ .idea/vcs.xml | 6 +++ .mvn/wrapper/MavenWrapperDownloader.java | 10 ++--- pom.xml | 11 ++++++ .../java/com/uci/utils/bot/util/BotUtil.java | 25 ++++++------ .../java/com/uci/utils/bot/util/FileUtil.java | 38 ++++++++++++------- 10 files changed, 125 insertions(+), 30 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..52a791d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5f20501 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java index a45eb6b..add96f7 100644 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -32,14 +32,12 @@ public class MavenWrapperDownloader { * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to * use instead of the default one. */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; /** * Path where the maven-wrapper.jar will be saved to. */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; + private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; /** * Name of the property which should be used to override the default download url for the wrapper. @@ -89,7 +87,7 @@ public static void main(String args[]) { System.out.println("Done"); System.exit(0); } catch (Throwable e) { - System.out.println("- Error downloading"); + System.out.println("-Error downloading"); e.printStackTrace(); System.exit(1); } @@ -111,8 +109,8 @@ protected PasswordAuthentication getPasswordAuthentication() { rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream(destination); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); rbc.close(); + fos.close(); } } diff --git a/pom.xml b/pom.xml index 57f2dd1..c04a701 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,17 @@ io.projectreactor.kafka reactor-kafka + + org.apache.logging.log4j + log4j-slf4j-impl + 2.14.1 + + + org.slf4j + slf4j-api + + + diff --git a/src/main/java/com/uci/utils/bot/util/BotUtil.java b/src/main/java/com/uci/utils/bot/util/BotUtil.java index b02ef83..713bda2 100644 --- a/src/main/java/com/uci/utils/bot/util/BotUtil.java +++ b/src/main/java/com/uci/utils/bot/util/BotUtil.java @@ -82,13 +82,13 @@ public static String getBotValid(String status, String startDate, String endDate * @return */ public static Boolean checkBotValidFromJsonNode(JsonNode data) { - String status = data.findValue("status").asText(); - String startDate = data.findValue("startDate").asText(); - String endDate = data.findValue("endDate").asText(); + String botstatus = data.findValue("status").asText(); + String botstartDate = data.findValue("startDate").asText(); + String botendDate = data.findValue("endDate").asText(); - log.info("Bot Status: "+status+", Start Date: "+startDate+", End Date: "+endDate); + log.info("Bot Status: "+botstatus+", Start Date: "+botstartDate+", End Date: "+botendDate); - return checkBotValid(status, startDate, endDate); + return checkBotValid(botstatus, botstartDate, botendDate); } /** @@ -99,14 +99,17 @@ public static Boolean checkBotValidFromJsonNode(JsonNode data) { * @return */ public static Boolean checkBotValid(String status, String startDate, String endDate) { - if(checkBotLiveStatus(status) && checkBotStartDateValid(startDate) - && checkBotEndDateValid(endDate) - && !(startDate == null || startDate == "null" || startDate.isEmpty())) { - return true; - } - return false; + boolean isBotValid = checkBotLiveStatus(status) && + checkBotStartDateValid(startDate) && + checkBotEndDateValid(endDate) && + startDate != null && + !startDate.equals("null") && + !startDate.isEmpty(); + + return isBotValid; } + /** * Check if bot' status is live/enabled * @param status diff --git a/src/main/java/com/uci/utils/bot/util/FileUtil.java b/src/main/java/com/uci/utils/bot/util/FileUtil.java index 77c5a09..d143655 100644 --- a/src/main/java/com/uci/utils/bot/util/FileUtil.java +++ b/src/main/java/com/uci/utils/bot/util/FileUtil.java @@ -114,13 +114,15 @@ public static String getUploadedFileName(String mimeType, String name) { * @return */ public static String validateFileSizeByInputBytes(byte[] inputBytes, Double maxSizeForMedia) { - /* Discard if file size is greater than MAX_SIZE_FOR_MEDIA */ if (maxSizeForMedia != null && inputBytes.length > maxSizeForMedia) { - return "file size is greater than limit : " + inputBytes.length; + String errorMessage = "File size is greater than the limit: " + inputBytes.length; + return errorMessage; } + return ""; } + /** * Function to get Mime type of file from url * @param url @@ -199,19 +201,29 @@ public static boolean isFileTypeDocument(String mime_type) { * @param mime_type * @return */ +// public static boolean isValidFileType(String mime_type) { +// ArrayList list = getImageFileTypes(); +// list.addAll(getAudioFileTypes()); +// list.addAll(getVideoFileTypes()); +// list.addAll(getDocumentFileTypes()); +// for(int i=0; i < list.size(); i++) { +// if(list.get(i).equals(mime_type)) { +// return true; +// } +// } +// return false; +// } public static boolean isValidFileType(String mime_type) { - ArrayList list = getImageFileTypes(); - list.addAll(getAudioFileTypes()); - list.addAll(getVideoFileTypes()); - list.addAll(getDocumentFileTypes()); - for(int i=0; i < list.size(); i++) { - if(list.get(i).equals(mime_type)) { - return true; - } - } - return false; + ArrayList validFileTypes = new ArrayList<>(); + validFileTypes.addAll(getImageFileTypes()); + validFileTypes.addAll(getAudioFileTypes()); + validFileTypes.addAll(getVideoFileTypes()); + validFileTypes.addAll(getDocumentFileTypes()); + + return validFileTypes.contains(mime_type); } - + + /** * Get Image file types list * @return From 06edf2bf4ec1e22029246de07a2c3f02f37bd2a0 Mon Sep 17 00:00:00 2001 From: SoumyoNathTripathy Date: Sat, 22 Jul 2023 16:26:25 +0530 Subject: [PATCH 4/6] .idea files removed --- .idea/.gitignore | 8 -------- .idea/compiler.xml | 19 ------------------- .idea/encodings.xml | 6 ------ .idea/jarRepositories.xml | 20 -------------------- .idea/misc.xml | 12 ------------ .idea/vcs.xml | 6 ------ 6 files changed, 71 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 52a791d..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 63e9001..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 5f20501..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From a7bb78e8d8e93e6f9197e849dc657d88104822bf Mon Sep 17 00:00:00 2001 From: SoumyoNathTripathy Date: Mon, 24 Jul 2023 15:07:04 +0530 Subject: [PATCH 5/6] updated spring version --- .idea/compiler.xml | 18 ++++++++++++++++++ .idea/encodings.xml | 7 +++++++ .idea/jarRepositories.xml | 20 ++++++++++++++++++++ .idea/misc.xml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ pom.xml | 2 +- 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..c6dc836 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ea0b3a9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9fc7313..9733bdf 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.5.7 + 3.0.4 com.uci From e876515f1c09be004819c2e40998282c3385f23d Mon Sep 17 00:00:00 2001 From: SoumyoNathTripathy Date: Mon, 24 Jul 2023 15:28:13 +0530 Subject: [PATCH 6/6] updated --- .idea/compiler.xml | 1 + pom.xml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index c6dc836..52a791d 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,6 +2,7 @@ + diff --git a/pom.xml b/pom.xml index 9733bdf..afeabf1 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ utils Demo project for Spring Boot - 11 + 17 4.7.2 4.7.2 @@ -64,6 +64,8 @@ io.projectreactor.kafka reactor-kafka + + org.apache.logging.log4j log4j-slf4j-impl