Skip to content

Commit

Permalink
SAK-45722 Samigo placing duplicated variables in calculated question …
Browse files Browse the repository at this point in the history
…(formula placeholders) breaks other placeholder (sakaiproject#12805)
  • Loading branch information
jesusmmp authored Aug 20, 2024
1 parent 15be4c5 commit f866659
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ invalid_min_scale=Min decimal places greater than scale value
invalid_max=Max must be a valid number (0.0)
invalid_max_scale=Max decimal places greater than scale value
unique_names=Variables, Global Variables and Formulas must have unique names
repeated_formula_names_instructions=There are repeated names on formulas {{ }} in the instructions
variable_name_empty=Variable name cannot be empty. Variables must begin with an alpha character and can only contain alpha, numeric, and underscore characters and are wrapped in single curly braces (i.e. {x} )
variable_name_invalid=Variable name is invalid. Variables must begin with an alpha character and can only contain alpha, numeric, and underscore characters and are wrapped in single curly braces (i.e. {x} )
formula_name_empty=Formula name cannot be empty. Formula names must begin with an alpha character and can only contain alpha, numeric, and underscore characters and are wrapped in double curly braces (i.e. {{y}} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ invalid_min_scale=El n\u00famero de decimales m\u00ednimo supera la escala
invalid_max=Max debe ser un n\u00famero v\u00e1lido (0.0)
invalid_max_scale=El n\u00famero de decimales m\u00e1ximo supera la escala
unique_names=Las variables, las variables globales y las f\u00f3rmulas deben tener nombres exclusivos

repeated_formula_names_instructions=No puede haber nombres repetidos en las formulas {{ }} de las instrucciones
variable_name_empty=El nombre de la variable no puede estar vac\u00edo. Las variables deben comenzar con un car\u00e1cter alfab\u00e9tico (no num\u00e9rico) y s\u00f3lo pueden contener caracteres alfanum\u00e9ricos y guiones bajos y deben estar envueltas en llaves individuales (por ejemplo, {x})
variable_name_invalid=El nombre de la variable no es v\u00e1lido. Las variables deben comenzar con un car\u00e1cter alfab\u00e9tico y s\u00f3lo pueden contener caracteres alfanum\u00e9ricos y guiones bajos y deben estar envueltas en llaves individuales (por ejemplo, {x})
formula_name_invalid=El nombre de la f\u00f3rmula no es v\u00e1lido. Los nombres de f\u00f3rmula deben comenzar con un car\u00e1cter alfab\u00e9tico y s\u00f3lo pueden contener caracteres alfanum\u00e9ricos, y guiones bajos y deben estar envueltas en llaves dobles (por ejemplo, {{y}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -136,6 +137,9 @@ public List<String> validate(ItemBean item,boolean extracting) {
errors.addAll(validateExtractedNames(corrvariableNames, corrformulaNames, globalVariableNames));
errors.addAll(validateExtractedNames(incorrvariableNames, incorrformulaNames, globalVariableNames));

//checking if there are duplicated formula names on instructions.
errors.addAll(checkDuplicatesFormulaNamesOnInstructions(formulaNames));

// checking if there are variable names on feedback which are not in instructions.
errors.addAll(checkVariableNamesOnFeedback(variableNames, corrvariableNames, VARIABLE_ON_CORRECT_FEEDBACK_NOT_IN_INSTRUCTIONS));
errors.addAll(checkVariableNamesOnFeedback(variableNames, incorrvariableNames, VARIABLE_ON_INCORRECT_FEEDBACK_NOT_IN_INSTRUCTIONS));
Expand Down Expand Up @@ -853,4 +857,20 @@ private static List<String> checkGlobalVariableNamesFeedabackOnGlobalVariables(M
return errors;
}

/**
* checkDuplicatesFormulaNamesOnInstructions() check if there are duplicated formula names
* @param formulasNames
* @return
*/
private static List<String> checkDuplicatesFormulaNamesOnInstructions(List<String> formulasNames) {
List<String> errors = new ArrayList<String>();

HashSet<String> set = new HashSet<>(formulasNames);
if (set.size() < formulasNames.size()) {
errors.add(getErrorMessage("repeated_formula_names_instructions"));
}

return errors;
}

}

0 comments on commit f866659

Please sign in to comment.