-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move declaration to description for dsfr sequences (#1005)
- Loading branch information
Showing
5 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../main/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...t/java/fr/insee/eno/core/processing/out/steps/lunatic/LunaticSequenceDescriptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters