Skip to content

Commit

Permalink
feat: identification section (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave authored Nov 14, 2023
1 parent 072c258 commit 51dfc14
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

allprojects {
group = 'fr.insee.eno'
version = '3.11.11-SNAPSHOT'
version = '3.12.0-SNAPSHOT'
sourceCompatibility = '17'
}

Expand Down
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);
}

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

}

0 comments on commit 51dfc14

Please sign in to comment.