INFRA-4022 | Dhruv | fixes flatmap ignoring empty collection

This commit is contained in:
dhruvjoshi
2024-11-28 01:37:26 +05:30
parent c8e31502b5
commit 1b57302dfd
3 changed files with 13 additions and 5 deletions

Submodule kutegen updated: 642f67474d...81f19c9947

View File

@@ -34,6 +34,9 @@ public final class FlatMapUtil {
final var root = entry.getKey();
if (entry.getValue() instanceof Map<?, ?>) {
Map<?, ?> properties = (Map<?, ?>) entry.getValue();
if (properties.isEmpty()) {
return Stream.of(new SimpleEntry<>(root, Map.of()));
}
return properties.entrySet()
.stream()
.map(e -> mapToEntry(root, e))
@@ -42,6 +45,9 @@ public final class FlatMapUtil {
if (entry.getValue() instanceof List<?>) {
List<?> list = (List<?>) entry.getValue();
if (list.isEmpty()) {
return Stream.of(new SimpleEntry<>(root, List.of()));
}
return IntStream.range(0, list.size())
.mapToObj(i -> mapToEntry(root, list.get(i), i))
.flatMap(FlatMapUtil::flatten);
@@ -54,8 +60,10 @@ public final class FlatMapUtil {
return new SimpleEntry<>(getKey(root, e), e.getValue());
}
private static SimpleEntry<String, Object> mapToEntry(final String root, final Object value,
final int i) {
private static SimpleEntry<String, Object> mapToEntry(
final String root, final Object value,
final int i
) {
return new SimpleEntry<>(getKey(root, i), value);
}
@@ -66,4 +74,4 @@ public final class FlatMapUtil {
private static String getKey(final String root, final int index) {
return root + "/" + index;
}
}
}

View File

@@ -110,7 +110,7 @@ public class MapDiffUtil {
final var result = new HashMap<String, Object>();
for (var e : map.entrySet()) {
Entry<String, Object> entry = e;
if (e.getKey().contains("environmentVariables")) {
if (e.getKey().contains("environmentVariables/")) {
entry = mapEnvVarToKey(map).apply(e);
}
result.put(entry.getKey(), entry.getValue());