Skip to content
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/v3 lunatic resizing #718

Merged
merged 13 commits into from
Sep 25, 2023
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

allprojects {
group = 'fr.insee.eno'
version = '3.9.3-SNAPSHOT'
version = '3.10.0-SNAPSHOT'
sourceCompatibility = '17'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fr.insee.eno.core.exceptions.business;

/** Exception to be thrown if a blocking logical inconsistency is detected in the Lunatic questionnaire. */
public class LunaticLogicException extends RuntimeException {

public LunaticLogicException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/** Exception to be thrown when invalid information is detected in a loop object that makes it impossible to be
* resolved in Lunatic. */
public class LunaticLoopResolutionException extends RuntimeException {
public class LunaticLoopException extends RuntimeException {

public LunaticLoopResolutionException(String message) {
public LunaticLoopException(String message) {
super(message);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.insee.eno.core.exceptions.technical;

/** Exception to be thrown if illegal content if found in a Lunatic pairwise object.
* This exception exists since current Lunatic pairwise modeling relies on implicit conventions. */
public class LunaticPairwiseException extends RuntimeException {

public LunaticPairwiseException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@AllArgsConstructor
public class LunaticResizingLoopVariable {
public class LunaticResizingEntry {
private String name;
private String size;
private List<String> variables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@AllArgsConstructor
public class LunaticResizingPairWiseVariable {
public class LunaticResizingPairwiseEntry {
private String name;
private List<String> sizeForLinksVariables;
private List<String> linksVariables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fr.insee.eno.core.processing.out.steps.lunatic.calculatedvariable.ShapefromAttributeRetrieval;
import fr.insee.eno.core.processing.out.steps.lunatic.calculatedvariable.ShapefromAttributeRetrievalFromVariableGroups;
import fr.insee.eno.core.processing.out.steps.lunatic.pagination.LunaticAddPageNumbers;
import fr.insee.eno.core.processing.out.steps.lunatic.resizing.LunaticAddResizing;
import fr.insee.eno.core.processing.out.steps.lunatic.table.LunaticTableProcessing;
import fr.insee.eno.core.reference.EnoCatalog;
import fr.insee.eno.core.reference.EnoIndex;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void applyProcessing(Questionnaire lunaticQuestionnaire, EnoQuestionnaire
.then(new LunaticLoopResolution(enoQuestionnaire))
.then(new LunaticTableProcessing(enoQuestionnaire))
.then(new LunaticAddMissingVariables(enoCatalog, parameters.isMissingVariables()))
//.then(new LunaticAddResizing(enoQuestionnaire)) // TODO: re-active when work is done
.then(new LunaticAddResizing(enoQuestionnaire))
.then(new LunaticAddHierarchy())
.then(new LunaticAddPageNumbers(parameters.getLunaticPaginationMode()))
.then(new LunaticAddCleaningVariables())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.insee.eno.core.processing.out.steps.lunatic;

import fr.insee.eno.core.exceptions.business.LunaticProcessingException;
import fr.insee.eno.core.exceptions.business.LunaticLoopException;
import fr.insee.eno.core.model.lunatic.MissingBlock;
import fr.insee.eno.core.processing.ProcessingStep;
import fr.insee.eno.core.reference.EnoCatalog;
Expand Down Expand Up @@ -170,7 +170,8 @@ private void setComponentMissingResponse(ComponentType component) {
.map(ComponentSimpleResponseType::getResponse)
.map(ResponseType::getName)
.findFirst()
.orElseThrow(() -> new LunaticProcessingException(String.format("main loop %s does not have a simple question in his components", loop.getId())));
.orElseThrow(() -> new LunaticLoopException(String.format(
"Main loop '%s' does not have a simple question in its components.", loop.getId())));
}

// missing responses are handled on the components of pairwise
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.insee.eno.core.processing.out.steps.lunatic;

import fr.insee.eno.core.Constant;
import fr.insee.eno.core.exceptions.business.LunaticLoopResolutionException;
import fr.insee.eno.core.exceptions.business.LunaticLoopException;
import fr.insee.eno.core.exceptions.technical.MappingException;
import fr.insee.eno.core.model.EnoIdentifiableObject;
import fr.insee.eno.core.model.EnoObject;
Expand Down Expand Up @@ -60,7 +60,7 @@ private static Loop findLunaticLoop(Questionnaire lunaticQuestionnaire, fr.insee

private void insertSequencesInLoop(Questionnaire lunaticQuestionnaire, Loop lunaticLoop, fr.insee.eno.core.model.navigation.Loop enoLoop) {
if (enoLoop.getLoopScope().isEmpty())
throw new LunaticLoopResolutionException("Loop '" + enoLoop.getId() + "' has an empty scope.");
throw new LunaticLoopException("Loop '" + enoLoop.getId() + "' has an empty scope.");
int position = insertSequenceInLoop(lunaticQuestionnaire, lunaticLoop, enoLoop.getLoopScope().get(0).getId());
enoLoop.getLoopScope().stream().skip(1).forEachOrdered(structureItemReference ->
insertSequenceInLoop(lunaticQuestionnaire, lunaticLoop, structureItemReference.getId()));
Expand Down Expand Up @@ -151,7 +151,7 @@ private void setLinkedLoopIterations(Loop lunaticLoop, LinkedLoop enoLinkedLoop)
// We "just" want to find the first variable in the scope of the reference loop
EnoIdentifiableObject reference = enoIndex.get(enoLinkedLoop.getReference());
if (reference instanceof StandaloneLoop enoReferenceLoop) {
String variableName = findFirstVariableOfReference(enoLinkedLoop, enoReferenceLoop);
String variableName = findFirstVariableOfReference(enoLinkedLoop, enoReferenceLoop, enoIndex);
lunaticLoop.setIterations(new LabelType());
lunaticLoop.getIterations().setValue("count("+ variableName +")");
lunaticLoop.getIterations().setType(Constant.LUNATIC_LABEL_VTL);
Expand All @@ -163,24 +163,25 @@ private void setLinkedLoopIterations(Loop lunaticLoop, LinkedLoop enoLinkedLoop)
"Linked loop '%s' is based on a dynamic table. This feature is not supported yet.",
enoLinkedLoop.getId()));
}
throw new LunaticLoopResolutionException(String.format(
throw new LunaticLoopException(String.format(
"Linked loop '%s' reference object's '%s' is neither a loop nor a dynamic table.",
enoLinkedLoop.getId(), reference));
}

private String findFirstVariableOfReference(LinkedLoop enoLinkedLoop, StandaloneLoop enoReferenceLoop) {
public static String findFirstVariableOfReference(LinkedLoop enoLinkedLoop, StandaloneLoop enoReferenceLoop,
EnoIndex enoIndex) {
AbstractSequence startSequence = (AbstractSequence) enoIndex.get(enoReferenceLoop.getLoopScope().get(0).getId());
if (startSequence.getSequenceStructure().isEmpty()) {
throw new LunaticLoopResolutionException(String.format(
throw new LunaticLoopException(String.format(
"Linked loop '%s' is based on loop '%s'. " +
"This loop is defined to start at sequence '%s', which is empty. " +
"Unable to find its first question to compute Lunatic \"iterations\" expression.",
enoLinkedLoop.getId(), enoReferenceLoop.getId(), startSequence.getId()));
}
String firstQuestionId = findFirstQuestionId(startSequence);
String firstQuestionId = findFirstQuestionId(startSequence, enoIndex);
EnoObject firstQuestion = enoIndex.get(firstQuestionId);
if (! (firstQuestion instanceof SingleResponseQuestion)) {
throw new LunaticLoopResolutionException(String.format(
throw new LunaticLoopException(String.format(
"Linked loop '%s' is based on loop '%s' that starts at sequence '%s'. " +
"This first question of the sequence is not a \"simple\" question.",
enoLinkedLoop.getId(), enoReferenceLoop.getId(), startSequence.getId()));
Expand All @@ -190,15 +191,16 @@ private String findFirstVariableOfReference(LinkedLoop enoLinkedLoop, Standalone

/**
* Return the id of the first question in given sequence or subsequence object.
*
* @param sequence Eno sequence object.
* @return The id of the first question within the sequence.
*/
private String findFirstQuestionId(AbstractSequence sequence) {
private static String findFirstQuestionId(AbstractSequence sequence, EnoIndex enoIndex) {
StructureItemReference firstSequenceItem = sequence.getSequenceStructure().get(0);
if (firstSequenceItem.getType() == StructureItemType.QUESTION)
return firstSequenceItem.getId();
AbstractSequence subsequence = (AbstractSequence) enoIndex.get(firstSequenceItem.getId());
return findFirstQuestionId(subsequence);
return findFirstQuestionId(subsequence, enoIndex);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.insee.eno.core.processing.out.steps.lunatic.pagination;

import fr.insee.eno.core.exceptions.business.LunaticLoopResolutionException;
import fr.insee.eno.core.exceptions.business.LunaticLoopException;
import fr.insee.lunatic.model.flat.ComponentType;
import fr.insee.lunatic.model.flat.ComponentTypeEnum;
import fr.insee.lunatic.model.flat.Loop;
Expand Down Expand Up @@ -50,7 +50,7 @@ public void applyNumPageOnSubsequence(Subsequence subsequence, String numPagePre
private boolean shouldLoopBePaginated(Loop loop) {
List<ComponentType> loopComponents = loop.getComponents();
if(loopComponents == null || loopComponents.isEmpty()) {
throw new LunaticLoopResolutionException(String.format("Loop %s should have components inside", loop.getId()));
throw new LunaticLoopException(String.format("Loop %s should have components inside", loop.getId()));
}

return loopComponents.get(0).getComponentType().equals(ComponentTypeEnum.SEQUENCE);
Expand Down
Loading