remove logs and fix merge settings

This commit is contained in:
Anthony Stirling 2025-07-28 15:51:27 +01:00
parent 3cc6bf4c6c
commit 5e268fe77e

View File

@ -80,26 +80,20 @@ public class AdminSettingsController {
}) })
public ResponseEntity<?> getSettings( public ResponseEntity<?> getSettings(
@RequestParam(value = "includePending", defaultValue = "false") boolean includePending) { @RequestParam(value = "includePending", defaultValue = "false") boolean includePending) {
log.info("Admin requested all application settings (includePending={}, pendingChanges.size={})", includePending, pendingChanges.size()); log.debug("Admin requested all application settings (includePending={})", includePending);
// Convert ApplicationProperties to Map and mask sensitive fields // Convert ApplicationProperties to Map
Map<String, Object> maskedSettings = maskSensitiveFields( Map<String, Object> settings = objectMapper.convertValue(applicationProperties, Map.class);
objectMapper.convertValue(applicationProperties, Map.class)
);
if (!includePending) { if (includePending && !pendingChanges.isEmpty()) {
log.debug("Returning current settings only (includePending=false)"); // Merge pending changes into the settings map
return ResponseEntity.ok(maskedSettings); settings = mergePendingChanges(settings, pendingChanges);
} }
// Include pending changes in response (also mask sensitive pending changes) // Mask sensitive fields after merging
Map<String, Object> response = new HashMap<>(); Map<String, Object> maskedSettings = maskSensitiveFields(settings);
response.put("currentSettings", maskedSettings);
response.put("pendingChanges", maskSensitiveFields(new HashMap<>(pendingChanges)));
response.put("hasPendingChanges", !pendingChanges.isEmpty());
log.info("Returning settings with pending changes: hasPendingChanges={}, pendingChanges.keys={}", !pendingChanges.isEmpty(), pendingChanges.keySet()); return ResponseEntity.ok(maskedSettings);
return ResponseEntity.ok(response);
} }
@GetMapping("/delta") @GetMapping("/delta")
@ -588,4 +582,44 @@ public class AdminSettingsController {
} }
} }
/**
* Merge pending changes into the settings map using dot notation keys
*/
@SuppressWarnings("unchecked")
private Map<String, Object> mergePendingChanges(Map<String, Object> settings, Map<String, Object> pendingChanges) {
// Create a deep copy of the settings to avoid modifying the original
Map<String, Object> mergedSettings = new HashMap<>(settings);
for (Map.Entry<String, Object> pendingEntry : pendingChanges.entrySet()) {
String dotNotationKey = pendingEntry.getKey();
Object pendingValue = pendingEntry.getValue();
// Split the dot notation key into parts
String[] keyParts = dotNotationKey.split("\\.");
// Navigate to the parent object and set the value
Map<String, Object> currentMap = mergedSettings;
// Navigate through all parts except the last one
for (int i = 0; i < keyParts.length - 1; i++) {
String keyPart = keyParts[i];
// Get or create the nested map
Object nested = currentMap.get(keyPart);
if (!(nested instanceof Map)) {
// Create a new nested map if it doesn't exist or isn't a map
nested = new HashMap<String, Object>();
currentMap.put(keyPart, nested);
}
currentMap = (Map<String, Object>) nested;
}
// Set the final value
String finalKey = keyParts[keyParts.length - 1];
currentMap.put(finalKey, pendingValue);
}
return mergedSettings;
}
} }