Skip to content

refactor(memory-service): externalize API paths and configuration constants

zakariae yahya a demandé de fusionner feat/memory-service-implementation vers develop

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
  • Modified File: MemoryServiceClient.java

    • Removed duplicate constant declarations
    • Updated to use MemoryServiceConstants throughout
    • Simplified URL construction using utility methods
    • Added import for MemoryServiceConstants

Key Benefits

No Duplication - API paths defined once, used everywhere
Easy Maintenance - Change path in one place, applies everywhere
Type-Safe - Prevents typos in paths and headers
Readable - Meaningful constant names make code self-documenting
Reusable - Other clients can import and use same constants

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)

Rapports de requête de fusion