Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @author Ivan Corrales Solera
* @author Daniel Frey
* @author Ian Bondoc
* @author Chen Li
*
*/
@RestController
Expand Down Expand Up @@ -291,45 +292,32 @@ private ResponseEntity<String> getSuccess(String body, MediaType mediaType) {
}

private Map<String, Object> convertToProperties(Environment profiles) {

// Map of unique keys containing full map of properties for each unique
// key
Map<String, Map<String, Object>> map = new LinkedHashMap<>();
List<PropertySource> sources = new ArrayList<>(profiles.getPropertySources());
Collections.reverse(sources);
Map<String, Object> combinedMap = new LinkedHashMap<>();
Map<String, Map<String, Object>> arrayMap = new LinkedHashMap<>();
for (PropertySource source : sources) {

@SuppressWarnings("unchecked")
Map<String, Object> value = (Map<String, Object>) source.getSource();
for (String key : value.keySet()) {

if (!key.contains("[")) {

// Not an array, add unique key to the map
combinedMap.put(key, value.get(key));
Map<String, Map<String, Object>> currentArrayMap = new LinkedHashMap<>();

for (Entry<String, Object> entry : value.entrySet()) {
if (!entry.getKey().contains("[")) {
combinedMap.put(entry.getKey(), entry.getValue());
}
else {

// An existing array might have already been added to the property map
// of an unequal size to the current array. Replace the array key in
// the current map.
key = key.substring(0, key.indexOf("["));
Map<String, Object> filtered = new LinkedHashMap<>();
for (String index : value.keySet()) {
if (index.startsWith(key + "[")) {
filtered.put(index, value.get(index));
}
}
map.put(key, filtered);
String prefixKey = entry.getKey().substring(0,
entry.getKey().indexOf("["));
currentArrayMap.computeIfAbsent(prefixKey, k -> new LinkedHashMap<>())
.put(entry.getKey(), entry.getValue());
}
}

// Override array properties by prefix key
arrayMap.putAll(currentArrayMap);
}

// Combine all unique keys for array values into the combined map
for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
for (Entry<String, Map<String, Object>> entry : arrayMap.entrySet()) {
combinedMap.putAll(entry.getValue());
}

Expand Down