Skip to content

Commit

Permalink
refactor: dynamic table mapping (#1152)
Browse files Browse the repository at this point in the history
* refactor: more robust mapping of ddi rank 1 dimension

* refactor: simplify big integer to string

* chore: bump version
  • Loading branch information
nsenave authored Nov 18, 2024
1 parent f3a9d5c commit f226a9e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ java {

allprojects {
group = "fr.insee.eno"
version = "3.29.0"
version = "3.29.1-SNAPSHOT"
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.eno.core.model.question;

import fr.insee.ddi.lifecycle33.datacollection.GridDimensionType;
import fr.insee.ddi.lifecycle33.datacollection.QuestionGridType;
import fr.insee.ddi.lifecycle33.reusable.CommandCodeType;
import fr.insee.ddi.lifecycle33.reusable.CommandType;
Expand Down Expand Up @@ -92,22 +93,20 @@ public class DynamicTableQuestion extends MultipleResponseQuestion implements En
List<CellLabel> cellLabels = new ArrayList<>();

public static CommandType mapDDISizeExpression(QuestionGridType ddiDynamicTableQuestion) {
checkRank1Dimension(ddiDynamicTableQuestion);
CommandCodeType conditionForContinuation = ddiDynamicTableQuestion.getGridDimensionArray(0).getRoster()
.getConditionForContinuation();
GridDimensionType rank1Dimension = checkRank1Dimension(ddiDynamicTableQuestion);
CommandCodeType conditionForContinuation = rank1Dimension.getRoster().getConditionForContinuation();
if (conditionForContinuation == null)
return null;
return conditionForContinuation.getCommandArray(0);
}

private static void checkRank1Dimension(QuestionGridType ddiDynamicTableQuestion) {
boolean hasRank1Dimension = ddiDynamicTableQuestion.getGridDimensionList().stream()
.filter(gridDimensionType -> gridDimensionType.getRank() != null)
.anyMatch(gridDimensionType -> 1 == gridDimensionType.getRank().intValue());
if (! hasRank1Dimension)
throw new IllegalDDIElementException(
"DDI dynamic table question '" + ddiDynamicTableQuestion.getIDArray(0).getStringValue() +
"' has no rank 1 dimension.");
private static GridDimensionType checkRank1Dimension(QuestionGridType ddiDynamicTableQuestion) {
return ddiDynamicTableQuestion.getGridDimensionList().stream()
.filter(gridDimensionType -> BigInteger.ONE.equals(gridDimensionType.getRank()))
.findAny()
.orElseThrow(() -> new IllegalDDIElementException(
"DDI dynamic table question '" + ddiDynamicTableQuestion.getIDArray(0).getStringValue() +
"' has no rank 1 dimension."));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ else if (enoTable.getSizeExpression() != null)
private static void setMinMaxProperties(DynamicTableQuestion enoTable, LinesRoster lines) {
LabelType minLabel = new LabelType();
minLabel.setType(LabelTypeEnum.VTL);
minLabel.setValue(Integer.toString(enoTable.getMinLines().intValue()));
minLabel.setValue(enoTable.getMinLines().toString());
lines.setMin(minLabel);

LabelType maxLabel = new LabelType();
maxLabel.setType(LabelTypeEnum.VTL);
maxLabel.setValue(Integer.toString(enoTable.getMaxLines().intValue()));
maxLabel.setValue(enoTable.getMaxLines().toString());
lines.setMax(maxLabel);
}

Expand Down

0 comments on commit f226a9e

Please sign in to comment.