Commit bf45bdb6 authored by Kevin Robert's avatar Kevin Robert
Browse files

UNOTOPLYS-268 : Ajout de la méthode et du type de condition "hasNoAnswer";

parent 09b891bd
......@@ -14,6 +14,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
@JsonSubTypes.Type(value = AnswerCondition.class, name = "answers"), // Réponses sélectionnées.
@JsonSubTypes.Type(value = ComparisonCondition.class, name = "comparison"), // Comparaison simple.
@JsonSubTypes.Type(value = HasAnswerCondition.class, name = "hasAnswer"), // Question répondue.
@JsonSubTypes.Type(value = HasNoAnswerCondition.class, name = "hasNoAnswer"), // Question non répondue.
@JsonSubTypes.Type(value = AdvancedCondition.class, name = "advanced"), // Saisie manuelle.
@JsonSubTypes.Type(value = RangeCondition.class, name = "range"), // Double comparaison.
}
......
......@@ -87,10 +87,16 @@ public class DisplayConditions {
displayConditions.add(advancedCondition);
}
} else if (astNode instanceof MethodReference) {
final MethodReference hasAnswerMethod = (MethodReference) astNode;
final MethodReference method = (MethodReference) astNode;
if (method.getName().equals("hasAnswer")) {
HasAnswerCondition hasAnswerCondition = new HasAnswerCondition();
displayConditions.add(hasAnswerCondition);
hasAnswerCondition.setQuestionReference(hasAnswerMethod.getChild(0).toStringAST());
hasAnswerCondition.setQuestionReference(method.getChild(0).toStringAST());
} else if (method.getName().equals("hasNoAnswer")) {
HasNoAnswerCondition hasNoAnswerCondition = new HasNoAnswerCondition();
displayConditions.add(hasNoAnswerCondition);
hasNoAnswerCondition.setQuestionReference(method.getChild(0).toStringAST());
}
} else {
AnswerCondition answerCondition = new AnswerCondition();
answerCondition.addAnswers(extractVariableName(astNode.toStringAST()));
......
package com.unantes.orientactive.condition;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.unantes.orientactive.converter.bean.AnswerElements;
import com.unantes.orientactive.converter.bean.Choice;
import com.unantes.orientactive.converter.bean.MultipleChoiceItem;
import com.unantes.orientactive.service.dto.AnswerDTO;
import com.unantes.orientactive.service.dto.VariableDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
......@@ -23,11 +16,17 @@ import org.springframework.expression.ParseException;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import com.unantes.orientactive.converter.bean.AnswerElements;
import com.unantes.orientactive.converter.bean.Choice;
import com.unantes.orientactive.converter.bean.MultipleChoiceItem;
import com.unantes.orientactive.service.dto.AnswerDTO;
import com.unantes.orientactive.service.dto.VariableDTO;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* {@link IExpression}.
......@@ -213,6 +212,16 @@ public class Expression implements IExpression {
return questionsWithAnswer.contains(questionReference);
}
/**
* Inverse de {@link #hasNoAnswer(String)}. Est ce que la question n'a pas de réponse ?
*
* @param questionReference La référence de la question.
* @return Vrai si la question n'a pas de réponse, sinon faux.
*/
public boolean hasNoAnswer(String questionReference) {
return !questionsWithAnswer.contains(questionReference);
}
/**
* Ou exclusif.
* @param op1 opérande 1
......
package com.unantes.orientactive.condition;
/**
* Représentation d'un test permettant de savoir si une question n'est pas répondue.
*/
class HasNoAnswerCondition extends DisplayCondition {
private String questionReference;
public HasNoAnswerCondition() {
super("hasNoAnswer");
}
public String getQuestionReference() {
return questionReference;
}
public void setQuestionReference(String questionReference) {
this.questionReference = questionReference;
}
@Override
public String toSpel() {
return "hasNoAnswer(" + questionReference + ")";
}
}
......@@ -52,7 +52,7 @@ public class ExpressionParsing {
@Test
public void displayConditionWithRange() throws JsonProcessingException {
String s1 =
"(answers[S1_Q1_V1] or answers[S1_Q1_V2]) and variables[score_spe_scient_bacG] > 2 and scores[spes_bac_g_scient4] < 5 and scores[spes_bac_g_scient6] >= 2 and hasAnswer('spes_bac_g_scient4') and scores[spes_bac_g_scient4] > 0";
"(answers[S1_Q1_V1] or answers[S1_Q1_V2]) and variables[score_spe_scient_bacG] > 2 and scores[spes_bac_g_scient4] < 5 and scores[spes_bac_g_scient6] >= 2 and hasAnswer('spes_bac_g_scient4') and hasNoAnswer('spes_bac_g') and scores[spes_bac_g_scient4] > 0";
parseDisplayCondition(s1);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment