Skip to content

Unified ElasticSearch Utility Module#644

Merged
maheshkumargangula merged 5 commits intodevelopfrom
es-utils
Feb 5, 2026
Merged

Unified ElasticSearch Utility Module#644
maheshkumargangula merged 5 commits intodevelopfrom
es-utils

Conversation

@chethann007
Copy link
Contributor

Summary

Re-architected and rewrote the ElasticSearch utility layer into a single, unified core/sunbird-es-utils module. This new implementation consolidates disparate ElasticSearch handling logic from across all microservices into one central library.

Key Changes

  • New Core Module: Created core/sunbird-es-utils as the single source of truth for all ElasticSearch operations.
  • Cleanup: Removed the legacy ‎course-mw/sunbird-util/sunbird-es-utils module and refactored all dependent services (Actors, DAOs) to use the new unified implementation.

Impact

Eliminates code duplication across microservices, enforces a standardized database access pattern, and simplifies future maintenance and upgrades.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request consolidates the ElasticSearch utility layer by moving it from course-mw/sunbird-util/sunbird-es-utils to a new unified core/sunbird-es-utils module. This architectural change standardizes ElasticSearch access patterns across all microservices and eliminates code duplication.

Changes:

  • Created new core/sunbird-es-utils module with improved implementation and documentation
  • Removed legacy course-mw/sunbird-util/sunbird-es-utils module completely
  • Updated ElasticSearchService interface with reordered parameters (RequestContext moved to last position)
  • Refactored all dependent services (actors, DAOs, tests) to use new method signatures
  • Centralized dependency version management in parent POM

Reviewed changes

Copilot reviewed 78 out of 80 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
core/sunbird-es-utils/* New unified ES utils module with improved connection management, comprehensive documentation, and better error handling
core/pom.xml Added new module and centralized all dependency version properties
course-mw/sunbird-util/pom.xml Removed reference to old sunbird-es-utils module
course-mw/sunbird-util/sunbird-es-utils/* Complete removal of legacy ES utils implementation
course-mw/**/JsonKey.java Added new constants: SEARCH_FUZZY and REST
course-mw/**/Actor.java Updated all ES service method calls to new signature order
course-mw/**/Test.java Updated all mock expectations to match new method signatures
Comments suppressed due to low confidence (2)

core/sunbird-es-utils/src/main/java/org/sunbird/dto/SearchDTO.java:226


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +74 to +86
long startTime = System.currentTimeMillis();
Promise<String> promise = Futures.promise();

logger.debug(requestContext, "ElasticSearchRestHighImpl:save: method started at ==" + startTime + " for Index " + index);

if (StringUtils.isBlank(identifier) || StringUtils.isBlank(index)) {
logger.info(requestContext, "ElasticSearchRestHighImpl:save: Identifier or Index value is null or empty, identifier : "
+ identifier + ", index: " + index + ", not able to save data.");
promise.failure(ProjectUtil.createClientException(ResponseCode.invalidData));
return promise.future();
}

try {
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The save method now throws an exception for invalid input instead of returning "ERROR" as a string. This is an API behavior change that could break existing error handling code that checks for the "ERROR" string return value. The old implementation (based on the removed test) returned "ERROR" on validation failure, but the new implementation throws an exception via promise.failure().

Consider adding migration documentation or checking if all callers handle exceptions properly instead of checking for "ERROR" string.

Suggested change
long startTime = System.currentTimeMillis();
Promise<String> promise = Futures.promise();
logger.debug(requestContext, "ElasticSearchRestHighImpl:save: method started at ==" + startTime + " for Index " + index);
if (StringUtils.isBlank(identifier) || StringUtils.isBlank(index)) {
logger.info(requestContext, "ElasticSearchRestHighImpl:save: Identifier or Index value is null or empty, identifier : "
+ identifier + ", index: " + index + ", not able to save data.");
promise.failure(ProjectUtil.createClientException(ResponseCode.invalidData));
return promise.future();
}
try {
long startTime = System.currentTimeMillis();
Promise<String> promise = Futures.promise();
logger.debug(requestContext, "ElasticSearchRestHighImpl:save: method started at ==" + startTime + " for Index " + index);
if (StringUtils.isBlank(identifier) || StringUtils.isBlank(index)) {
logger.info(
requestContext,
"ElasticSearchRestHighImpl:save: Identifier or Index value is null or empty, identifier : "
+ identifier
+ ", index: "
+ index
+ ", not able to save data.");
// Maintain backward-compatible behavior: return "ERROR" instead of throwing an exception.
promise.success(ERROR);
return promise.future();
}
try {

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +77
String[] splitedHost = hostName.split(",");
for (String host : splitedHost) {
String trimmedHost = host.trim();
if (StringUtils.isNotBlank(trimmedHost)) {
hosts.add(trimmedHost);
}
}

// Parse comma-separated ports (currently stored but not used)
String[] splitedPort = port.split(",");
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent use of "splited" instead of "split" in variable names. While this is existing code being moved, consider using proper English grammar: splitedHost should be splitHost or hostArray, and splitedPort should be splitPort or portArray.

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +87
// Parse comma-separated ports (currently stored but not used)
String[] splitedPort = port.split(",");
for (String portStr : splitedPort) {
String trimmedPort = portStr.trim();
if (StringUtils.isNotBlank(trimmedPort)) {
try {
ports.add(Integer.parseInt(trimmedPort));
} catch (NumberFormatException e) {
logger.warn(null, "Invalid port number in SUNBIRD_ES_PORT: " + trimmedPort, null);
}
}
}
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ports list is populated from environment variables but never actually used. The hardcoded port 9200 is always used on line 155. Either remove the unused ports list and related parsing logic (lines 76-87), or use the parsed port values instead of hardcoding 9200. The comment on line 27 acknowledges this but it should be addressed.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +29
/** List of Elasticsearch ports (populated from env but currently unused). */
private static final List<Integer> ports = new ArrayList<>();

Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contents of this container are never accessed.

Suggested change
/** List of Elasticsearch ports (populated from env but currently unused). */
private static final List<Integer> ports = new ArrayList<>();

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 5, 2026

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 5, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
10 Security Hotspots
9.5% Coverage on New Code (required ≥ 80%)
6.6% Duplication on New Code (required ≤ 3%)
E Reliability Rating on New Code (required ≥ A)
D Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@maheshkumargangula maheshkumargangula merged commit 6bde042 into develop Feb 5, 2026
9 of 11 checks passed
@maheshkumargangula maheshkumargangula deleted the es-utils branch February 5, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants