diff --git a/build.gradle.kts b/build.gradle.kts index ae126a54f..f65a18099 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ java { allprojects { group = "fr.insee.eno" - version = "3.31.4-SNAPSHOT" + version = "3.31.5" } subprojects { diff --git a/eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoops.java b/eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoops.java index da7f5ef86..8a02d112a 100644 --- a/eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoops.java +++ b/eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoops.java @@ -15,6 +15,7 @@ import fr.insee.lunatic.model.flat.variable.CollectedVariableValues; import fr.insee.lunatic.model.flat.variable.VariableDimension; import fr.insee.lunatic.model.flat.variable.VariableType; +import lombok.extern.slf4j.Slf4j; import java.util.List; import java.util.Optional; @@ -26,6 +27,7 @@ * This processing step replaces these loops by roundabout components, and adds the roundabout-specific information * using the Eno questionnaire. */ +@Slf4j public class LunaticRoundaboutLoops implements ProcessingStep { private static final String DDI_INSTANCE_LABEL_TYPE = "loop.instanceLabel"; @@ -161,6 +163,9 @@ private Roundabout createRoundabout(RoundaboutSequence roundaboutSequence, Loop lunaticRoundabout.setLabel(new LabelType()); lunaticRoundabout.getLabel().setValue(roundaboutSequence.getLabel().getValue()); lunaticRoundabout.getLabel().setType(LabelTypeEnum.VTL_MD); + // + mapRoundaboutDescription(roundaboutSequence, lunaticRoundabout); + // lunaticRoundabout.setProgressVariable(progressVariableName); // LunaticMapper lunaticMapper = new LunaticMapper(); @@ -194,6 +199,15 @@ private Roundabout createRoundabout(RoundaboutSequence roundaboutSequence, Loop return lunaticRoundabout; } + private static void mapRoundaboutDescription(RoundaboutSequence roundaboutSequence, Roundabout lunaticRoundabout) { + Optional descriptionValue = getRoundaboutDescription(roundaboutSequence); + if (descriptionValue.isEmpty()) + return; + lunaticRoundabout.setDescription(new LabelType()); + lunaticRoundabout.getDescription().setValue(descriptionValue.get()); + lunaticRoundabout.getDescription().setType(LabelTypeEnum.VTL_MD); + } + /** * Return the label value of the instruction that holds the label of instances of the roundabout. * @param roundaboutSequence A Eno roundabout sequence. @@ -222,6 +236,28 @@ private static String getInstanceDescription(RoundaboutSequence roundaboutSequen return labelInstruction.map(instruction -> instruction.getLabel().getValue()).orElse(null); } + /** + * Return the eventual value of the description of the roundabout. + * In the roundabout sequence object, this description is an "instruction" object. + * Note: Pogues may let the user input several of such instructions, yet Lunatic only accepts one description. + * @param roundaboutSequence A Eno roundabout sequence. + * @return String value of the description. Can be null if there is no description. + */ + private static Optional getRoundaboutDescription(RoundaboutSequence roundaboutSequence) { + List roundaboutInstructions = roundaboutSequence.getInstructions().stream() + .filter(instruction -> !DDI_INSTANCE_LABEL_TYPE.equals(instruction.getDeclarationType())) + .filter(instruction -> !DDI_INSTANCE_DESCRIPTION_TYPE.equals(instruction.getDeclarationType())) + .toList(); + if (roundaboutInstructions.isEmpty()) + return Optional.empty(); + if (roundaboutInstructions.size() > 1) + log.warn("Roundabout {} has more than 1 instructions. Only the first one will be mapped.", + roundaboutSequence.getId()); + if (!roundaboutSequence.getDeclarations().isEmpty()) // some check on passing + log.warn("Roundabout {} has declarations which is unexpected.", roundaboutSequence.getId()); + return Optional.of(roundaboutInstructions.getFirst().getLabel().getValue()); + } + /** * Return the expression of the occurrence filter of the loop. * @param enoLoop A Eno loop object. diff --git a/eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoopsTest.java b/eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoopsTest.java index 49f1f8f9e..8281d37b5 100644 --- a/eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoopsTest.java +++ b/eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticRoundaboutLoopsTest.java @@ -64,6 +64,8 @@ void roundaboutProperties() { assertEquals("4", roundabout.getPage()); assertEquals("\"Roundabout on S2\"", roundabout.getLabel().getValue()); assertEquals(LabelTypeEnum.VTL_MD, roundabout.getLabel().getType()); + assertEquals("\"Roundabout declaration\"", roundabout.getDescription().getValue()); + assertEquals(LabelTypeEnum.VTL_MD, roundabout.getDescription().getType()); assertEquals("true", roundabout.getConditionFilter().getValue()); // roundabout specific ones assertEquals("count(FIRST_NAME)", roundabout.getIterations().getValue()); diff --git a/eno-core/src/test/resources/integration/ddi/ddi-roundabout.xml b/eno-core/src/test/resources/integration/ddi/ddi-roundabout.xml index 6db6d79ce..ec6c93d0c 100644 --- a/eno-core/src/test/resources/integration/ddi/ddi-roundabout.xml +++ b/eno-core/src/test/resources/integration/ddi/ddi-roundabout.xml @@ -10,7 +10,7 @@ xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="ddi:instance:3_3 https://www.ddialliance.org/Specification/DDI-Lifecycle/3.3/XMLSchema/instance.xsd" - isMaintainable="true"> + isMaintainable="true"> fr.insee INSEE-lxsxhihx 1 @@ -72,6 +72,31 @@ + + fr.insee + m55ba6zt + 1 + + help + + + SelfAdministeredQuestionnaire.WebBased + + + SelfAdministeredQuestionnaire.Paper + + + Interview.Telephone.CATI + + + Interview.FaceToFace.CAPIorCAMI + + + + "Roundabout declaration" + + + fr.insee @@ -201,6 +226,12 @@ 1 Instruction + + fr.insee + m55ba6zt + 1 + Instruction + roundabout fr.insee diff --git a/eno-core/src/test/resources/integration/pogues/pogues-roundabout.json b/eno-core/src/test/resources/integration/pogues/pogues-roundabout.json index ec5133de6..c3e6c281a 100644 --- a/eno-core/src/test/resources/integration/pogues/pogues-roundabout.json +++ b/eno-core/src/test/resources/integration/pogues/pogues-roundabout.json @@ -133,7 +133,20 @@ "CAWI", "PAPI" ], - "Declaration": [], + "Declaration": [ + { + "id": "m55ba6zt", + "Text": "\"Roundabout declaration\"", + "position": "AFTER_QUESTION_TEXT", + "DeclarationMode": [ + "CAPI", + "CATI", + "CAWI", + "PAPI" + ], + "declarationType": "HELP" + } + ], "FlowControl": [], "OccurrenceLabel": "$FIRST_NAME$", "OccurrenceDescription": "\"Occurrence description of \" || $FIRST_NAME$"