Search in sources :

Example 31 with AssessmentSection

use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.

public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
    ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
    Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
    // single choice
    File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
    AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
    QtiSerializer qtiSerializer = qtiService.qtiSerializer();
    manifestBuilder.appendAssessmentItem(itemFile.getName());
    // test
    File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
    AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
    manifestBuilder.appendAssessmentTest(testFile.getName());
    // item -> test
    try {
        AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
        AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
    } catch (URISyntaxException e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(itemFile)) {
        qtiSerializer.serializeJqtiObject(assessmentItem, out);
    } catch (Exception e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(testFile)) {
        qtiSerializer.serializeJqtiObject(assessmentTest, out);
    } catch (Exception e) {
        log.error("", e);
    }
    manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) Translator(org.olat.core.gui.translator.Translator) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 32 with AssessmentSection

use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doInsert.

private void doInsert(UserRequest ureq, AssessmentItemsPackage importPackage) {
    TreeNode selectedNode = menuTree.getSelectedNode();
    TreeNode sectionNode = getNearestSection(selectedNode);
    String firstItemId = null;
    boolean errorOnImport = false;
    Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
    try {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        List<AssessmentItemAndMetadata> itemsAndMetadata = importPackage.getItems();
        for (AssessmentItemAndMetadata itemAndMetadata : itemsAndMetadata) {
            if (itemAndMetadata.isHasError()) {
                errorOnImport = true;
                continue;
            }
            AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
            AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
            AssessmentItemRef itemRef = doInsert(section, assessmentItem);
            ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
            metadata.setQtiMetadataInteractionTypes(itemBuilder.getInteractionNames());
            itemAndMetadata.toBuilder(metadata, getLocale());
            if (firstItemId == null) {
                firstItemId = itemRef.getIdentifier().toString();
            }
            flyingObjects.put(itemRef, assessmentItem);
        }
    } catch (URISyntaxException e) {
        errorOnImport = true;
        logError("", e);
    }
    if (errorOnImport) {
        showError("error.import.question");
    }
    if (firstItemId != null) {
        // persist metadata
        doSaveAssessmentTest(ureq, flyingObjects);
        doSaveManifest();
        updateTreeModel(false);
        TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
        menuTree.setSelectedNode(newItemNode);
        menuTree.open(newItemNode);
        partEditorFactory(ureq, newItemNode);
    }
}
Also used : HashMap(java.util.HashMap) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) HotspotAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder) UploadAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.UploadAssessmentItemBuilder) HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) DrawingAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) AssessmentItemAndMetadata(org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)

Example 33 with AssessmentSection

use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doConfirmDelete.

private void doConfirmDelete(UserRequest ureq) {
    if (confirmDeleteCtrl != null)
        return;
    TreeNode selectedNode = menuTree.getSelectedNode();
    if (selectedNode == null) {
        showWarning("warning.atleastone");
        return;
    }
    Object uobject = selectedNode.getUserObject();
    if (uobject instanceof AssessmentTest) {
        showWarning("error.cannot.delete");
    } else if (uobject instanceof TestPart) {
        TestPart testPart = (TestPart) uobject;
        if (testPart.getParent().getTestParts().size() == 1) {
            showWarning("error.cannot.delete");
        }
        String msg = translate("delete.testPart");
        confirmDeleteCtrl = activateYesNoDialog(ureq, translate("tools.change.delete"), msg, confirmDeleteCtrl);
        confirmDeleteCtrl.setUserObject(selectedNode);
    } else {
        String msg;
        if (uobject instanceof AssessmentSection) {
            AssessmentSection section = (AssessmentSection) uobject;
            if (checkAtLeastOneSection(section)) {
                msg = translate("delete.section", selectedNode.getTitle());
            } else {
                showWarning("warning.atleastonesection");
                return;
            }
        } else if (uobject instanceof AssessmentItemRef) {
            msg = translate("delete.item", selectedNode.getTitle());
        } else {
            showError("error.cannot.delete");
            return;
        }
        confirmDeleteCtrl = activateYesNoDialog(ureq, translate("tools.change.delete"), msg, confirmDeleteCtrl);
        confirmDeleteCtrl.setUserObject(selectedNode);
    }
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)

Example 34 with AssessmentSection

use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doInsert.

private void doInsert(UserRequest ureq, List<QuestionItemView> items) {
    TreeNode selectedNode = menuTree.getSelectedNode();
    TreeNode sectionNode = getNearestSection(selectedNode);
    boolean allOk = true;
    String firstItemId = null;
    Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
    try {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        for (QuestionItemView item : items) {
            QuestionItemFull qItem = qti21QPoolServiceProvider.getFullQuestionItem(item);
            AssessmentItem assessmentItem = qti21QPoolServiceProvider.exportToQTIEditor(qItem, getLocale(), unzippedDirRoot);
            if (assessmentItem != null) {
                AssessmentItemRef itemRef = doInsert(section, assessmentItem);
                if (firstItemId == null) {
                    firstItemId = itemRef.getIdentifier().toString();
                }
                flyingObjects.put(itemRef, assessmentItem);
                ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
                metadata.appendMetadataFrom(qItem, assessmentItem, getLocale());
                metadata.setOpenOLATMetadataCopiedAt(new Date());
            } else {
                allOk &= false;
            }
        }
    } catch (IOException | URISyntaxException e) {
        showError("error.import.question");
        logError("", e);
    }
    if (!allOk) {
        showError("error.import.question");
    }
    if (firstItemId != null) {
        // persist metadata
        doSaveAssessmentTest(ureq, flyingObjects);
        doSaveManifest();
        updateTreeModel(false);
        TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
        menuTree.setSelectedNode(newItemNode);
        menuTree.open(newItemNode);
        partEditorFactory(ureq, newItemNode);
    }
}
Also used : HashMap(java.util.HashMap) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Date(java.util.Date) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 35 with AssessmentSection

use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doNewAssessmentItem.

/**
 * The method create a simple single choice, save the assessment item
 * and append it to the test, update the manifest file.
 *
 * @param ureq
 * @param selectedNode
 */
private void doNewAssessmentItem(UserRequest ureq, TreeNode selectedNode, AssessmentItemBuilder itemBuilder) {
    try {
        TreeNode sectionNode = getNearestSection(selectedNode);
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        AssessmentItemRef itemRef = new AssessmentItemRef(section);
        String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
        itemRef.setIdentifier(Identifier.parseString(itemId));
        File itemFile = new File(unzippedDirRoot, itemId + ".xml");
        itemRef.setHref(new URI(itemFile.getName()));
        section.getSectionParts().add(itemRef);
        AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
        qtiService.persistAssessmentObject(itemFile, assessmentItem);
        Map<AssessmentItemRef, AssessmentItem> flyingObjects = Collections.singletonMap(itemRef, assessmentItem);
        doSaveAssessmentTest(ureq, flyingObjects);
        manifestBuilder.appendAssessmentItem(itemFile.getName());
        doSaveManifest();
        updateTreeModel(false);
        TreeNode newItemNode = menuTree.getTreeModel().getNodeById(itemId);
        menuTree.setSelectedNode(newItemNode);
        menuTree.open(newItemNode);
        partEditorFactory(ureq, newItemNode);
    } catch (URISyntaxException e) {
        logError("", e);
    }
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI)

Aggregations

AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)62 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)28 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)26 TestPart (uk.ac.ed.ph.jqtiplus.node.test.TestPart)26 TreeNode (org.olat.core.gui.components.tree.TreeNode)22 File (java.io.File)20 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)20 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)20 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)20 URISyntaxException (java.net.URISyntaxException)16 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)14 IOException (java.io.IOException)12 URI (java.net.URI)12 RubricBlock (uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock)12 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)10 SectionPart (uk.ac.ed.ph.jqtiplus.node.test.SectionPart)10 FileOutputStream (java.io.FileOutputStream)8 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)8 ArrayList (java.util.ArrayList)6 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6