Skip to content

Commit

Permalink
feat: adjust lunatic parameters (#752)
Browse files Browse the repository at this point in the history
* refactor: proper class for lunatic parameters

* test(parameters): new specs

* feat(parameters): parametrized file name

* feat(parameters): adjustments with new specs

* chore: bump version
  • Loading branch information
nsenave authored Oct 17, 2023
1 parent 7b4ce13 commit cf5a37b
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 68 deletions.
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.10.10-SNAPSHOT'
version = '3.11.0-SNAPSHOT'
sourceCompatibility = '17'
}

Expand Down
2 changes: 1 addition & 1 deletion eno-core/src/main/java/fr/insee/eno/core/EnoToLunatic.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static Questionnaire transform(EnoQuestionnaire enoQuestionnaire, EnoPara
Questionnaire lunaticQuestionnaire = new Questionnaire();
lunaticMapper.mapQuestionnaire(enoQuestionnaire, lunaticQuestionnaire);
//
LunaticProcessing lunaticProcessing = new LunaticProcessing(enoParameters);
LunaticProcessing lunaticProcessing = new LunaticProcessing(enoParameters.getLunaticParameters());
lunaticProcessing.applyProcessing(lunaticQuestionnaire, enoQuestionnaire);
//
return lunaticQuestionnaire;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.eno.core.parameter;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.insee.eno.core.model.mode.Mode;
Expand Down Expand Up @@ -42,12 +43,8 @@ public enum LunaticPaginationMode {NONE, SEQUENCE, QUESTION}
private List<Mode> selectedModes = new ArrayList<>();

// Lunatic parameters
private boolean controls;
private boolean toolTip; // Not implemented yet in Lunatic
private boolean missingVariables;
private boolean filterResult;
private boolean filterDescription;
private LunaticPaginationMode lunaticPaginationMode;
@JsonProperty("lunatic")
private LunaticParameters lunaticParameters;

private EnoParameters() {}

Expand Down Expand Up @@ -85,8 +82,7 @@ public static EnoParameters of(Context context, ModeParameter modeParameter, For
enoParameters.setOutFormat(outFormat);
//
enoParameters.enoValues(context, modeParameter);
//
enoParameters.lunaticValues(modeParameter);
enoParameters.setLunaticParameters(LunaticParameters.of(context, modeParameter));
//
return enoParameters;
}
Expand All @@ -106,28 +102,11 @@ private void enoValues(Context context, ModeParameter modeParameter) {
//
this.setIdentificationQuestion(Context.BUSINESS.equals(context));
this.setResponseTimeQuestion(Context.BUSINESS.equals(context));
this.setCommentSection(Context.HOUSEHOLD.equals(context) || Context.BUSINESS.equals(context));
this.setCommentSection(Context.BUSINESS.equals(context));
this.setQuestionNumberingMode(
Context.HOUSEHOLD.equals(context) ? QuestionNumberingMode.ALL : QuestionNumberingMode.SEQUENCE);
this.sequenceNumbering = true;
this.arrowCharInQuestions = true;
}

private void lunaticValues(ModeParameter modeParameter) {
//
if (ModeParameter.PAPI.equals(modeParameter))
throw new IllegalArgumentException("Mode 'PAPI' is not compatible with Lunatic format.");
//
boolean isInterview = ModeParameter.CAPI.equals(modeParameter) || ModeParameter.CATI.equals(modeParameter);
boolean isWeb = ModeParameter.CAWI.equals(modeParameter);
boolean isProcess = ModeParameter.PROCESS.equals(modeParameter);
this.setControls(isWeb || isProcess);
this.setToolTip(isWeb || isProcess);
this.setFilterDescription(isProcess);
this.setFilterResult(isWeb);
this.setMissingVariables(isInterview);
this.setLunaticPaginationMode(
isInterview || isWeb ? LunaticPaginationMode.QUESTION : LunaticPaginationMode.NONE);
Context.HOUSEHOLD.equals(context) ? QuestionNumberingMode.NONE : QuestionNumberingMode.SEQUENCE);
this.setSequenceNumbering(true);
this.setArrowCharInQuestions(Context.BUSINESS.equals(context));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package fr.insee.eno.core.parameter;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class LunaticParameters {

private boolean controls;
private boolean toolTip; // Not implemented yet in Lunatic
private boolean missingVariables;
private boolean filterResult;
private boolean filterDescription;
private EnoParameters.LunaticPaginationMode lunaticPaginationMode;

private LunaticParameters() {}

public static LunaticParameters emptyValues() {
return new LunaticParameters();
}

public static LunaticParameters of(EnoParameters.Context context, EnoParameters.ModeParameter modeParameter) {
LunaticParameters parameters = new LunaticParameters();
parameters.lunaticValues(context, modeParameter);
return parameters;
}

private void lunaticValues(EnoParameters.Context context, EnoParameters.ModeParameter modeParameter) {
//
if (EnoParameters.ModeParameter.PAPI.equals(modeParameter))
throw new IllegalArgumentException("Mode 'PAPI' is not compatible with Lunatic format.");
//
boolean isInterview = EnoParameters.ModeParameter.CAPI.equals(modeParameter) || EnoParameters.ModeParameter.CATI.equals(modeParameter);
boolean isWeb = EnoParameters.ModeParameter.CAWI.equals(modeParameter);
boolean isProcess = EnoParameters.ModeParameter.PROCESS.equals(modeParameter);
this.setControls(isWeb || isProcess);
this.setToolTip(isWeb || isProcess);
this.setFilterDescription(isProcess);
this.setFilterResult(isWeb);
this.setMissingVariables(isInterview);
this.setLunaticPaginationMode(
EnoParameters.Context.BUSINESS.equals(context) ?
EnoParameters.LunaticPaginationMode.SEQUENCE :
EnoParameters.LunaticPaginationMode.NONE);
}

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

import fr.insee.eno.core.exceptions.business.EnoParametersException;
import fr.insee.eno.core.model.EnoQuestionnaire;
import fr.insee.eno.core.parameter.EnoParameters;
import fr.insee.eno.core.parameter.Format;
import fr.insee.eno.core.parameter.LunaticParameters;
import fr.insee.eno.core.processing.ProcessingPipeline;
import fr.insee.eno.core.processing.out.steps.lunatic.*;
import fr.insee.eno.core.processing.out.steps.lunatic.calculatedvariable.ShapefromAttributeRetrieval;
Expand All @@ -17,9 +15,9 @@

public class LunaticProcessing {

private final EnoParameters parameters;
private final LunaticParameters parameters;

public LunaticProcessing(EnoParameters parameters) {
public LunaticProcessing(LunaticParameters parameters) {
this.parameters = parameters;
}

Expand All @@ -31,9 +29,6 @@ public LunaticProcessing(EnoParameters parameters) {
*/
public void applyProcessing(Questionnaire lunaticQuestionnaire, EnoQuestionnaire enoQuestionnaire) {
//
if (! Format.LUNATIC.equals(parameters.getOutFormat()))
throw new EnoParametersException("Out format is not 'LUNATIC' in given parameters.");
//
EnoIndex enoIndex = enoQuestionnaire.getIndex();
assert enoIndex != null;
EnoCatalog enoCatalog = new EnoCatalog(enoQuestionnaire);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ class EnoParameterTest {
@Test
void lunaticParameters_DefaultCAWILunatic_testLunaticValues() {
//
EnoParameters parameters = EnoParameters.of(
EnoParameters enoParameters = EnoParameters.of(
EnoParameters.Context.DEFAULT, EnoParameters.ModeParameter.CAWI, Format.LUNATIC);
//
assertTrue(parameters.isControls());
assertTrue(parameters.isToolTip());
assertFalse(parameters.isFilterDescription());
assertTrue(parameters.isFilterResult());
assertFalse(parameters.isMissingVariables());
assertEquals(EnoParameters.LunaticPaginationMode.QUESTION, parameters.getLunaticPaginationMode());
LunaticParameters lunaticParameters = enoParameters.getLunaticParameters();
assertTrue(lunaticParameters.isControls());
assertTrue(lunaticParameters.isToolTip());
assertFalse(lunaticParameters.isFilterDescription());
assertTrue(lunaticParameters.isFilterResult());
assertFalse(lunaticParameters.isMissingVariables());
assertEquals(EnoParameters.LunaticPaginationMode.NONE, lunaticParameters.getLunaticPaginationMode());
}

@Test
Expand All @@ -26,4 +27,45 @@ void lunaticParameters_DefaultPAPILunatic_shouldThrowException() {
EnoParameters.of(EnoParameters.Context.DEFAULT, EnoParameters.ModeParameter.PAPI, Format.LUNATIC));
}

@Test
void parameters_HouseholdCAWILunatic_testEnoValues() {
//
EnoParameters enoParameters = EnoParameters.of(
EnoParameters.Context.HOUSEHOLD, EnoParameters.ModeParameter.CAWI, Format.LUNATIC);
//
assertEquals(EnoParameters.QuestionNumberingMode.NONE, enoParameters.getQuestionNumberingMode());
assertFalse(enoParameters.isArrowCharInQuestions());
assertFalse(enoParameters.isCommentSection());
}

@Test
void parameters_HouseholdCAPILunatic_enoValues() {
//
EnoParameters enoParameters = EnoParameters.of(
EnoParameters.Context.HOUSEHOLD, EnoParameters.ModeParameter.CAPI, Format.LUNATIC);
//
assertEquals(EnoParameters.QuestionNumberingMode.NONE, enoParameters.getQuestionNumberingMode());
assertFalse(enoParameters.isArrowCharInQuestions());
}

@Test
void parameters_HouseholdCATILunatic_enoValues() {
//
EnoParameters enoParameters = EnoParameters.of(
EnoParameters.Context.HOUSEHOLD, EnoParameters.ModeParameter.CAPI, Format.LUNATIC);
//
assertEquals(EnoParameters.QuestionNumberingMode.NONE, enoParameters.getQuestionNumberingMode());
assertFalse(enoParameters.isArrowCharInQuestions());
}

@Test
void parameters_BusinessCAPILunatic_lunaticPagination() {
//
EnoParameters enoParameters = EnoParameters.of(
EnoParameters.Context.BUSINESS, EnoParameters.ModeParameter.CAPI, Format.LUNATIC);
//
LunaticParameters lunaticParameters = enoParameters.getLunaticParameters();
assertEquals(EnoParameters.LunaticPaginationMode.SEQUENCE, lunaticParameters.getLunaticPaginationMode());
}

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

import fr.insee.eno.core.parameter.EnoParameters;
import fr.insee.eno.core.parameter.Format;
import fr.insee.eno.core.parameter.LunaticParameters;
import fr.insee.eno.legacy.parameters.*;
import fr.insee.eno.treatments.LunaticPostProcessing;
import fr.insee.eno.ws.PassThrough;
Expand Down Expand Up @@ -144,43 +145,44 @@ public Mono<ResponseEntity<String>> generateLunaticJsonQuestionnaire(
Mono<LunaticPostProcessing> lunaticPostProcessings = controllerUtils.generateLunaticPostProcessings(specificTreatment);

//
EnoParameters parameters = EnoParameters.of(context, modeParameter, Format.LUNATIC);
EnoParameters enoParameters = EnoParameters.of(context, modeParameter, Format.LUNATIC);
//
parameters.setIdentificationQuestion(identificationQuestion);
parameters.setResponseTimeQuestion(endQuestionResponseTime);
parameters.setIdentificationQuestion(endQuestionCommentQuestion);
enoParameters.setIdentificationQuestion(identificationQuestion);
enoParameters.setResponseTimeQuestion(endQuestionResponseTime);
enoParameters.setIdentificationQuestion(endQuestionCommentQuestion);
if (parsingXpathVTL)
log.info("Parsing XpathVTL parameter is ignored.");
parameters.setFilterDescription(filterDescription);
LunaticParameters lunaticParameters = enoParameters.getLunaticParameters();
lunaticParameters.setFilterDescription(filterDescription);
if (filterDescription)
log.info("'Filter description' feature is not supported yet.");
parameters.setMissingVariables(missingVar);
lunaticParameters.setMissingVariables(missingVar);
if (missingVar)
log.info("'MISSING' variables is not implemented yet.");
parameters.setFilterResult(addFilterResult);
lunaticParameters.setFilterResult(addFilterResult);
if (addFilterResult)
log.info("'FILTER_RESULT' variables is not supported yet.");
parameters.setControls(control);
lunaticParameters.setControls(control);
if (control)
log.info("Generated format controls is not supported yet.");
switch (questNum) {
case ALL -> parameters.setQuestionNumberingMode(EnoParameters.QuestionNumberingMode.ALL);
case MODULE -> parameters.setQuestionNumberingMode(EnoParameters.QuestionNumberingMode.SEQUENCE);
case NO_NUMBER -> parameters.setQuestionNumberingMode(EnoParameters.QuestionNumberingMode.NONE);
case ALL -> enoParameters.setQuestionNumberingMode(EnoParameters.QuestionNumberingMode.ALL);
case MODULE -> enoParameters.setQuestionNumberingMode(EnoParameters.QuestionNumberingMode.SEQUENCE);
case NO_NUMBER -> enoParameters.setQuestionNumberingMode(EnoParameters.QuestionNumberingMode.NONE);
}
parameters.setSequenceNumbering(seqNum);
parameters.setArrowCharInQuestions(preQuestSymbol);
enoParameters.setSequenceNumbering(seqNum);
enoParameters.setArrowCharInQuestions(preQuestSymbol);
switch (pagination) {
case NONE -> parameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.NONE);
case SEQUENCE -> parameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.SEQUENCE);
case NONE -> lunaticParameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.NONE);
case SEQUENCE -> lunaticParameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.SEQUENCE);
case SUBSEQUENCE -> {
parameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.NONE);
lunaticParameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.NONE);
log.info("Lunatic 'SUBSEQUENCE' pagination is not supported. Pagination has been set to 'NONE'.");
}
case QUESTION -> parameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.QUESTION);
case QUESTION -> lunaticParameters.setLunaticPaginationMode(EnoParameters.LunaticPaginationMode.QUESTION);
}
//
return controllerUtils.ddiToLunaticJson(ddiFile, parameters, lunaticPostProcessings);
return controllerUtils.ddiToLunaticJson(ddiFile, enoParameters, lunaticPostProcessings);
}

@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
@RequestMapping("/v3/parameter")
public class V3ParameterController {

public static final String PARAMETERS_V3_FILE_NAME = "default-parameters-v3.json";

private final ParameterService parameterService;

public V3ParameterController(ParameterService parameterService) {
Expand All @@ -30,15 +28,18 @@ public V3ParameterController(ParameterService parameterService) {
description = "Return default parameters file in function of context given, " +
"to be used in V3 endpoints that require a parameter file.")
@GetMapping(value = "{context}/{outFormat}/default", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public Mono<ResponseEntity<String>> v3DefaultParameters(
public Mono<ResponseEntity<String>> v3Parameters(
@PathVariable EnoParameters.Context context,
@PathVariable Format outFormat,
@RequestParam(value = "Mode") EnoParameters.ModeParameter modeParameter) {
//
String parametersFileName = "eno-parameters-" + context + "-" + modeParameter + "-" + outFormat + ".json";
//
return parameterService.defaultParams(context, outFormat, modeParameter)
.map(params -> ResponseEntity
.ok()
.cacheControl(CacheControl.noCache())
.headers(HeadersUtils.with(PARAMETERS_V3_FILE_NAME))
.headers(HeadersUtils.with(parametersFileName))
.body(params));
}

Expand Down

0 comments on commit cf5a37b

Please sign in to comment.