-
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.
- Loading branch information
Showing
3 changed files
with
124 additions
and
2 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
66 changes: 65 additions & 1 deletion
66
.../src/main/java/fr/insee/eno/core/processing/common/steps/EnoAddIdentificationSection.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 |
---|---|---|
@@ -1,13 +1,77 @@ | ||
package fr.insee.eno.core.processing.common.steps; | ||
|
||
import fr.insee.eno.core.Constant; | ||
import fr.insee.eno.core.model.EnoQuestionnaire; | ||
import fr.insee.eno.core.model.label.DynamicLabel; | ||
import fr.insee.eno.core.model.label.Label; | ||
import fr.insee.eno.core.model.question.TextQuestion; | ||
import fr.insee.eno.core.model.sequence.Sequence; | ||
import fr.insee.eno.core.model.sequence.StructureItemReference; | ||
import fr.insee.eno.core.model.sequence.StructureItemReference.StructureItemType; | ||
import fr.insee.eno.core.model.sequence.Subsequence; | ||
import fr.insee.eno.core.model.variable.CollectedVariable; | ||
import fr.insee.eno.core.model.variable.ExternalVariable; | ||
import fr.insee.eno.core.processing.ProcessingStep; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class EnoAddIdentificationSection implements ProcessingStep<EnoQuestionnaire> { | ||
|
||
public static final String IDENTIFICATION_LABEL_VARIABLE = "LABEL_UNITE_ENQUETEE"; | ||
public static final String IDENTIFICATION_COMMENT_VARIABLE = "COMMENT_UE"; | ||
public static final String IDENTIFICATION_SEQUENCE_ID = "BEGIN-QUESTION-SEQ"; | ||
public static final String IDENTIFICATION_SEQUENCE_LABEL = "\"Identification\""; | ||
public static final String IDENTIFICATION_SUBSEQUENCE_ID = "BEGIN-QUESTION-SUBSEQ"; | ||
public static final String IDENTIFICATION_SUBSEQUENCE_LABEL = | ||
"\"Identification de votre \" || cast(LABEL_UNITE_ENQUETEE, string)"; | ||
public static final String IDENTIFICATION_QUESTION_ID = "COMMENT-UE-QUESTION"; | ||
public static final String IDENTIFICATION_QUESTION_LABEL = | ||
"\"Remarque, commentaire sur un changement concernant votre \" || cast(LABEL_UNITE_ENQUETEE, string) || \"\u00a0:\""; | ||
public static final int IDENTIFICATION_QUESTION_LENGTH = 2000; | ||
public static final boolean IDENTIFICATION_QUESTION_MANDATORY = false; | ||
|
||
@Override | ||
public void apply(EnoQuestionnaire enoQuestionnaire) { | ||
throw new UnsupportedOperationException("The addition of the 'identification' section is not supported yet."); | ||
// | ||
ExternalVariable labelVariable = new ExternalVariable(); | ||
labelVariable.setName(IDENTIFICATION_LABEL_VARIABLE); | ||
enoQuestionnaire.getVariables().add(labelVariable); | ||
// | ||
CollectedVariable commentVariable = new CollectedVariable(); | ||
commentVariable.setName(IDENTIFICATION_COMMENT_VARIABLE); | ||
commentVariable.setQuestionReference(IDENTIFICATION_QUESTION_ID); | ||
enoQuestionnaire.getVariables().add(commentVariable); | ||
// | ||
Sequence sequence = new Sequence(); | ||
sequence.setId(IDENTIFICATION_SEQUENCE_ID); | ||
sequence.setLabel(new Label()); | ||
sequence.getLabel().setValue(IDENTIFICATION_SEQUENCE_LABEL); | ||
sequence.getLabel().setType(Constant.LUNATIC_LABEL_VTL_MD); | ||
sequence.getSequenceStructure().add( | ||
StructureItemReference.builder().id(IDENTIFICATION_SUBSEQUENCE_ID).type(StructureItemType.SUBSEQUENCE).build()); | ||
enoQuestionnaire.getSequences().add(0, sequence); | ||
enoQuestionnaire.getIndex().put(IDENTIFICATION_SEQUENCE_ID, sequence); | ||
// | ||
Subsequence subsequence = new Subsequence(); | ||
subsequence.setId(IDENTIFICATION_SUBSEQUENCE_ID); | ||
subsequence.setLabel(new Label()); | ||
subsequence.getLabel().setValue(IDENTIFICATION_SUBSEQUENCE_LABEL); | ||
subsequence.getLabel().setType(Constant.LUNATIC_LABEL_VTL_MD); | ||
subsequence.getSequenceStructure().add( | ||
StructureItemReference.builder().id(IDENTIFICATION_QUESTION_ID).type(StructureItemType.QUESTION).build()); | ||
enoQuestionnaire.getSubsequences().add(0, subsequence); | ||
enoQuestionnaire.getIndex().put(IDENTIFICATION_SUBSEQUENCE_ID, subsequence); | ||
// | ||
TextQuestion question = new TextQuestion(); | ||
question.setId(IDENTIFICATION_QUESTION_ID); | ||
question.setLabel(new DynamicLabel()); | ||
question.getLabel().setValue(IDENTIFICATION_QUESTION_LABEL); | ||
question.getLabel().setType(Constant.LUNATIC_LABEL_VTL_MD); | ||
question.setLengthType(TextQuestion.qualifyLength(IDENTIFICATION_QUESTION_LENGTH)); | ||
question.setMaxLength(BigInteger.valueOf(IDENTIFICATION_QUESTION_LENGTH)); | ||
question.setMandatory(IDENTIFICATION_QUESTION_MANDATORY); | ||
enoQuestionnaire.getSingleResponseQuestions().add(0, question); | ||
enoQuestionnaire.getIndex().put(IDENTIFICATION_QUESTION_ID, question); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
.../test/java/fr/insee/eno/core/processing/common/steps/EnoAddIdentificationSectionTest.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,58 @@ | ||
package fr.insee.eno.core.processing.common.steps; | ||
|
||
import fr.insee.eno.core.DDIToEno; | ||
import fr.insee.eno.core.DDIToLunatic; | ||
import fr.insee.eno.core.exceptions.business.DDIParsingException; | ||
import fr.insee.eno.core.model.EnoQuestionnaire; | ||
import fr.insee.eno.core.model.label.DynamicLabel; | ||
import fr.insee.eno.core.model.question.TextQuestion; | ||
import fr.insee.eno.core.model.sequence.Sequence; | ||
import fr.insee.eno.core.model.sequence.StructureItemReference; | ||
import fr.insee.eno.core.parameter.EnoParameters; | ||
import fr.insee.eno.core.parameter.Format; | ||
import fr.insee.eno.core.reference.EnoIndex; | ||
import fr.insee.lunatic.model.flat.ComponentType; | ||
import fr.insee.lunatic.model.flat.ComponentTypeEnum; | ||
import fr.insee.lunatic.model.flat.Questionnaire; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class EnoAddIdentificationSectionTest { | ||
|
||
@Test | ||
void integrationTest() throws DDIParsingException { | ||
// | ||
EnoParameters enoParameters = EnoParameters.of( | ||
EnoParameters.Context.BUSINESS, EnoParameters.ModeParameter.CAWI); | ||
enoParameters.setIdentificationQuestion(true); | ||
// | ||
EnoQuestionnaire enoQuestionnaire = DDIToEno.transform( | ||
this.getClass().getClassLoader().getResourceAsStream("integration/ddi/ddi-simple.xml"), | ||
enoParameters); | ||
// | ||
Sequence identificationSequence = enoQuestionnaire.getSequences().get(0); | ||
assertEquals(EnoAddIdentificationSection.IDENTIFICATION_SEQUENCE_ID, identificationSequence.getId()); | ||
} | ||
|
||
@Test | ||
void integrationTest_lunaticOutput() throws DDIParsingException { | ||
// | ||
EnoParameters enoParameters = EnoParameters.of( | ||
EnoParameters.Context.BUSINESS, EnoParameters.ModeParameter.CAWI, Format.LUNATIC); | ||
enoParameters.setIdentificationQuestion(true); | ||
// | ||
Questionnaire lunaticQuestionnaire = DDIToLunatic.transform( | ||
this.getClass().getClassLoader().getResourceAsStream("integration/ddi/ddi-simple.xml"), | ||
enoParameters); | ||
// | ||
ComponentType identificationSequence = lunaticQuestionnaire.getComponents().get(0); | ||
assertTrue(identificationSequence instanceof fr.insee.lunatic.model.flat.Sequence); | ||
assertEquals(ComponentTypeEnum.SEQUENCE, identificationSequence.getComponentType()); | ||
assertEquals(EnoAddIdentificationSection.IDENTIFICATION_SEQUENCE_ID, identificationSequence.getId()); | ||
} | ||
|
||
} |