From 1c680f82ab0363bfc0015c9595173b8d1f8ca828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20S=C3=A9nave?= <59770457+nsenave@users.noreply.github.com> Date: Wed, 15 May 2024 12:11:14 +0200 Subject: [PATCH] feat: move declaration to description for dsfr sequences (#1005) --- build.gradle | 2 +- .../processing/out/LunaticProcessing.java | 2 +- .../lunatic/LunaticSequenceDescription.java | 36 +++++++++++++++++++ .../LunaticSequenceDescriptionTest.java | 34 ++++++++++++++++++ .../integration/ddi/ddi-declarations.xml | 2 +- 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescription.java create mode 100644 eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescriptionTest.java diff --git a/build.gradle b/build.gradle index c89e6e69f..2ef211a71 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ tasks.withType(JavaCompile).configureEach { allprojects { group = 'fr.insee.eno' - version = '3.21.4-SNAPSHOT' + version = '3.21.5-SNAPSHOT' } subprojects { diff --git a/eno-core/src/main/java/fr/insee/eno/core/processing/out/LunaticProcessing.java b/eno-core/src/main/java/fr/insee/eno/core/processing/out/LunaticProcessing.java index a41f5ee1a..9232fca22 100644 --- a/eno-core/src/main/java/fr/insee/eno/core/processing/out/LunaticProcessing.java +++ b/eno-core/src/main/java/fr/insee/eno/core/processing/out/LunaticProcessing.java @@ -59,7 +59,7 @@ public void applyProcessing(Questionnaire lunaticQuestionnaire, EnoQuestionnaire .then(new LunaticFinalizePairwise(enoQuestionnaire)) .thenIf(lunaticParameters.isFilterResult(), new LunaticFilterResult(enoQuestionnaire, shapefromAttributeRetrieval)) - + .thenIf(lunaticParameters.isLunaticV3(), new LunaticSequenceDescription()) .thenIf(lunaticParameters.isLunaticV3(), new LunaticInputNumberDescription(enoParameters.getLanguage())) .thenIf(lunaticParameters.isLunaticV3(), new LunaticQuestionComponent()); } diff --git a/eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescription.java b/eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescription.java new file mode 100644 index 000000000..75094d63c --- /dev/null +++ b/eno-core/src/main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescription.java @@ -0,0 +1,36 @@ +package fr.insee.eno.core.processing.out.steps.lunatic; + +import fr.insee.eno.core.processing.ProcessingStep; +import fr.insee.lunatic.model.flat.*; + +import java.util.List; + +public class LunaticSequenceDescription implements ProcessingStep { + + @Override + public void apply(Questionnaire lunaticQuestionnaire) { + // + moveSequencesDescription(lunaticQuestionnaire.getComponents()); + // + lunaticQuestionnaire.getComponents().stream() + .filter(Loop.class::isInstance).map(Loop.class::cast) + .map(Loop::getComponents) + .forEach(this::moveSequencesDescription); + } + + private void moveSequencesDescription(List lunaticComponents) { + lunaticComponents.stream() + .filter(component -> ComponentTypeEnum.SEQUENCE.equals(component.getComponentType()) + || ComponentTypeEnum.SUBSEQUENCE.equals(component.getComponentType())) + .forEach(this::moveSequencesDescription); + } + + private void moveSequencesDescription(ComponentType sequenceOrSubsequence) { + if (sequenceOrSubsequence.getDeclarations().isEmpty()) + return; + sequenceOrSubsequence.setDescription( + sequenceOrSubsequence.getDeclarations().getFirst().getLabel()); + sequenceOrSubsequence.getDeclarations().clear(); + } + +} diff --git a/eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescriptionTest.java b/eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescriptionTest.java new file mode 100644 index 000000000..cb535c51f --- /dev/null +++ b/eno-core/src/test/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescriptionTest.java @@ -0,0 +1,34 @@ +package fr.insee.eno.core.processing.out.steps.lunatic; + +import fr.insee.eno.core.DDIToLunatic; +import fr.insee.eno.core.exceptions.business.DDIParsingException; +import fr.insee.eno.core.parameter.EnoParameters; +import fr.insee.eno.core.parameter.Format; +import fr.insee.lunatic.model.flat.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class LunaticSequenceDescriptionTest { + + @Test + void testFromDDI() throws DDIParsingException { + // + EnoParameters enoParameters = EnoParameters.of( + EnoParameters.Context.HOUSEHOLD, EnoParameters.ModeParameter.CAWI, Format.LUNATIC); + enoParameters.getLunaticParameters().setLunaticV3(true); + Questionnaire lunaticQuestionnaire = DDIToLunatic.transform( + this.getClass().getClassLoader().getResourceAsStream("integration/ddi/ddi-declarations.xml"), + enoParameters); + // + Sequence sequence = (Sequence) lunaticQuestionnaire.getComponents().getFirst(); + assertTrue(sequence.getDeclarations().isEmpty()); + assertEquals("\"Static label of type 'Aide' in Pogues\"", + sequence.getDescription().getValue()); + // + Question input = (Question) lunaticQuestionnaire.getComponents().get(1); + assertFalse(input.getDeclarations().isEmpty()); + assertNull(input.getDescription()); + } + +} diff --git a/eno-core/src/test/resources/integration/ddi/ddi-declarations.xml b/eno-core/src/test/resources/integration/ddi/ddi-declarations.xml index 964a9a9bf..45aa21e2f 100644 --- a/eno-core/src/test/resources/integration/ddi/ddi-declarations.xml +++ b/eno-core/src/test/resources/integration/ddi/ddi-declarations.xml @@ -51,7 +51,7 @@ - "Static label of type 'Aide' in Pogues" + "Static label of type 'Aide' in Pogues"