use of org.olat.ims.qti21.model.xml.ModalFeedbackBuilder in project openolat by klemens.
the class MultipleChoiceAssessmentItemBuilderTest method readMultipleChoice_allAnswers_1110.
@Test
public void readMultipleChoice_allAnswers_1110() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/multiple-choice-score-all-11-1-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(2, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof ChoiceInteraction);
Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
// choices
SimpleChoice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("mc1959a495d449f9af65b38695d3aff1"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
SimpleChoice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("mca856e7adb54d3f9af06ecf9c00da69"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
SimpleChoice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("mcd39be64a6b4f20a2372cba44340e59"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
SimpleChoice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("mc18648f96a84d479817cb5e81165c80"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(2.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("All answers are correct"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("You missed something"));
// hint
ModalFeedbackBuilder hint = itemBuilder.getHint();
Assert.assertNotNull(hint);
Assert.assertNotNull(hint.getText());
Assert.assertTrue(hint.getText().contains("This is the correct solution"));
// per answer
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
}
use of org.olat.ims.qti21.model.xml.ModalFeedbackBuilder in project openolat by klemens.
the class MultipleChoiceAssessmentItemBuilderTest method readMultipleChoice_perAnswer_1123.
@Test
public void readMultipleChoice_perAnswer_1123() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/multiple-choice-per-answer-11-2-3.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof ChoiceInteraction);
// choices
SimpleChoice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("mc80677ac3f4449ebc689cf60c230a3d"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
SimpleChoice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("mc7e5667abeb415fa05a8c7d8fd3d6bb"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
SimpleChoice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("mcaacc51e0ca4027b3adb3107cda4e30"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
SimpleChoice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("mc1b7b8257e2419b880936ea11bff1f1"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(1.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("All answers correct"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("Some choices are wrong"));
// per answer
Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
use of org.olat.ims.qti21.model.xml.ModalFeedbackBuilder in project openolat by klemens.
the class OnyxToAssessmentItemBuilderTest method extractsingleChoiceWithFeedbacks.
@Test
public void extractsingleChoiceWithFeedbacks() throws URISyntaxException {
URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/onyx/single-choice-1-with-feedbacks_5-11.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
// correct answer
List<SimpleChoice> choices = itemBuilder.getChoices();
Assert.assertNotNull(choices);
SimpleChoice choice = choices.get(3);
Assert.assertTrue(itemBuilder.isCorrect(choice));
// scoring
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
ScoreBuilder maxScoreBuilder = itemBuilder.getMaxScoreBuilder();
Assert.assertEquals(4.0d, maxScoreBuilder.getScore(), 0.00001d);
// check standard feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertTrue(correctFeedback.isCorrectRule());
Assert.assertEquals("<p>Richtig Text</p>", correctFeedback.getText());
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertTrue(incorrectFeedback.isIncorrectRule());
Assert.assertEquals("<p>Falsch Text</p>", incorrectFeedback.getText());
}
use of org.olat.ims.qti21.model.xml.ModalFeedbackBuilder in project openolat by klemens.
the class FeedbacksEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_feedback");
formLayout.setElementCssClass("o_sel_assessment_item_feedbacks");
DropdownItem dropdownEl = uifactory.addDropdownMenu("add.feedback.menu", null, formLayout, getTranslator());
dropdownEl.setOrientation(DropdownOrientation.right);
dropdownEl.setElementCssClass("o_sel_add_feedbacks");
dropdownEl.setVisible(!restrictedEdit && !readOnly);
dropdownEl.setEmbbeded(true);
addHintButton = uifactory.addFormLink("add.hint.feedback", formLayout, Link.LINK);
addHintButton.setElementCssClass("o_sel_add_hint");
addHintButton.setVisible(enable.isEnabled(ModalFeedbackType.hint));
dropdownEl.addElement(addHintButton);
addCorrectSolutionButton = uifactory.addFormLink("add.correctSolution.feedback", formLayout, Link.LINK);
addCorrectSolutionButton.setElementCssClass("o_sel_add_correct_solution");
addCorrectSolutionButton.setVisible(enable.isEnabled(ModalFeedbackType.correctSolution));
dropdownEl.addElement(addCorrectSolutionButton);
addCorrectButton = uifactory.addFormLink("add.correct.feedback", formLayout, Link.LINK);
addCorrectButton.setElementCssClass("o_sel_add_correct");
addCorrectButton.setVisible(enable.isEnabled(ModalFeedbackType.correct));
dropdownEl.addElement(addCorrectButton);
addIncorrectButton = uifactory.addFormLink("add.incorrect.feedback", formLayout, Link.LINK);
addIncorrectButton.setElementCssClass("o_sel_add_incorrect");
addIncorrectButton.setVisible(enable.isEnabled(ModalFeedbackType.incorrect));
dropdownEl.addElement(addIncorrectButton);
addAnsweredButton = uifactory.addFormLink("add.answered.feedback", formLayout, Link.LINK);
addAnsweredButton.setElementCssClass("o_sel_add_answered");
addAnsweredButton.setVisible(enable.isEnabled(ModalFeedbackType.answered));
dropdownEl.addElement(addAnsweredButton);
addEmptyButton = uifactory.addFormLink("add.empty.feedback", formLayout, Link.LINK);
addEmptyButton.setElementCssClass("o_sel_add_empty");
addEmptyButton.setVisible(enable.isEnabled(ModalFeedbackType.empty));
dropdownEl.addElement(addEmptyButton);
addAdditionalButton = uifactory.addFormLink("add.additional.feedback", formLayout, Link.LINK);
addAdditionalButton.setElementCssClass("o_sel_add_conditional");
dropdownEl.addElement(addAdditionalButton);
ModalFeedbackBuilder hint = itemBuilder.getHint();
hintForm = new SimpleFeedbackForm(hint, ModalFeedbackType.hint);
hintForm.initForm(ureq, formLayout);
hintForm.setVisible(!hintForm.isEmpty());
ModalFeedbackBuilder correctSolution = itemBuilder.getCorrectSolutionFeedback();
correctSolutionForm = new SimpleFeedbackForm(correctSolution, ModalFeedbackType.correctSolution);
correctSolutionForm.initForm(ureq, formLayout);
correctSolutionForm.setVisible(!correctSolutionForm.isEmpty());
ModalFeedbackBuilder correct = itemBuilder.getCorrectFeedback();
correctForm = new SimpleFeedbackForm(correct, ModalFeedbackType.correct);
correctForm.initForm(ureq, formLayout);
correctForm.setVisible(!correctForm.isEmpty());
ModalFeedbackBuilder incorrect = itemBuilder.getIncorrectFeedback();
incorrectForm = new SimpleFeedbackForm(incorrect, ModalFeedbackType.incorrect);
incorrectForm.initForm(ureq, formLayout);
incorrectForm.setVisible(!incorrectForm.isEmpty());
ModalFeedbackBuilder answered = itemBuilder.getAnsweredFeedback();
answeredForm = new SimpleFeedbackForm(answered, ModalFeedbackType.answered);
answeredForm.initForm(ureq, formLayout);
answeredForm.setVisible(!answeredForm.isEmpty());
ModalFeedbackBuilder empty = itemBuilder.getEmptyFeedback();
emptyForm = new SimpleFeedbackForm(empty, ModalFeedbackType.empty);
emptyForm.initForm(ureq, formLayout);
emptyForm.setVisible(!emptyForm.isEmpty());
List<ModalFeedbackBuilder> additionals = itemBuilder.getAdditionalFeedbackBuilders();
if (additionals != null && additionals.size() > 0) {
int count = 0;
for (ModalFeedbackBuilder additional : additionals) {
RuledFeedbackForm conditionForm = new RuledFeedbackForm(additional, ++count);
conditionForm.initForm(ureq, formLayout);
additionalForms.add(conditionForm);
}
}
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
layoutCont.contextPut("additionals", additionalForms);
}
// Submit Button
if (!restrictedEdit && !readOnly) {
uifactory.addFormSubmitButton("submit", formLayout);
}
updateAddButtons();
}
use of org.olat.ims.qti21.model.xml.ModalFeedbackBuilder in project openolat by klemens.
the class FeedbacksEditorController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (restrictedEdit || readOnly)
return;
hintForm.commit();
hintForm.setVisible(!hintForm.isEmpty());
correctSolutionForm.commit();
correctSolutionForm.setVisible(!correctSolutionForm.isEmpty());
correctForm.commit();
correctForm.setVisible(!correctForm.isEmpty());
incorrectForm.commit();
incorrectForm.setVisible(!incorrectForm.isEmpty());
answeredForm.commit();
answeredForm.setVisible(!answeredForm.isEmpty());
emptyForm.commit();
emptyForm.setVisible(!emptyForm.isEmpty());
List<RuledFeedbackForm> validAdditionalForms = new ArrayList<>();
List<ModalFeedbackBuilder> additionalBuilders = new ArrayList<>();
for (RuledFeedbackForm additionalForm : additionalForms) {
ModalFeedbackBuilder additionalBuilder = additionalForm.commit();
if (additionalBuilder != null) {
additionalBuilders.add(additionalBuilder);
validAdditionalForms.add(additionalForm);
}
}
itemBuilder.setAdditionalFeedbackBuilders(additionalBuilders);
additionalForms.clear();
additionalForms.addAll(validAdditionalForms);
updateAddButtons();
fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem()));
}
Aggregations