Skip to content

Commit

Permalink
fix: roundabout description (#1183)
Browse files Browse the repository at this point in the history
* test: update roundabout test questionnaire

* fix: roundabout description

* chore: version 3.31.5
  • Loading branch information
nsenave committed Dec 26, 2024
1 parent 3a1707c commit 9d6029c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ java {

allprojects {
group = "fr.insee.eno"
version = "3.31.4-SNAPSHOT"
version = "3.31.5"
}

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

private static final String DDI_INSTANCE_LABEL_TYPE = "loop.instanceLabel";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -194,6 +199,15 @@ private Roundabout createRoundabout(RoundaboutSequence roundaboutSequence, Loop
return lunaticRoundabout;
}

private static void mapRoundaboutDescription(RoundaboutSequence roundaboutSequence, Roundabout lunaticRoundabout) {
Optional<String> 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.
Expand Down Expand Up @@ -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<String> getRoundaboutDescription(RoundaboutSequence roundaboutSequence) {
List<Instruction> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
33 changes: 32 additions & 1 deletion eno-core/src/test/resources/integration/ddi/ddi-roundabout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"><!--Eno version : 2.9.10. Generation date : 24/06/2024 - 13:32:16-->
isMaintainable="true"><!--Eno version : 2.12.1. Generation date : 26/12/2024 - 12:24:17-->
<r:Agency>fr.insee</r:Agency>
<r:ID>INSEE-lxsxhihx</r:ID>
<r:Version>1</r:Version>
Expand Down Expand Up @@ -72,6 +72,31 @@
</d:ConditionalText>
</d:InstructionText>
</d:Instruction>
<d:Instruction>
<r:Agency>fr.insee</r:Agency>
<r:ID>m55ba6zt</r:ID>
<r:Version>1</r:Version>
<d:InstructionName>
<r:String xml:lang="fr-FR">help</r:String>
</d:InstructionName>
<d:InstructionName>
<r:String xml:lang="fr-FR">SelfAdministeredQuestionnaire.WebBased</r:String>
</d:InstructionName>
<d:InstructionName>
<r:String xml:lang="fr-FR">SelfAdministeredQuestionnaire.Paper</r:String>
</d:InstructionName>
<d:InstructionName>
<r:String xml:lang="fr-FR">Interview.Telephone.CATI</r:String>
</d:InstructionName>
<d:InstructionName>
<r:String xml:lang="fr-FR">Interview.FaceToFace.CAPIorCAMI</r:String>
</d:InstructionName>
<d:InstructionText>
<d:LiteralText>
<d:Text xml:lang="fr-FR">"Roundabout declaration"</d:Text>
</d:LiteralText>
</d:InstructionText>
</d:Instruction>
</d:InterviewerInstructionScheme>
<d:ControlConstructScheme>
<r:Agency>fr.insee</r:Agency>
Expand Down Expand Up @@ -201,6 +226,12 @@
<r:Version>1</r:Version>
<r:TypeOfObject>Instruction</r:TypeOfObject>
</d:InterviewerInstructionReference>
<d:InterviewerInstructionReference>
<r:Agency>fr.insee</r:Agency>
<r:ID>m55ba6zt</r:ID>
<r:Version>1</r:Version>
<r:TypeOfObject>Instruction</r:TypeOfObject>
</d:InterviewerInstructionReference>
<d:TypeOfSequence controlledVocabularyID="INSEE-TOS-CL-1">roundabout</d:TypeOfSequence>
<d:ControlConstructReference>
<r:Agency>fr.insee</r:Agency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$"
Expand Down

0 comments on commit 9d6029c

Please sign in to comment.