-
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.
fix: remove prefix in questionnaire id (#890)
* fix: add ddi step to remove prefix in questionnaire id * test: unit test * chore: bump version
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
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
28 changes: 28 additions & 0 deletions
28
...re/src/main/java/fr/insee/eno/core/processing/in/steps/ddi/DDICleanUpQuestionnaireId.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,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, "")); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...rc/test/java/fr/insee/eno/core/processing/in/steps/ddi/DDICleanUpQuestionnaireIdTest.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,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()); | ||
} | ||
|
||
} |