-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ddi to lunatic): dynamic units #1175
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d94cdc6
test: add test questionnaire
nsenave 2e0b291
test: fix typo in test questionnaire
nsenave 3b133d2
feat(dynamic unit): ddi mapping
nsenave 50fa9ee
test: unit on variables mapped from ddi
nsenave af74a00
feat(dynamic unit): update ddi insert unit in questions step
nsenave f54e895
test: little change in test questionnaire
nsenave 69f2304
test(dynamic unit): add test integration test in ddi step
nsenave 80d0d69
feat(dynamic unit): finish mapping and test lunatic output
nsenave c8b0f93
test: update label value in some test
nsenave c1667ab
fix: filter null unit labels
nsenave 1a2809e
chore: bump version
nsenave ae7d59f
chore: remove unused imports
nsenave 01228ce
fix: input number description with unit object
nsenave b5c0391
chore: bump snapshot version
nsenave 9621748
fix: set unit label type to 'vtl'
nsenave 4791cc3
fix(dynamic-unit): bump pogues-model version
nsenave cd65c06
chore: release version 3.31.0 [skip ci]
nsenave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,39 +1,42 @@ | ||
package fr.insee.eno.core.processing.in.steps.ddi; | ||
|
||
import fr.insee.eno.core.model.EnoQuestionnaire; | ||
import fr.insee.eno.core.model.label.DynamicLabel; | ||
import fr.insee.eno.core.model.navigation.Binding; | ||
import fr.insee.eno.core.model.question.*; | ||
import fr.insee.eno.core.model.question.table.NumericCell; | ||
import fr.insee.eno.core.model.question.table.ResponseCell; | ||
import fr.insee.eno.core.model.question.table.TableCell; | ||
import fr.insee.eno.core.model.variable.CollectedVariable; | ||
import fr.insee.eno.core.model.variable.Variable; | ||
import fr.insee.eno.core.processing.ProcessingStep; | ||
import fr.insee.eno.core.reference.EnoIndex; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** Processing step to move units which are mapped in variable objects to numeric questions. */ | ||
@Slf4j | ||
public class DDIMoveUnitInQuestions implements ProcessingStep<EnoQuestionnaire> { | ||
|
||
// TODO: JavaDoc on method or on class? | ||
private final EnoIndex enoIndex; | ||
|
||
public DDIMoveUnitInQuestions(EnoIndex enoIndex) { | ||
this.enoIndex = enoIndex; | ||
} | ||
|
||
/** In DDI, the 'unit' information is accessible in variables. | ||
* This information must also belong in concerned questions in the Eno model. | ||
* In Lunatic, this information is required in some numeric questions. */ | ||
public void apply(EnoQuestionnaire enoQuestionnaire) { | ||
// TODO: assert or proper log + exception? | ||
assert enoQuestionnaire.getIndex() != null; | ||
// | ||
enoQuestionnaire.getVariables().stream() | ||
.filter(variable -> Variable.CollectionType.COLLECTED.equals(variable.getCollectionType())) | ||
.map(CollectedVariable.class::cast) | ||
.filter(variable -> variable.getUnit() != null) | ||
.forEach(variable -> { | ||
Question question = (Question) enoQuestionnaire.get(variable.getQuestionReference()); | ||
Question question = (Question) enoIndex.get(variable.getQuestionReference()); | ||
if (question instanceof NumericQuestion numericQuestion) { | ||
numericQuestion.setUnit(variable.getUnit()); | ||
numericQuestion.setUnit(createUnit(variable.getUnit())); | ||
return; | ||
} | ||
|
||
|
@@ -86,6 +89,16 @@ private void applyUnitOnNumericCell(Variable variable, List<Binding> bindings, L | |
return; | ||
} | ||
|
||
numericCell.get().setUnit(variable.getUnit()); | ||
numericCell.get().setUnit(createUnit(variable.getUnit())); | ||
} | ||
|
||
public static DynamicLabel createUnit(String value) { | ||
if (value == null) | ||
return null; | ||
DynamicLabel label = new DynamicLabel(); | ||
label.setValue(value); | ||
// (type is left at its default value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm j'aurais pu skip tout le code que j'ai ajouté dans |
||
return label; | ||
} | ||
|
||
} |
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
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
45 changes: 45 additions & 0 deletions
45
eno-core/src/test/java/fr/insee/eno/core/mapping/in/ddi/VariableTest.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,45 @@ | ||
package fr.insee.eno.core.mapping.in.ddi; | ||
|
||
import fr.insee.eno.core.exceptions.business.DDIParsingException; | ||
import fr.insee.eno.core.mappers.DDIMapper; | ||
import fr.insee.eno.core.model.EnoQuestionnaire; | ||
import fr.insee.eno.core.model.variable.Variable; | ||
import fr.insee.eno.core.serialize.DDIDeserializer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class VariableTest { | ||
|
||
@Test | ||
void variableUnitIntegrationTest() throws DDIParsingException { | ||
// Given + When | ||
EnoQuestionnaire enoQuestionnaire = new EnoQuestionnaire(); | ||
DDIMapper ddiMapper = new DDIMapper(); | ||
ddiMapper.mapDDI( | ||
DDIDeserializer.deserialize(this.getClass().getClassLoader().getResourceAsStream( | ||
"integration/ddi/ddi-dynamic-unit.xml")), | ||
enoQuestionnaire); | ||
|
||
// Then | ||
// Index variables by name to ease testing | ||
Map<String, Variable> variableMap = enoQuestionnaire.getVariables().stream() | ||
.collect(Collectors.toMap(Variable::getName, variable -> variable)); | ||
// | ||
assertEquals("€", variableMap.get("NUMBER_FIXED_UNIT").getUnit()); | ||
assertEquals("%", variableMap.get("TABLE11").getUnit()); | ||
assertEquals("%", variableMap.get("TABLE21").getUnit()); | ||
assertEquals("€", variableMap.get("DYNAMIC_TABLE1").getUnit()); | ||
List.of("NUMBER_DYNAMIC_UNIT", "TABLE12", "TABLE22", "DYNAMIC_TABLE2").forEach(variableName -> | ||
assertTrue(variableMap.get(variableName).getUnit().contains("¤"))); | ||
// | ||
List.of("NUMBER_FIXED_UNIT", "TABLE11", "TABLE21", "DYNAMIC_TABLE1").forEach(variableName -> | ||
assertFalse(variableMap.get(variableName).getIsUnitDynamic())); | ||
List.of("NUMBER_DYNAMIC_UNIT", "TABLE12", "TABLE22", "DYNAMIC_TABLE2").forEach(variableName -> | ||
assertTrue(variableMap.get(variableName).getIsUnitDynamic())); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (value == null || value.trim().isEmpty()) { throw new InvalidValueException("The value for DynamicLabel cannot be null or empty."); }
Ne serait-ce pas mieux de lever une exception ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui je comprends ta remarque c'est le signe d'une faiblesse dans la modélisation de cet objet, mais il a le droit de façon légitime de ne pas avoir de
unit
, dans ces cas là la prop reste ànull
donc pas besoin de créer un objet "label" sur la cible.Ceci dit, au départ la méthode était en privée ici donc c'était pas trop gênant, mais entre deux je l'ai passée en public pour m'en resservir ailleurs, et dans le "cas général" c'est piégeux que la méthode puisse renvoyer du
null
en effetJe vais essayer de refacto pour faire plus propre