Search in sources :

Example 6 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project openolat by klemens.

the class CSVToQuestionConverterTest method importMultipleChoice.

@Test
public void importMultipleChoice() throws IOException, URISyntaxException {
    URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_mc.txt");
    Assert.assertNotNull(importTxtUrl);
    File importTxt = new File(importTxtUrl.toURI());
    String input = FileUtils.readFileToString(importTxt, "UTF-8");
    Translator translator = new KeyTranslator(Locale.ENGLISH);
    ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
    converter.parse(input);
    List<ItemAndMetadata> items = converter.getItems();
    Assert.assertNotNull(items);
    Assert.assertEquals(1, items.size());
    ItemAndMetadata importedItem = items.get(0);
    Item item = importedItem.getItem();
    Assert.assertNotNull(item);
    Assert.assertEquals("Fussball: Austragungsort", item.getTitle());
    Assert.assertEquals("Die Fussball WM wird alle vier Jahre von einem anderen Land ausgerichtet.", item.getObjectives());
    Assert.assertEquals(Question.TYPE_MC, item.getQuestion().getType());
    Assert.assertTrue(item.getQuestion() instanceof ChoiceQuestion);
    Material questionMat = item.getQuestion().getQuestion();
    Assert.assertNotNull(questionMat);
    Assert.assertNotNull(questionMat.getElements());
    Assert.assertEquals(1, questionMat.getElements().size());
    QTIObject questionMatEl = questionMat.getElements().get(0);
    Assert.assertTrue(questionMatEl instanceof Mattext);
    String text = ((Mattext) questionMatEl).getContent();
    Assert.assertEquals("In welchen L\u00E4ndern wurde zwischen dem Jahr 2000 und 2015 eine Fussball Weltmeisterschaft ausgetragen?", text);
    ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
    Assert.assertNotNull(question.getResponses());
    Assert.assertEquals(7, question.getResponses().size());
    List<Response> responses = question.getResponses();
    Assert.assertEquals(1.0f, responses.get(0).getPoints(), 0.0001);
    Assert.assertEquals(1.0f, responses.get(1).getPoints(), 0.0001);
    Assert.assertEquals(1.0f, responses.get(2).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(3).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(4).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(5).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(6).getPoints(), 0.0001);
    // after it will be set to true for all of them
    Assert.assertTrue(responses.get(0).isCorrect());
    Assert.assertTrue(responses.get(1).isCorrect());
    Assert.assertTrue(responses.get(2).isCorrect());
    Assert.assertFalse(responses.get(3).isCorrect());
    Assert.assertFalse(responses.get(4).isCorrect());
    Assert.assertFalse(responses.get(5).isCorrect());
    Assert.assertFalse(responses.get(6).isCorrect());
    String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
    Assert.assertEquals("Bravo! Die Antwort ich absolut korrekt.", feedbackMastery);
    String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
    Assert.assertEquals("Leider falsch. Probieren Sie es noch einmal.", feedbackFail);
}
Also used : Material(org.olat.ims.qti.editor.beecom.objects.Material) URL(java.net.URL) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) Item(org.olat.ims.qti.editor.beecom.objects.Item) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Translator(org.olat.core.gui.translator.Translator) KeyTranslator(org.olat.test.KeyTranslator) KeyTranslator(org.olat.test.KeyTranslator) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) File(java.io.File) Test(org.junit.Test)

Example 7 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project openolat by klemens.

the class CSVToQuestionConverter method processQuestion.

private void processQuestion(String[] parts) {
    if (currentItem == null)
        return;
    Question question = currentItem.getItem().getQuestion();
    Material mat = question.getQuestion();
    String content = parts[1];
    Mattext matText = new Mattext(content);
    List<QTIObject> elements = new ArrayList<QTIObject>(1);
    elements.add(matText);
    mat.setElements(elements);
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) ArrayList(java.util.ArrayList) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 8 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project openolat by klemens.

the class QTIEditHelper method setFeedback.

/**
 * Set feedback
 * @param object
 * @param feedbackString
 * @param sIdent
 */
public static void setFeedback(QTIObject object, String feedbackString, String sIdent) {
    List<Feedback> feedbacks = getFeedbacks(object);
    Feedback feedback = getFeedback(sIdent, feedbacks);
    if (feedbackString == null || feedbackString.trim().length() == 0) {
        feedbacks.remove(feedback);
        return;
    }
    if (feedback != null) {
        feedbackString = feedbackString.trim();
        List matList = feedback.getMaterials();
        if (matList.size() > 0) {
            Material mat = (Material) feedback.getMaterials().get(0);
            if (mat == null) {
                mat = new Material();
                mat.getElements().add(new Mattext(feedbackString));
                feedback.getMaterials().add(mat);
            } else if (mat.getElements().size() > 0) {
                mat.getElements().set(0, new Mattext(feedbackString));
            } else {
                mat.getElements().add(new Mattext(feedbackString));
            }
        } else {
            Material mat = new Material();
            mat.getElements().add(new Mattext(feedbackString));
            feedback.getMaterials().add(mat);
        }
    } else {
        Feedback newFeedback = new Feedback();
        newFeedback.setIdent(sIdent);
        newFeedback.setView("All");
        Mattext newMattext = new Mattext(feedbackString);
        List<QTIObject> newMattextL = new ArrayList<>();
        newMattextL.add(newMattext);
        Material material = new Material();
        material.setElements(newMattextL);
        List<Material> newMaterialL = new ArrayList<>();
        newMaterialL.add(material);
        newFeedback.setMaterials(newMaterialL);
        feedbacks.add(newFeedback);
    }
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Feedback(org.olat.ims.qti.editor.beecom.objects.Feedback) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 9 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project openolat by klemens.

the class QTIEditorMainController method doMove.

private void doMove(TreePosition tp) {
    // user chose a position to insert a new node
    GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
    int targetPos = tp.getChildpos();
    GenericQtiNode selectedNode = (GenericQtiNode) menuTree.getSelectedNode();
    int selectedPos = selectedNode.getPosition();
    GenericQtiNode parentSelectedNode = (GenericQtiNode) selectedNode.getParent();
    if (parentTargetNode == parentSelectedNode) {
        // if we're on the same subnode
        if (targetPos > selectedNode.getPosition()) {
            // if we're moving after our current position
            targetPos--;
        // decrease insert pos since we're going to be removed from the
        // parent before re-insert
        }
    }
    // insert into menutree (insert on GenericNode do a remove from parent)
    parentTargetNode.insert(selectedNode, targetPos);
    // insert into model (remove from parent needed prior to insert)
    QTIObject subject = parentSelectedNode.removeQTIObjectAt(selectedPos);
    parentTargetNode.insertQTIObjectAt(subject, targetPos);
    qtiPackage.serializeQTIDocument();
    parentSelectedNode.childNodeChanges();
    parentTargetNode.childNodeChanges();
}
Also used : QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode)

Example 10 with QTIObject

use of org.olat.ims.qti.editor.beecom.objects.QTIObject in project openolat by klemens.

the class MaterialParser method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("material");
    List materials = element.elements();
    if (materials.size() == 0)
        return null;
    Material material = new Material();
    // ATTRIBUTES
    Attribute label = element.attribute("label");
    if (label != null)
        material.setLable(label.getValue());
    // ELEMENTS
    for (Iterator i = materials.iterator(); i.hasNext(); ) {
        QTIObject obj = (QTIObject) parserManager.parse((Element) i.next());
        if (obj != null)
            material.getElements().add(obj);
    }
    return material;
}
Also used : QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Iterator(java.util.Iterator) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Aggregations

QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)22 ArrayList (java.util.ArrayList)12 List (java.util.List)10 Element (org.dom4j.Element)10 Iterator (java.util.Iterator)8 Material (org.olat.ims.qti.editor.beecom.objects.Material)8 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)8 Attribute (org.dom4j.Attribute)6 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)4 Duration (org.olat.ims.qti.editor.beecom.objects.Duration)4 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)4 Question (org.olat.ims.qti.editor.beecom.objects.Question)4 Section (org.olat.ims.qti.editor.beecom.objects.Section)4 SelectionOrdering (org.olat.ims.qti.editor.beecom.objects.SelectionOrdering)4 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)4 File (java.io.File)2 URL (java.net.URL)2