fix: add hack for namespace

This commit is contained in:
MiniDigger | Martin 2023-10-29 10:42:53 +01:00
parent 00768cb1ef
commit 7b1ea6e02b
2 changed files with 30 additions and 4 deletions

View File

@ -82,10 +82,11 @@ public final class QueryMerger {
if (pkValue == null) {
System.out.println(prefix + "no primary key found: " + others);
// no more nesting
final Map<String, Object> map = new HashMap<>();
for (final String key : others.keySet()) {
result.put(key, others.get(key));
map.put(key, others.get(key));
}
result.put(commonKey, map);
} else {
System.out.println(prefix + "others: " + others);
newInputs.computeIfAbsent(pkValue, _ -> new ArrayList<>()).add(others);
@ -104,9 +105,12 @@ public final class QueryMerger {
for (final String key : result.keySet()) {
final Object entry = result.get(key);
if (entry instanceof final Map map) {
if (key.equals("pages") || key.equals("projects")) { // TODO cheat
if (key.equals("namespace")) { // TODO cheat, these should stay a map
continue;
} else if (key.equals("pages") || key.equals("projects")) { // TODO cheat, these should be a lis
result.put(key, map.values());
} else {
// these should be a single value
result.put(key, map.values().stream().findFirst().orElseThrow());
}
}

View File

@ -136,9 +136,31 @@ class QueryMergerTest {
private static void compare(Map<String, Object> expected, Map<String, Object> output) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
@Test
void mergeNoPrimaryKeyNamespace() throws JsonProcessingException {
final List<Map<String, String>> input = new ArrayList<>();
input.add(Map.of(
"projectbyslug_name", "Test",
"projectbyslug_namespace_slug", "Test",
"projectbyslug_namespace_owner", "MiniDigger"
));
final Map<String, Object> expected = Map.of(
"projectbyslug", Map.of(
"name", "Test",
"namespace", Map.of(
"owner", "MiniDigger",
"slug", "Test"
)
)
);
compare(expected, QueryMerger.merge(input));
}
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
final ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
objectWriter.writeValueAsString(expected);
assertEquals(objectWriter.writeValueAsString(expected), objectWriter.writeValueAsString(output));