Skip to content

Commit

Permalink
refactor: null cases handling for ddi code lists (#863)
Browse files Browse the repository at this point in the history
* refactor: null cases handling in ddi 'insert code lists' processing

* chore: version 3.15.7
  • Loading branch information
nsenave authored Jan 17, 2024
1 parent 53a7dce commit ad5078b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
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.15.6'
version = '3.15.7'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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.model.code.CodeList;
import fr.insee.eno.core.model.question.*;
Expand Down Expand Up @@ -65,12 +66,37 @@ public void apply(EnoQuestionnaire enoQuestionnaire) {
.forEach(this::insertCodeItems));
}

/**
* Return the code list that is referenced in the Eno component (such as unique choice question, unique choice
* table cell or else) with given id, using the local code list map of this class.
* Throws a runtime exception if there is something null along the way.
* @param codeListReference Code list referenced in the Eno component.
* @param enoComponentId Eno component id.
* @return The corresponding (non-null) code list.
*/
private CodeList getCodeListFromMap(String codeListReference, String enoComponentId) {
if (codeListReference == null)
throw new MappingException(String.format(
"Eno component '%s' has no referenced code list.",
enoComponentId));
CodeList searchedCodeList = codeListMap.get(codeListReference);
if (searchedCodeList == null)
throw new MappingException(String.format(
"Code list referenced in Eno component '%s' with id '%s' cannot be found.",
enoComponentId, codeListReference));
return searchedCodeList;
}

private void insertCodeItems(UniqueChoiceQuestion uniqueChoiceQuestion) {
uniqueChoiceQuestion.setCodeItems(codeListMap.get(uniqueChoiceQuestion.getCodeListReference()).getCodeItems());
uniqueChoiceQuestion.setCodeItems(
getCodeListFromMap(uniqueChoiceQuestion.getCodeListReference(), uniqueChoiceQuestion.getId())
.getCodeItems());
}

private void insertCodeItems(UniqueChoiceCell uniqueChoiceCell) {
uniqueChoiceCell.setCodeItems(codeListMap.get(uniqueChoiceCell.getCodeListReference()).getCodeItems());
uniqueChoiceCell.setCodeItems(
getCodeListFromMap(uniqueChoiceCell.getCodeListReference(), uniqueChoiceCell.getId())
.getCodeItems());
}

private void insertHeader(EnoTable enoTable) {
Expand Down

0 comments on commit ad5078b

Please sign in to comment.