From 6962581104bef5a498a8f9c5d825af3bb4d94778 Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Tue, 1 Aug 2023 15:16:36 +0530 Subject: [PATCH 1/7] Api for invalidate cache on transaction layer on bot update - ticket #202 --- .../controller/CaffeineCacheController.java | 112 +++++++++++------- 1 file changed, 68 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java b/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java index 3b2d720..9e2d031 100644 --- a/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java +++ b/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java @@ -1,14 +1,16 @@ package com.uci.utils.cache.controller; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.CacheManager; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -23,48 +25,70 @@ @Slf4j @RequestMapping(value = "/cache/caffeine") public class CaffeineCacheController { - @Autowired - private Cache cache; - - /** - * call this to invalidate all cache instances - */ - @GetMapping(path = "/all", produces = { "application/json", "text/json" }) - public ResponseEntity getAll() { - ObjectMapper mapper = new ObjectMapper(); + @Autowired + private Cache cache; + @Value("${spring.caffeine.authorization.key}") + private String authorizationKey; + + /** + * call this to invalidate all cache instances + */ + @GetMapping(path = "/all", produces = {"application/json", "text/json"}) + public ResponseEntity getAll() { + ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode; - try { - jsonNode = mapper.readTree("{\"id\":\"api.content.cache\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"responseCode\":\"OK\",\"result\":{}}"); - JsonNode resultNode = mapper.createObjectNode(); - cache.asMap().keySet().forEach(key -> { - String cacheName = key.toString(); - ((ObjectNode) resultNode).put(cacheName, cache.getIfPresent(cacheName).toString()); - }); - ((ObjectNode) jsonNode).put("result", resultNode); - return ResponseEntity.ok(jsonNode); - } catch (JsonMappingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JsonProcessingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + try { + jsonNode = mapper.readTree("{\"id\":\"api.content.cache\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"responseCode\":\"OK\",\"result\":{}}"); + JsonNode resultNode = mapper.createObjectNode(); + cache.asMap().keySet().forEach(key -> { + String cacheName = key.toString(); + ((ObjectNode) resultNode).put(cacheName, cache.getIfPresent(cacheName).toString()); + }); + ((ObjectNode) jsonNode).put("result", resultNode); + return ResponseEntity.ok(jsonNode); + } catch (JsonMappingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JsonProcessingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return ResponseEntity.ok(null); - } + } - /** - * call this to invalidate all cache instances - */ - @DeleteMapping(path = "/removeAll") - public void removeAll() { - cache.asMap().keySet().forEach(key -> { - removeCache(key.toString()); - }); - } + /** + * call this to invalidate all cache instances + */ + @DeleteMapping(path = "/removeAll") + public ResponseEntity removeAll(@RequestHeader(name = "Authorization") String authorizationHeader) { + try { + if (authorizationKey.equals(authorizationHeader)) { + cache.asMap().keySet().forEach(key -> { + removeCache(key.toString()); + }); + log.info("All cache removed success"); + Map map = new HashMap<>(); + map.put("message", "Cache removed success"); + map.put("status", "success"); + return new ResponseEntity<>(map, HttpStatus.OK); + } else { + Map map = new HashMap<>(); + map.put("message", "Unauthorized. Invalid secure key."); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.UNAUTHORIZED); + } + } catch (Exception ex) { + log.error("CaffeineCacheController:removeAll: Error while removing cache : " + ex.getMessage()); + Map map = new HashMap<>(); + map.put("message", ex.getMessage()); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.INTERNAL_SERVER_ERROR); + } + } - private void removeCache(final String cacheName) { - if (cache.getIfPresent(cacheName) != null) { - cache.invalidate(cacheName); - } - } + private void removeCache(final String cacheName) { + if (cache.getIfPresent(cacheName) != null) { + cache.invalidate(cacheName); + } + } } From d289afadcdaa7973a8f32edb578b8d9493fc765e Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Tue, 1 Aug 2023 15:42:49 +0530 Subject: [PATCH 2/7] Hot fix --- .../controller/CaffeineCacheController.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java b/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java index 9e2d031..829778f 100644 --- a/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java +++ b/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java @@ -27,33 +27,39 @@ public class CaffeineCacheController { @Autowired private Cache cache; - @Value("${spring.caffeine.authorization.key}") + @Value("${spring.caffeine.authorization.key:#{''}}") private String authorizationKey; /** * call this to invalidate all cache instances */ @GetMapping(path = "/all", produces = {"application/json", "text/json"}) - public ResponseEntity getAll() { + public ResponseEntity getAll(@RequestHeader(name = "Authorization") String authorizationHeader) { ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode; try { - jsonNode = mapper.readTree("{\"id\":\"api.content.cache\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"responseCode\":\"OK\",\"result\":{}}"); - JsonNode resultNode = mapper.createObjectNode(); - cache.asMap().keySet().forEach(key -> { - String cacheName = key.toString(); - ((ObjectNode) resultNode).put(cacheName, cache.getIfPresent(cacheName).toString()); - }); - ((ObjectNode) jsonNode).put("result", resultNode); - return ResponseEntity.ok(jsonNode); - } catch (JsonMappingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JsonProcessingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (authorizationKey.equals(authorizationHeader)) { + jsonNode = mapper.readTree("{\"id\":\"api.content.cache\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"responseCode\":\"OK\",\"result\":{}}"); + JsonNode resultNode = mapper.createObjectNode(); + cache.asMap().keySet().forEach(key -> { + String cacheName = key.toString(); + ((ObjectNode) resultNode).put(cacheName, cache.getIfPresent(cacheName).toString()); + }); + ((ObjectNode) jsonNode).put("result", resultNode); + return ResponseEntity.ok(resultNode); + } else { + Map map = new HashMap<>(); + map.put("message", "Unauthorized. Invalid secure key."); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.UNAUTHORIZED); + } + } catch (Exception ex) { + log.error("CaffeineCacheController:getAll: Error while getting cache : " + ex.getMessage()); + Map map = new HashMap<>(); + map.put("message", ex.getMessage()); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.INTERNAL_SERVER_ERROR); } - return ResponseEntity.ok(null); } /** From 3e5843c4edc83fa2a432492918f70b50b2190230 Mon Sep 17 00:00:00 2001 From: Pankaj Jangid <103931276+pankajjangid05@users.noreply.github.com> Date: Wed, 2 Aug 2023 14:20:52 +0530 Subject: [PATCH 3/7] Api for invalidate cache on transaction layer on bot update (#60) * Api for invalidate cache on transaction layer on bot update - ticket #202 * Hot fix --- .../controller/CaffeineCacheController.java | 120 +++++++++++------- 1 file changed, 75 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java b/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java index 3b2d720..829778f 100644 --- a/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java +++ b/src/main/java/com/uci/utils/cache/controller/CaffeineCacheController.java @@ -1,14 +1,16 @@ package com.uci.utils.cache.controller; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.CacheManager; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -23,48 +25,76 @@ @Slf4j @RequestMapping(value = "/cache/caffeine") public class CaffeineCacheController { - @Autowired - private Cache cache; - - /** - * call this to invalidate all cache instances - */ - @GetMapping(path = "/all", produces = { "application/json", "text/json" }) - public ResponseEntity getAll() { - ObjectMapper mapper = new ObjectMapper(); + @Autowired + private Cache cache; + @Value("${spring.caffeine.authorization.key:#{''}}") + private String authorizationKey; + + /** + * call this to invalidate all cache instances + */ + @GetMapping(path = "/all", produces = {"application/json", "text/json"}) + public ResponseEntity getAll(@RequestHeader(name = "Authorization") String authorizationHeader) { + ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode; - try { - jsonNode = mapper.readTree("{\"id\":\"api.content.cache\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"responseCode\":\"OK\",\"result\":{}}"); - JsonNode resultNode = mapper.createObjectNode(); - cache.asMap().keySet().forEach(key -> { - String cacheName = key.toString(); - ((ObjectNode) resultNode).put(cacheName, cache.getIfPresent(cacheName).toString()); - }); - ((ObjectNode) jsonNode).put("result", resultNode); - return ResponseEntity.ok(jsonNode); - } catch (JsonMappingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JsonProcessingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ResponseEntity.ok(null); - } + try { + if (authorizationKey.equals(authorizationHeader)) { + jsonNode = mapper.readTree("{\"id\":\"api.content.cache\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"responseCode\":\"OK\",\"result\":{}}"); + JsonNode resultNode = mapper.createObjectNode(); + cache.asMap().keySet().forEach(key -> { + String cacheName = key.toString(); + ((ObjectNode) resultNode).put(cacheName, cache.getIfPresent(cacheName).toString()); + }); + ((ObjectNode) jsonNode).put("result", resultNode); + return ResponseEntity.ok(resultNode); + } else { + Map map = new HashMap<>(); + map.put("message", "Unauthorized. Invalid secure key."); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.UNAUTHORIZED); + } + } catch (Exception ex) { + log.error("CaffeineCacheController:getAll: Error while getting cache : " + ex.getMessage()); + Map map = new HashMap<>(); + map.put("message", ex.getMessage()); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.INTERNAL_SERVER_ERROR); + } + } - /** - * call this to invalidate all cache instances - */ - @DeleteMapping(path = "/removeAll") - public void removeAll() { - cache.asMap().keySet().forEach(key -> { - removeCache(key.toString()); - }); - } + /** + * call this to invalidate all cache instances + */ + @DeleteMapping(path = "/removeAll") + public ResponseEntity removeAll(@RequestHeader(name = "Authorization") String authorizationHeader) { + try { + if (authorizationKey.equals(authorizationHeader)) { + cache.asMap().keySet().forEach(key -> { + removeCache(key.toString()); + }); + log.info("All cache removed success"); + Map map = new HashMap<>(); + map.put("message", "Cache removed success"); + map.put("status", "success"); + return new ResponseEntity<>(map, HttpStatus.OK); + } else { + Map map = new HashMap<>(); + map.put("message", "Unauthorized. Invalid secure key."); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.UNAUTHORIZED); + } + } catch (Exception ex) { + log.error("CaffeineCacheController:removeAll: Error while removing cache : " + ex.getMessage()); + Map map = new HashMap<>(); + map.put("message", ex.getMessage()); + map.put("status", "failed"); + return new ResponseEntity<>(map, HttpStatus.INTERNAL_SERVER_ERROR); + } + } - private void removeCache(final String cacheName) { - if (cache.getIfPresent(cacheName) != null) { - cache.invalidate(cacheName); - } - } + private void removeCache(final String cacheName) { + if (cache.getIfPresent(cacheName) != null) { + cache.invalidate(cacheName); + } + } } From 65869ccff1ab42252af31474d36492705748c16b Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Wed, 2 Aug 2023 17:15:19 +0530 Subject: [PATCH 4/7] Update transaction layer search by name handling --- src/main/java/com/uci/utils/BotService.java | 183 +++++++++++--------- 1 file changed, 98 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/uci/utils/BotService.java b/src/main/java/com/uci/utils/BotService.java index a7cbcc8..950b138 100644 --- a/src/main/java/com/uci/utils/BotService.java +++ b/src/main/java/com/uci/utils/BotService.java @@ -66,33 +66,38 @@ public Mono getBotNodeFromStartingMessage(String startingMessage) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get() - .uri(builder -> builder.path("admin/bot/search/internal") - .queryParam("perPage", 5) - .queryParam("page", 1) - .queryParam("match", true) - .queryParam("startingMessage", startingMessage) - .build()) - .retrieve().bodyToMono(String.class).map(response -> { - if (response != null) { - log.info("Call getBotNodeFromStartingMessage : " + response + " cache : " + cache.getIfPresent(cacheKey)); - try { - ObjectMapper mapper = new ObjectMapper(); - JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { - return root.path("result").get(0); - } - return new ObjectMapper().createObjectNode(); - } catch (JsonProcessingException jsonMappingException) { - return new ObjectMapper().createObjectNode(); - } + .uri(builder -> builder.path("admin/bot/search") + .queryParam("perPage", 5) + .queryParam("page", 1) + .queryParam("match", true) + .queryParam("startingMessage", startingMessage) + .build()) + .retrieve().bodyToMono(String.class).map(response -> { + if (response != null) { + log.info("Call getBotNodeFromStartingMessage : " + response + " cache : " + cache.getIfPresent(cacheKey)); + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode root = mapper.readTree(response); +// if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { +// return root.path("result").get(0); +// } + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty()) { + return root.path("result").get("data").get(0); + } + return new ObjectMapper().createObjectNode(); + } catch (JsonProcessingException jsonMappingException) { + return new ObjectMapper().createObjectNode(); + } - } else { - return new ObjectMapper().createObjectNode(); - } - }) - .doOnError(throwable -> log.info("Error in getting campaign: " + throwable.getMessage())) - .onErrorReturn(new ObjectMapper().createObjectNode()) - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + } else { + return new ObjectMapper().createObjectNode(); + } + }) + .doOnError(throwable -> log.info("Error in getting campaign: " + throwable.getMessage())) + .onErrorReturn(new ObjectMapper().createObjectNode()) + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) @@ -122,7 +127,7 @@ public Mono getBotNodeFromName(String botName) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get() - .uri(builder -> builder.path("admin/bot/search/internal") + .uri(builder -> builder.path("admin/bot/search") .queryParam("perPage", 5) .queryParam("page", 1) .queryParam("match", true) @@ -134,8 +139,10 @@ public Mono getBotNodeFromName(String botName) { try { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { - return root.path("result").get(0); + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty()) { + return root.path("result").get("data").get(0); } return new ObjectMapper().createObjectNode(); } catch (JsonProcessingException jsonMappingException) { @@ -216,7 +223,7 @@ public Mono getBotNodeFromId(String botId) { // return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? cache.getIfPresent(key).toString() : null) // .map(Signal::next), cacheKey) // .onCacheMissResume(() -> webClient.get() -// .uri(builder -> builder.path("admin/bot/search/internal") +// .uri(builder -> builder.path("admin/bot/search") // .queryParam("perPage", 5) // .queryParam("page", 1) // .queryParam("match", true) @@ -270,39 +277,45 @@ public Mono getBotIdFromBotName(String botName) { } return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? cache.getIfPresent(key).toString() : null) .map(Signal::next), cacheKey) - .onCacheMissResume(() -> webClient.get().uri(builder -> builder.path("admin/bot/search/internal") - .queryParam("perPage", 5) - .queryParam("page", 1) - .queryParam("match", true) - .queryParam("name", botName) - .build()) - .retrieve().bodyToMono(String.class).map(new Function() { - @Override - public String apply(String response) { - if (response != null) { - log.info("BotService:getBotIdFromBotName::Got Data From UCI Api : " + response + " cache : " + cache.getIfPresent(cacheKey)); - ObjectMapper mapper = new ObjectMapper(); - try { - JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null - && !root.path("result").get(0).isEmpty() - && BotUtil.checkBotValidFromJsonNode(root.path("result").get(0))) { - return BotUtil.getBotNodeData(root.path("result").get(0), "id"); + .onCacheMissResume(() -> webClient.get().uri(builder -> builder.path("admin/bot/search") + .queryParam("perPage", 5) + .queryParam("page", 1) + .queryParam("match", true) + .queryParam("name", botName) + .build()) + .retrieve().bodyToMono(String.class).map(new Function() { + @Override + public String apply(String response) { + if (response != null) { + log.info("BotService:getBotIdFromBotName::Got Data From UCI Api : " + response + " cache : " + cache.getIfPresent(cacheKey)); + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode root = mapper.readTree(response); +// if (root.path("result") != null && root.path("result").get(0) != null +// && !root.path("result").get(0).isEmpty() +// && BotUtil.checkBotValidFromJsonNode(root.path("result").get(0))) { +// return BotUtil.getBotNodeData(root.path("result").get(0), "id"); +// } + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty() + && BotUtil.checkBotValidFromJsonNode(root.path("result").get("data").get(0))) { + return BotUtil.getBotNodeData(root.path("result").get("data").get(0), "id"); + } + return null; + } catch (JsonProcessingException jsonMappingException) { + log.error("Error while parsing data from json : " + jsonMappingException.getMessage()); + return null; + } + + } else { } return null; - } catch (JsonProcessingException jsonMappingException) { - log.error("Error while parsing data from json : " + jsonMappingException.getMessage()); - return null; } - - } else { - } - return null; - } - }) - .doOnError(throwable -> log.info("BotService:getBotIdFromBotName::Exception: " + throwable.getMessage())) - .onErrorReturn("") - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + }) + .doOnError(throwable -> log.info("BotService:getBotIdFromBotName::Exception: " + throwable.getMessage())) + .onErrorReturn("") + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) @@ -384,34 +397,34 @@ public Mono getAdapterByID(String adapterID) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get().uri(new Function() { - @Override - public URI apply(UriBuilder builder) { - URI uri = builder.path("admin/adapter/" + adapterID).build(); - return uri; - } - }).retrieve().bodyToMono(String.class).map(new Function() { - @Override - public JsonNode apply(String response) { - log.info("BotService:getAdapterByID::Got Data From UCI Api : cache key : " + cacheKey + " cache data : " + cache.getIfPresent(cacheKey)); - if (response != null) { - ObjectMapper mapper = new ObjectMapper(); - try { - JsonNode root = mapper.readTree(response); - if (root != null && root.path("result") != null && root.path("result").path("id") != null && !root.path("result").path("id").asText().isEmpty()) { - return root.path("result"); + @Override + public URI apply(UriBuilder builder) { + URI uri = builder.path("admin/adapter/" + adapterID).build(); + return uri; + } + }).retrieve().bodyToMono(String.class).map(new Function() { + @Override + public JsonNode apply(String response) { + log.info("BotService:getAdapterByID::Got Data From UCI Api : cache key : " + cacheKey + " cache data : " + cache.getIfPresent(cacheKey)); + if (response != null) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode root = mapper.readTree(response); + if (root != null && root.path("result") != null && root.path("result").path("id") != null && !root.path("result").path("id").asText().isEmpty()) { + return root.path("result"); + } + return null; + } catch (JsonProcessingException jsonMappingException) { + return null; + } + + } else { } return null; - } catch (JsonProcessingException jsonMappingException) { - return null; } - - } else { - } - return null; - } - }) - .doOnError(throwable -> log.error("BotService:getAdapterByID::Exception: " + throwable.getMessage())) - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + }) + .doOnError(throwable -> log.error("BotService:getAdapterByID::Exception: " + throwable.getMessage())) + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) From fe43a97c48f70ad08267ec156873d4c294193748 Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Wed, 2 Aug 2023 17:15:19 +0530 Subject: [PATCH 5/7] Update transaction layer search by name handling --- src/main/java/com/uci/utils/BotService.java | 183 +++++++++++--------- 1 file changed, 98 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/uci/utils/BotService.java b/src/main/java/com/uci/utils/BotService.java index a7cbcc8..950b138 100644 --- a/src/main/java/com/uci/utils/BotService.java +++ b/src/main/java/com/uci/utils/BotService.java @@ -66,33 +66,38 @@ public Mono getBotNodeFromStartingMessage(String startingMessage) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get() - .uri(builder -> builder.path("admin/bot/search/internal") - .queryParam("perPage", 5) - .queryParam("page", 1) - .queryParam("match", true) - .queryParam("startingMessage", startingMessage) - .build()) - .retrieve().bodyToMono(String.class).map(response -> { - if (response != null) { - log.info("Call getBotNodeFromStartingMessage : " + response + " cache : " + cache.getIfPresent(cacheKey)); - try { - ObjectMapper mapper = new ObjectMapper(); - JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { - return root.path("result").get(0); - } - return new ObjectMapper().createObjectNode(); - } catch (JsonProcessingException jsonMappingException) { - return new ObjectMapper().createObjectNode(); - } + .uri(builder -> builder.path("admin/bot/search") + .queryParam("perPage", 5) + .queryParam("page", 1) + .queryParam("match", true) + .queryParam("startingMessage", startingMessage) + .build()) + .retrieve().bodyToMono(String.class).map(response -> { + if (response != null) { + log.info("Call getBotNodeFromStartingMessage : " + response + " cache : " + cache.getIfPresent(cacheKey)); + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode root = mapper.readTree(response); +// if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { +// return root.path("result").get(0); +// } + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty()) { + return root.path("result").get("data").get(0); + } + return new ObjectMapper().createObjectNode(); + } catch (JsonProcessingException jsonMappingException) { + return new ObjectMapper().createObjectNode(); + } - } else { - return new ObjectMapper().createObjectNode(); - } - }) - .doOnError(throwable -> log.info("Error in getting campaign: " + throwable.getMessage())) - .onErrorReturn(new ObjectMapper().createObjectNode()) - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + } else { + return new ObjectMapper().createObjectNode(); + } + }) + .doOnError(throwable -> log.info("Error in getting campaign: " + throwable.getMessage())) + .onErrorReturn(new ObjectMapper().createObjectNode()) + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) @@ -122,7 +127,7 @@ public Mono getBotNodeFromName(String botName) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get() - .uri(builder -> builder.path("admin/bot/search/internal") + .uri(builder -> builder.path("admin/bot/search") .queryParam("perPage", 5) .queryParam("page", 1) .queryParam("match", true) @@ -134,8 +139,10 @@ public Mono getBotNodeFromName(String botName) { try { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { - return root.path("result").get(0); + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty()) { + return root.path("result").get("data").get(0); } return new ObjectMapper().createObjectNode(); } catch (JsonProcessingException jsonMappingException) { @@ -216,7 +223,7 @@ public Mono getBotNodeFromId(String botId) { // return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? cache.getIfPresent(key).toString() : null) // .map(Signal::next), cacheKey) // .onCacheMissResume(() -> webClient.get() -// .uri(builder -> builder.path("admin/bot/search/internal") +// .uri(builder -> builder.path("admin/bot/search") // .queryParam("perPage", 5) // .queryParam("page", 1) // .queryParam("match", true) @@ -270,39 +277,45 @@ public Mono getBotIdFromBotName(String botName) { } return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? cache.getIfPresent(key).toString() : null) .map(Signal::next), cacheKey) - .onCacheMissResume(() -> webClient.get().uri(builder -> builder.path("admin/bot/search/internal") - .queryParam("perPage", 5) - .queryParam("page", 1) - .queryParam("match", true) - .queryParam("name", botName) - .build()) - .retrieve().bodyToMono(String.class).map(new Function() { - @Override - public String apply(String response) { - if (response != null) { - log.info("BotService:getBotIdFromBotName::Got Data From UCI Api : " + response + " cache : " + cache.getIfPresent(cacheKey)); - ObjectMapper mapper = new ObjectMapper(); - try { - JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null - && !root.path("result").get(0).isEmpty() - && BotUtil.checkBotValidFromJsonNode(root.path("result").get(0))) { - return BotUtil.getBotNodeData(root.path("result").get(0), "id"); + .onCacheMissResume(() -> webClient.get().uri(builder -> builder.path("admin/bot/search") + .queryParam("perPage", 5) + .queryParam("page", 1) + .queryParam("match", true) + .queryParam("name", botName) + .build()) + .retrieve().bodyToMono(String.class).map(new Function() { + @Override + public String apply(String response) { + if (response != null) { + log.info("BotService:getBotIdFromBotName::Got Data From UCI Api : " + response + " cache : " + cache.getIfPresent(cacheKey)); + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode root = mapper.readTree(response); +// if (root.path("result") != null && root.path("result").get(0) != null +// && !root.path("result").get(0).isEmpty() +// && BotUtil.checkBotValidFromJsonNode(root.path("result").get(0))) { +// return BotUtil.getBotNodeData(root.path("result").get(0), "id"); +// } + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty() + && BotUtil.checkBotValidFromJsonNode(root.path("result").get("data").get(0))) { + return BotUtil.getBotNodeData(root.path("result").get("data").get(0), "id"); + } + return null; + } catch (JsonProcessingException jsonMappingException) { + log.error("Error while parsing data from json : " + jsonMappingException.getMessage()); + return null; + } + + } else { } return null; - } catch (JsonProcessingException jsonMappingException) { - log.error("Error while parsing data from json : " + jsonMappingException.getMessage()); - return null; } - - } else { - } - return null; - } - }) - .doOnError(throwable -> log.info("BotService:getBotIdFromBotName::Exception: " + throwable.getMessage())) - .onErrorReturn("") - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + }) + .doOnError(throwable -> log.info("BotService:getBotIdFromBotName::Exception: " + throwable.getMessage())) + .onErrorReturn("") + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) @@ -384,34 +397,34 @@ public Mono getAdapterByID(String adapterID) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get().uri(new Function() { - @Override - public URI apply(UriBuilder builder) { - URI uri = builder.path("admin/adapter/" + adapterID).build(); - return uri; - } - }).retrieve().bodyToMono(String.class).map(new Function() { - @Override - public JsonNode apply(String response) { - log.info("BotService:getAdapterByID::Got Data From UCI Api : cache key : " + cacheKey + " cache data : " + cache.getIfPresent(cacheKey)); - if (response != null) { - ObjectMapper mapper = new ObjectMapper(); - try { - JsonNode root = mapper.readTree(response); - if (root != null && root.path("result") != null && root.path("result").path("id") != null && !root.path("result").path("id").asText().isEmpty()) { - return root.path("result"); + @Override + public URI apply(UriBuilder builder) { + URI uri = builder.path("admin/adapter/" + adapterID).build(); + return uri; + } + }).retrieve().bodyToMono(String.class).map(new Function() { + @Override + public JsonNode apply(String response) { + log.info("BotService:getAdapterByID::Got Data From UCI Api : cache key : " + cacheKey + " cache data : " + cache.getIfPresent(cacheKey)); + if (response != null) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode root = mapper.readTree(response); + if (root != null && root.path("result") != null && root.path("result").path("id") != null && !root.path("result").path("id").asText().isEmpty()) { + return root.path("result"); + } + return null; + } catch (JsonProcessingException jsonMappingException) { + return null; + } + + } else { } return null; - } catch (JsonProcessingException jsonMappingException) { - return null; } - - } else { - } - return null; - } - }) - .doOnError(throwable -> log.error("BotService:getAdapterByID::Exception: " + throwable.getMessage())) - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + }) + .doOnError(throwable -> log.error("BotService:getAdapterByID::Exception: " + throwable.getMessage())) + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) From 931741d331698251f212485da5357428f612d45f Mon Sep 17 00:00:00 2001 From: Pankaj Jangid <103931276+pankajjangid05@users.noreply.github.com> Date: Thu, 3 Aug 2023 11:47:56 +0530 Subject: [PATCH 6/7] Update transaction layer search by name handling (#61) * Api for invalidate cache on transaction layer on bot update - ticket #202 * Hot fix * Update transaction layer search by name handling * Update transaction layer search by name handling --- src/main/java/com/uci/utils/BotService.java | 183 +++++++++++--------- 1 file changed, 98 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/uci/utils/BotService.java b/src/main/java/com/uci/utils/BotService.java index a7cbcc8..950b138 100644 --- a/src/main/java/com/uci/utils/BotService.java +++ b/src/main/java/com/uci/utils/BotService.java @@ -66,33 +66,38 @@ public Mono getBotNodeFromStartingMessage(String startingMessage) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get() - .uri(builder -> builder.path("admin/bot/search/internal") - .queryParam("perPage", 5) - .queryParam("page", 1) - .queryParam("match", true) - .queryParam("startingMessage", startingMessage) - .build()) - .retrieve().bodyToMono(String.class).map(response -> { - if (response != null) { - log.info("Call getBotNodeFromStartingMessage : " + response + " cache : " + cache.getIfPresent(cacheKey)); - try { - ObjectMapper mapper = new ObjectMapper(); - JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { - return root.path("result").get(0); - } - return new ObjectMapper().createObjectNode(); - } catch (JsonProcessingException jsonMappingException) { - return new ObjectMapper().createObjectNode(); - } + .uri(builder -> builder.path("admin/bot/search") + .queryParam("perPage", 5) + .queryParam("page", 1) + .queryParam("match", true) + .queryParam("startingMessage", startingMessage) + .build()) + .retrieve().bodyToMono(String.class).map(response -> { + if (response != null) { + log.info("Call getBotNodeFromStartingMessage : " + response + " cache : " + cache.getIfPresent(cacheKey)); + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode root = mapper.readTree(response); +// if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { +// return root.path("result").get(0); +// } + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty()) { + return root.path("result").get("data").get(0); + } + return new ObjectMapper().createObjectNode(); + } catch (JsonProcessingException jsonMappingException) { + return new ObjectMapper().createObjectNode(); + } - } else { - return new ObjectMapper().createObjectNode(); - } - }) - .doOnError(throwable -> log.info("Error in getting campaign: " + throwable.getMessage())) - .onErrorReturn(new ObjectMapper().createObjectNode()) - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + } else { + return new ObjectMapper().createObjectNode(); + } + }) + .doOnError(throwable -> log.info("Error in getting campaign: " + throwable.getMessage())) + .onErrorReturn(new ObjectMapper().createObjectNode()) + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) @@ -122,7 +127,7 @@ public Mono getBotNodeFromName(String botName) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get() - .uri(builder -> builder.path("admin/bot/search/internal") + .uri(builder -> builder.path("admin/bot/search") .queryParam("perPage", 5) .queryParam("page", 1) .queryParam("match", true) @@ -134,8 +139,10 @@ public Mono getBotNodeFromName(String botName) { try { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null && !root.path("result").get(0).isEmpty()) { - return root.path("result").get(0); + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty()) { + return root.path("result").get("data").get(0); } return new ObjectMapper().createObjectNode(); } catch (JsonProcessingException jsonMappingException) { @@ -216,7 +223,7 @@ public Mono getBotNodeFromId(String botId) { // return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? cache.getIfPresent(key).toString() : null) // .map(Signal::next), cacheKey) // .onCacheMissResume(() -> webClient.get() -// .uri(builder -> builder.path("admin/bot/search/internal") +// .uri(builder -> builder.path("admin/bot/search") // .queryParam("perPage", 5) // .queryParam("page", 1) // .queryParam("match", true) @@ -270,39 +277,45 @@ public Mono getBotIdFromBotName(String botName) { } return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? cache.getIfPresent(key).toString() : null) .map(Signal::next), cacheKey) - .onCacheMissResume(() -> webClient.get().uri(builder -> builder.path("admin/bot/search/internal") - .queryParam("perPage", 5) - .queryParam("page", 1) - .queryParam("match", true) - .queryParam("name", botName) - .build()) - .retrieve().bodyToMono(String.class).map(new Function() { - @Override - public String apply(String response) { - if (response != null) { - log.info("BotService:getBotIdFromBotName::Got Data From UCI Api : " + response + " cache : " + cache.getIfPresent(cacheKey)); - ObjectMapper mapper = new ObjectMapper(); - try { - JsonNode root = mapper.readTree(response); - if (root.path("result") != null && root.path("result").get(0) != null - && !root.path("result").get(0).isEmpty() - && BotUtil.checkBotValidFromJsonNode(root.path("result").get(0))) { - return BotUtil.getBotNodeData(root.path("result").get(0), "id"); + .onCacheMissResume(() -> webClient.get().uri(builder -> builder.path("admin/bot/search") + .queryParam("perPage", 5) + .queryParam("page", 1) + .queryParam("match", true) + .queryParam("name", botName) + .build()) + .retrieve().bodyToMono(String.class).map(new Function() { + @Override + public String apply(String response) { + if (response != null) { + log.info("BotService:getBotIdFromBotName::Got Data From UCI Api : " + response + " cache : " + cache.getIfPresent(cacheKey)); + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode root = mapper.readTree(response); +// if (root.path("result") != null && root.path("result").get(0) != null +// && !root.path("result").get(0).isEmpty() +// && BotUtil.checkBotValidFromJsonNode(root.path("result").get(0))) { +// return BotUtil.getBotNodeData(root.path("result").get(0), "id"); +// } + if (root.path("result") != null && root.path("result").get("data") != null + && root.path("result").get("data").size() > 0 + && !root.path("result").get("data").get(0).isEmpty() + && BotUtil.checkBotValidFromJsonNode(root.path("result").get("data").get(0))) { + return BotUtil.getBotNodeData(root.path("result").get("data").get(0), "id"); + } + return null; + } catch (JsonProcessingException jsonMappingException) { + log.error("Error while parsing data from json : " + jsonMappingException.getMessage()); + return null; + } + + } else { } return null; - } catch (JsonProcessingException jsonMappingException) { - log.error("Error while parsing data from json : " + jsonMappingException.getMessage()); - return null; } - - } else { - } - return null; - } - }) - .doOnError(throwable -> log.info("BotService:getBotIdFromBotName::Exception: " + throwable.getMessage())) - .onErrorReturn("") - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + }) + .doOnError(throwable -> log.info("BotService:getBotIdFromBotName::Exception: " + throwable.getMessage())) + .onErrorReturn("") + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) @@ -384,34 +397,34 @@ public Mono getAdapterByID(String adapterID) { return CacheMono.lookup(key -> Mono.justOrEmpty(cache.getIfPresent(cacheKey) != null ? (JsonNode) cache.getIfPresent(key) : null) .map(Signal::next), cacheKey) .onCacheMissResume(() -> webClient.get().uri(new Function() { - @Override - public URI apply(UriBuilder builder) { - URI uri = builder.path("admin/adapter/" + adapterID).build(); - return uri; - } - }).retrieve().bodyToMono(String.class).map(new Function() { - @Override - public JsonNode apply(String response) { - log.info("BotService:getAdapterByID::Got Data From UCI Api : cache key : " + cacheKey + " cache data : " + cache.getIfPresent(cacheKey)); - if (response != null) { - ObjectMapper mapper = new ObjectMapper(); - try { - JsonNode root = mapper.readTree(response); - if (root != null && root.path("result") != null && root.path("result").path("id") != null && !root.path("result").path("id").asText().isEmpty()) { - return root.path("result"); + @Override + public URI apply(UriBuilder builder) { + URI uri = builder.path("admin/adapter/" + adapterID).build(); + return uri; + } + }).retrieve().bodyToMono(String.class).map(new Function() { + @Override + public JsonNode apply(String response) { + log.info("BotService:getAdapterByID::Got Data From UCI Api : cache key : " + cacheKey + " cache data : " + cache.getIfPresent(cacheKey)); + if (response != null) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode root = mapper.readTree(response); + if (root != null && root.path("result") != null && root.path("result").path("id") != null && !root.path("result").path("id").asText().isEmpty()) { + return root.path("result"); + } + return null; + } catch (JsonProcessingException jsonMappingException) { + return null; + } + + } else { } return null; - } catch (JsonProcessingException jsonMappingException) { - return null; } - - } else { - } - return null; - } - }) - .doOnError(throwable -> log.error("BotService:getAdapterByID::Exception: " + throwable.getMessage())) - .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) + }) + .doOnError(throwable -> log.error("BotService:getAdapterByID::Exception: " + throwable.getMessage())) + .retryWhen(Retry.backoff(botServiceParams.getWebclientRetryMaxAttempts(), Duration.ofSeconds(botServiceParams.getGetWebclientMinBackoff())).filter(throwable -> exceptionsToHandleList.stream().anyMatch(exception -> exception.isInstance(throwable)))) ) .andWriteWith((key, signal) -> Mono.fromRunnable( () -> Optional.ofNullable(signal.get()).ifPresent(value -> cache.put(key, value)))) From cfdcdd6ab740f494d66e8e000d6c0e8b6b2c2b5d Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Thu, 3 Aug 2023 11:51:34 +0530 Subject: [PATCH 7/7] Updated build version 2.2.6-SNAPSHOT to 2.2.7-SNAPSHOT - BotService Changes --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1c6ed01..a775750 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.uci utils - 2.2.6-SNAPSHOT + 2.2.7-SNAPSHOT