From b8607d85db9224c1f353cfcd3cab5501ed270c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Henninger?= Date: Mon, 15 Jul 2024 14:01:33 +0200 Subject: [PATCH] Update lunatic reader when no loop dependencies --- .../core/metadata/LunaticReader.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/kraftwerk-core/src/main/java/fr/insee/kraftwerk/core/metadata/LunaticReader.java b/kraftwerk-core/src/main/java/fr/insee/kraftwerk/core/metadata/LunaticReader.java index 142de0f2..12dc57dc 100644 --- a/kraftwerk-core/src/main/java/fr/insee/kraftwerk/core/metadata/LunaticReader.java +++ b/kraftwerk-core/src/main/java/fr/insee/kraftwerk/core/metadata/LunaticReader.java @@ -214,11 +214,22 @@ private static void processPrimaryLoop(List variables, MetadataModel met */ private static Group processDependingLoop(List variables, MetadataModel metadataModel, Group parentGroup, JsonNode component) { JsonNode loopDependencies = component.get("loopDependencies"); - StringBuilder groupNameBuilder = new StringBuilder(loopDependencies.get(0).asText()); - for (int i = 1; i < loopDependencies.size(); i++) { - groupNameBuilder.append("_").append(loopDependencies.get(i).asText()); + String groupName; + if (!loopDependencies.isEmpty()) { + StringBuilder groupNameBuilder = new StringBuilder(loopDependencies.get(0).asText()); + for (int i = 1; i < loopDependencies.size(); i++) { + groupNameBuilder.append("_").append(loopDependencies.get(i).asText()); + } + groupName = groupNameBuilder.toString(); + } else { + int i = 1; + groupName = "UNNAMED_" + i; + List groups = metadataModel.getGroupNames(); + while (groups.contains(groupName)) { + i++; + groupName = "UNNAMED_" + i; + } } - String groupName = groupNameBuilder.toString(); log.info("Creation of group :" + groupName); Group group = getNewGroup(metadataModel, groupName, parentGroup); iterateOnComponentsToFindResponses(component, variables, metadataModel, group); @@ -301,6 +312,7 @@ private static void addResponsesAndMissing(JsonNode primaryComponent, Group grou iterateOnTableBody(primaryComponent, group, variables, metadataModel, isLunaticV2); break; case null: + log.warn(String.format("%s component type not recognized", primaryComponent.get(COMPONENT_TYPE).asText())); break; } //We also had the missing variable if it exists (only one missing variable even if multiple responses)