Skip to content

Commit

Permalink
fix: remove prefix in questionnaire id (#890)
Browse files Browse the repository at this point in the history
* fix: add ddi step to remove prefix in questionnaire id

* test: unit test

* chore: bump version
  • Loading branch information
nsenave authored Jan 30, 2024
1 parent 063e513 commit f487c48
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
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.16.0'
version = '3.16.1'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public void applyProcessing(EnoQuestionnaire enoQuestionnaire) {
//
ProcessingPipeline<EnoQuestionnaire> processingPipeline = new ProcessingPipeline<>();
processingPipeline.start(enoQuestionnaire)
.then(new DDICleanUpQuestionnaireId())
.then(new DDIMoveUnitInQuestions())
.then(new DDIInsertResponseInTableCells())
.then(new DDIResolveVariableReferencesInExpressions())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fr.insee.eno.core.processing.in.steps.ddi;

import fr.insee.eno.core.exceptions.technical.MappingException;
import fr.insee.eno.core.model.EnoQuestionnaire;
import fr.insee.eno.core.processing.ProcessingStep;
import lombok.extern.slf4j.Slf4j;

/**
* For some reason, an "Insee" prefix is added in the questionnaire identifier by the current Pogues to DDI
* transformation. This processing removes this prefix.
*/
@Slf4j
public class DDICleanUpQuestionnaireId implements ProcessingStep<EnoQuestionnaire> {

private static final String INSEE_PREFIX = "INSEE-";

/**
* Removes the "Insee" prefix in the given questionnaire's id.
* @param enoQuestionnaire A Eno questionnaire.
*/
@Override
public void apply(EnoQuestionnaire enoQuestionnaire) {
if (enoQuestionnaire.getId() == null) // Shouldn't happen but you never know...
throw new MappingException("Questionnaire as a null identifier.");
enoQuestionnaire.setId(enoQuestionnaire.getId().replace(INSEE_PREFIX, ""));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fr.insee.eno.core.processing.in.steps.ddi;

import fr.insee.eno.core.model.EnoQuestionnaire;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class DDICleanUpQuestionnaireIdTest {

@Test
void questionnaireWithNullId_shouldThrowException() {
EnoQuestionnaire enoQuestionnaire = new EnoQuestionnaire();
assertThrows(Exception.class, () -> new DDICleanUpQuestionnaireId().apply(enoQuestionnaire));
}

@Test
void questionnaireWithRegularId_shouldNotBeModified() {
//
EnoQuestionnaire enoQuestionnaire = new EnoQuestionnaire();
enoQuestionnaire.setId("abcde1234");
//
new DDICleanUpQuestionnaireId().apply(enoQuestionnaire);
//
assertEquals("abcde1234", enoQuestionnaire.getId());
}

@Test
void questionnaireWithInseePrefix_shouldBeModified() {
//
EnoQuestionnaire enoQuestionnaire = new EnoQuestionnaire();
enoQuestionnaire.setId("INSEE-abcde1234");
//
new DDICleanUpQuestionnaireId().apply(enoQuestionnaire);
//
assertEquals("abcde1234", enoQuestionnaire.getId());
}

}

0 comments on commit f487c48

Please sign in to comment.