Skip to content

Refactor ProfileService: Replace String Literals with Constants #9

@shekhar316

Description

@shekhar316

The ProfileService class currently uses hardcoded string literals throughout the code. To improve code maintainability, readability, and consistency with other modules (like BulkSchedulerService), we should extract these string literals into constants in the OptimizerConstants class.

Current State

The ProfileService.java file contains multiple hardcoded string literals such as:

- Error messages: "No metadata profiles found!", "No metric profiles found!", "No layers found!"
- Log messages: "Fetching metadata profiles from Kruize", "Fetching metric profiles from Kruize", "Fetching layers from Kruize"
- Success messages: "Installed: ", "Already installed: ", "Failed to install "
- Other strings: "Failed to read response body", "Successfully installed profile: "

Examples of String Literals to Convert
Lines 60, 73, 105, 119, 149, 161:

LOG.info("Fetching metadata profiles from Kruize");
if (responseBody != null && responseBody.contains("No metadata profiles found!")) {
    LOG.info("No metadata profiles found in Kruize, returning empty list");
}

What Needs to Be Done

  • Identify all string literals in ProfileService.java that should be constants
  • Add new constants to OptimizerConstants.java in the appropriate inner class (likely MessageConstants)
  • Replace all string literals in ProfileService.java with the newly created constants
  • Follow the existing pattern used in BulkSchedulerService.java as a reference
  • Reference Implementation: See how BulkSchedulerService uses constants from OptimizerConstants:
// Instead of hardcoded strings:
LOG.info(MessageConstants.INFO_INITIALIZING_BULK_SCHEDULER);
LOG.error(MessageConstants.ERROR_NO_DATASOURCE_AVAILABLE);

Definition of Done

  • All string literals in ProfileService are identified and documented
  • New constants are added to OptimizerConstants.MessageConstants class
  • All string literals in ProfileService are replaced with constants
  • Code compiles successfully without errors
  • Existing functionality remains unchanged (no behavioral changes)

Benefits

  • Improved code maintainability
  • Easier to update messages in the future
  • Consistency across the codebase

Metadata

Metadata

Labels

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions