Skip to content

Commit

Permalink
SAK-44744: SAMIGO - Wrong export when formulas includes more than one…
Browse files Browse the repository at this point in the history
… comma on a calculated question (sakaiproject#8894)
  • Loading branch information
jesusmmp authored Jan 4, 2021
1 parent f888d50 commit 2813e2a
Showing 1 changed file with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,20 +587,31 @@ private void addCalculatedQuestionFormula(ItemTextIfc itemText, Item itemXml, St
for (AnswerIfc answer : answers) {
if (answer.getIsCorrect()) {
String text = answer.getText();
String formula = text.substring(0, text.indexOf("|"));
String tolerance = text.substring(text.indexOf("|") + 1, text.indexOf(","));
String decimalPlaces = text.substring(text.indexOf(",") + 1);

// add nodes
itemXml.add(updatedXpath, "name");
itemXml.update(updatedXpath + "/name", itemText.getText());
itemXml.add(updatedXpath, "formula");
itemXml.update(updatedXpath + "/formula", formula);
itemXml.add(updatedXpath, "tolerance");
itemXml.update(updatedXpath + "/tolerance", tolerance);
itemXml.add(updatedXpath, "decimalPlaces");
itemXml.update(updatedXpath + "/decimalPlaces", decimalPlaces);
break;
String[] partsText = text.split("\\|");
if (partsText != null && partsText.length == 2) {
String formula = partsText[0];
String[] partsTolDp = partsText[1].split(",");
if (partsTolDp != null && partsTolDp.length == 2) {
String tolerance = partsTolDp[0];
String decimalPlaces = partsTolDp[1];

// add nodes
itemXml.add(updatedXpath, "name");
itemXml.update(updatedXpath + "/name", itemText.getText());
itemXml.add(updatedXpath, "formula");
itemXml.update(updatedXpath + "/formula", formula);
itemXml.add(updatedXpath, "tolerance");
itemXml.update(updatedXpath + "/tolerance", tolerance);
itemXml.add(updatedXpath, "decimalPlaces");
itemXml.update(updatedXpath + "/decimalPlaces", decimalPlaces);
break;
}
else {
log.error("Calculated question answer text {} is not formatted correctly.", text);
}
} else {
log.error("Calculated question answer text {} is not formatted correctly.", text);
}
}
}
} catch (Exception e) {
Expand Down

0 comments on commit 2813e2a

Please sign in to comment.