refactor(memory-service): externalize API paths and configuration constants
Summary
Externalized all hardcoded API paths, headers, and configuration values from
MemoryServiceClient into a centralized MemoryServiceConstants class. This refactoring
improves code maintainability and follows the DRY (Don't Repeat Yourself) principle.
Changes Made
-
New File:
MemoryServiceConstants.java- Gateway API configuration (
/api/memory) - API paths (
/chat/conversations,/memory) - HTTP headers (
x-user-uuid,x-agent-id) - Timeout configurations (30 seconds)
- Utility methods for URL building
- Gateway API configuration (
-
Modified File:
MemoryServiceClient.java- Removed duplicate constant declarations
- Updated to use
MemoryServiceConstantsthroughout - Simplified URL construction using utility methods
- Added import for
MemoryServiceConstants
Key Benefits
Example
Before:
String url = baseUrl + "/api/memory" + "/chat/conversations/" + conversationId + "/memory?window_size=" + windowSize;
.header("x-user-uuid", userUuid)
After:
String url = MemoryServiceConstants.buildFullMemoryUrl(baseUrl, conversationId, windowSize);
.header(MemoryServiceConstants.HEADER_USER_UUID, userUuid)
Test Plan
- Verify MemoryServiceClient still retrieves memory correctly via gateway
- Verify health check endpoint (isHealthy()) works with new constants
- Verify all HTTP headers are set correctly
- Verify API paths are constructed correctly (no double slashes, etc.)
- Run existing unit tests to ensure no regressions
- Check that timeout values are applied correctly (30s connect, 30s read)
Files Changed
- src/main/java/com/izemx/iavia/common/agent/common/memory/constants/MemoryServiceConstants.java (new)
- src/main/java/com/izemx/iavia/common/agent/common/memory/client/MemoryServiceClient.java (modified)