Skip to content

Commit

Permalink
Code merge and Update Build Version 2.2.7 to 2.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajjangid05 committed Aug 8, 2023
2 parents 4e1f9ef + b809940 commit 6a54a0f
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 131 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<groupId>com.uci</groupId>
<artifactId>utils</artifactId>
<!--For Development we are using SNAPSHOT with version-->
<version>2.2.7</version>
<version>2.2.8</version>

<!-- On changing, Set version in build-deploy.yml to delete the previous packages if exists and deploy new package for the specified version -->

Expand Down
183 changes: 98 additions & 85 deletions src/main/java/com/uci/utils/BotService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,38 @@ public Mono<JsonNode> 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))))
Expand Down Expand Up @@ -122,7 +127,7 @@ public Mono<JsonNode> 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)
Expand All @@ -134,8 +139,10 @@ public Mono<JsonNode> 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) {
Expand Down Expand Up @@ -216,7 +223,7 @@ public Mono<JsonNode> 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)
Expand Down Expand Up @@ -270,39 +277,45 @@ public Mono<String> 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<String, String>() {
@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<String, String>() {
@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))))
Expand Down Expand Up @@ -384,34 +397,34 @@ public Mono<JsonNode> 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<UriBuilder, URI>() {
@Override
public URI apply(UriBuilder builder) {
URI uri = builder.path("admin/adapter/" + adapterID).build();
return uri;
}
}).retrieve().bodyToMono(String.class).map(new Function<String, JsonNode>() {
@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<String, JsonNode>() {
@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))))
Expand Down
Loading

0 comments on commit 6a54a0f

Please sign in to comment.