Skip to content

Commit

Permalink
feat: move declaration to description for dsfr sequences (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed May 21, 2024
1 parent a6cfea5 commit 1c680f8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tasks.withType(JavaCompile).configureEach {

allprojects {
group = 'fr.insee.eno'
version = '3.21.4-SNAPSHOT'
version = '3.21.5-SNAPSHOT'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Questionnaire> {

@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<ComponentType> 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();
}

}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</d:InstructionName>
<d:InstructionText>
<d:LiteralText>
<d:Text xml:lang="fr-FR">"Static label of type 'Aide' in Pogues"</d:Text>
<d:Text xml:lang="fr-FR">"Static label of type 'Aide' in Pogues"</d:Text>
</d:LiteralText>
</d:InstructionText>
</d:Instruction>
Expand Down

0 comments on commit 1c680f8

Please sign in to comment.