Skip to content

Commit

Permalink
Rename a java field to make it more comprehensible
Browse files Browse the repository at this point in the history
  • Loading branch information
loichenninger committed Sep 10, 2024
1 parent dcf010a commit 984bc36
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/java/fr/insee/bpm/metadata/model/McqVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public McqVariable(String name, Group group, VariableType type, String variableL
@Builder
public McqVariable(String name, Group group, String questionItemName, String text) {
super(name, group, VariableType.BOOLEAN);
this.questionItemName = questionItemName;
this.questionName = questionItemName;
this.text = text;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/insee/bpm/metadata/model/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Variable {

/** Name of the item used to collect the answer. */
@Setter
protected String questionItemName;
protected String questionName;

/** Identifies if the variable is part a question grid */
@Setter
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/fr/insee/bpm/metadata/model/VariablesMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public boolean hasMcq(String questionName) {
return variables.values().stream()
.filter(McqVariable.class::isInstance)
.anyMatch(mcqVariable -> // (FILTER_RESULT variables are upper case)
mcqVariable.getQuestionItemName().equals(questionName)
|| mcqVariable.getQuestionItemName().equalsIgnoreCase(questionName));
mcqVariable.getQuestionName().equals(questionName)
|| mcqVariable.getQuestionName().equalsIgnoreCase(questionName));
}

public Group getMcqGroup(String questionName) {
return variables.values().stream()
.filter(McqVariable.class::isInstance)
.filter(mcqVariable -> mcqVariable.getQuestionItemName().equals(questionName))
.filter(mcqVariable -> mcqVariable.getQuestionName().equals(questionName))
.map(Variable::getGroup)
.findFirst().orElse(null);
}
Expand All @@ -99,14 +99,14 @@ public boolean isInQuestionGrid(String questionName){
return variables.values().stream()
.filter(Variable::isInQuestionGrid)
.anyMatch(varInQuestionGrid -> // (FILTER_RESULT variables are upper case)
(varInQuestionGrid.getQuestionItemName().equals(questionName)
|| varInQuestionGrid.getQuestionItemName().equalsIgnoreCase(questionName)));
(varInQuestionGrid.getQuestionName().equals(questionName)
|| varInQuestionGrid.getQuestionName().equalsIgnoreCase(questionName)));
}

public Group getQuestionGridGroup(String questionName) {
return variables.values().stream()
.filter(Variable::isInQuestionGrid)
.filter(varInQuestionGrid -> varInQuestionGrid.getQuestionItemName().equals(questionName))
.filter(varInQuestionGrid -> varInQuestionGrid.getQuestionName().equals(questionName))
.map(Variable::getGroup)
.findFirst().orElse(null);
}
Expand All @@ -124,7 +124,7 @@ public boolean hasUcq(String variableName) {
public boolean hasUcqMcq(String variableName) {
Variable variable = variables.get(variableName);
if (variable != null) {
return variable instanceof UcqVariable ucqVariable && !ucqVariable.getQuestionItemName().isEmpty();
return variable instanceof UcqVariable ucqVariable && !ucqVariable.getQuestionName().isEmpty();
}
return false;
}
Expand All @@ -139,7 +139,7 @@ public List<UcqVariable> getUcqVariables() {
public List<String> getUcqVariablesNames() {
return variables.values().stream()
.filter(UcqVariable.class::isInstance)
.map(Variable::getQuestionItemName)
.map(Variable::getQuestionName)
.filter(Objects::nonNull)
.distinct()
.toList();
Expand All @@ -148,7 +148,7 @@ public List<String> getUcqVariablesNames() {
public List<String> getMcqVariablesNames() {
return variables.values().stream()
.filter(McqVariable.class::isInstance)
.map(Variable::getQuestionItemName)
.map(Variable::getQuestionName)
.filter(Objects::nonNull)
.distinct()
.toList();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/fr/insee/bpm/metadata/reader/ddi/DDIReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,26 @@ private static void addVariableToVariablesMap(VariablesMap variablesMap, Group g
if (valuesElement != null) {
UcqVariable variable = new UcqVariable(variableName, group, variableType, variableLength);
if (questionName != null) {
variable.setQuestionItemName(questionName.getTextContent());
variable.setQuestionName(questionName.getTextContent());
} /*else if (mcqElement != null) {
variable.setQuestionItemName(mcqElement.getTextContent());
variable.setQuestionName(mcqElement.getTextContent());
variable.setInQuestionGrid(true);
}*/
NodeList valueElements = valuesElement.getChildNodes();
addValues(variable, valueElements);
variablesMap.putVariable(variable);
} else if (questionType != null && questionType.getTextContent().equals("MCQ")) {
McqVariable variable = new McqVariable(variableName, group, variableType, variableLength);
variable.setQuestionItemName(questionName.getTextContent());
variable.setQuestionName(questionName.getTextContent());
variable.setInQuestionGrid(true);
variable.setText(getFirstChildValue(variableElement, "Label"));
variablesMap.putVariable(variable);
} else {
Variable variable = new Variable(variableName, group, variableType, variableLength);
if (questionName != null) {
variable.setQuestionItemName(questionName.getTextContent());
variable.setQuestionName(questionName.getTextContent());
} else {
variable.setQuestionItemName(variableName);
variable.setQuestionName(variableName);
}
variablesMap.putVariable(variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private static void processCheckboxGroup(JsonNode checkboxComponent, Group group
if (isLunaticV2) mcqVariable.setText(response.get(LABEL).get(VALUE).asText());
if (!isLunaticV2) mcqVariable.setText(response.get(LABEL).asText());
mcqVariable.setInQuestionGrid(true);
mcqVariable.setQuestionItemName(questionName);
mcqVariable.setQuestionName(questionName);
metadataModel.getVariables().putVariable(mcqVariable);
variables.remove(variableName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public static MetadataModel createCompleteFakeVariablesMap() {

// unique choice question variable related to multiple choices question
UcqVariable ucqMcq1 = new UcqVariable("CAR_OWNER", rootGroup, VariableType.STRING, "50");
ucqMcq1.setQuestionItemName("VEHICLE_OWNER");
ucqMcq1.setQuestionName("VEHICLE_OWNER");
ucqMcq1.addModality("1", "Yes");
ucqMcq1.addModality("2", "No");
UcqVariable ucqMcq2 = new UcqVariable("MOTO_OWNER", rootGroup, VariableType.STRING, "50");
ucqMcq2.setQuestionItemName("VEHICLE_OWNER");
ucqMcq2.setQuestionName("VEHICLE_OWNER");
ucqMcq2.addModality("1", "Yes");
ucqMcq2.addModality("2", "No");
metadataM.getVariables().putVariable(ucqMcq1);
Expand Down Expand Up @@ -186,7 +186,7 @@ void testMcqMethods() {
.name("RELATIONSHIP_D").group(group).questionItemName("RELATIONSHIP").text("Other").build());
//
assertTrue(metadataModel.getVariables().hasMcq("RELATIONSHIP"));
assertSame("RELATIONSHIP", metadataModel.getVariables().getVariable("RELATIONSHIP_A").getQuestionItemName());
assertSame("RELATIONSHIP", metadataModel.getVariables().getVariable("RELATIONSHIP_A").getQuestionName());
assertFalse(metadataModel.getVariables().hasMcq("ADDRESS"));
assertFalse(metadataModel.getVariables().hasMcq("FIRST_NAME"));
assertFalse(metadataModel.getVariables().hasMcq("CAR_COLOR"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void readVqsWebVariables() throws MalformedURLException, MetadataParserException
assertInstanceOf(McqVariable.class, vqsMetadata.getVariables().getVariable("RELATION1"));
assertInstanceOf(McqVariable.class, vqsMetadata.getVariables().getVariable("RELATION4"));
McqVariable aidregA = (McqVariable) vqsMetadata.getVariables().getVariable("AIDREG_A");
assertEquals("AIDREG", aidregA.getQuestionItemName());
assertEquals("AIDREG", aidregA.getQuestionName());
assertEquals("1 - Oui, une aide aux activités de la vie quotidienne", aidregA.getText());
//
assertFalse(vqsMetadata.getVariables().getVariable("ADRESSE") instanceof McqVariable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void readVqsWebVariables() throws MalformedURLException, MetadataParserException
assertInstanceOf(McqVariable.class, vqsMetadata.getVariables().getVariable("RELATION1"));
assertInstanceOf(McqVariable.class, vqsMetadata.getVariables().getVariable("RELATION4"));
McqVariable aidregA = (McqVariable) vqsMetadata.getVariables().getVariable("AIDREG_A");
assertEquals("AIDREG", aidregA.getQuestionItemName());
assertEquals("AIDREG", aidregA.getQuestionName());
assertEquals("1 - Oui, une aide aux activités de la vie quotidienne", aidregA.getText());
//
assertFalse(vqsMetadata.getVariables().getVariable("ADRESSE") instanceof McqVariable);
Expand Down

0 comments on commit 984bc36

Please sign in to comment.