Search in sources :

Example 36 with AssessmentSection

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

the class AssessmentTestComposerController method doCopy.

private void doCopy(UserRequest ureq) {
    TreeNode selectedNode = menuTree.getSelectedNode();
    if (selectedNode == null || !(selectedNode.getUserObject() instanceof AssessmentItemRef))
        return;
    AssessmentItemRef itemRefToCopy = (AssessmentItemRef) selectedNode.getUserObject();
    AssessmentSection section = itemRefToCopy.getParentSection();
    ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRefToCopy);
    AssessmentItem originalAssessmentItem = resolvedAssessmentItem.getItemLookup().extractIfSuccessful();
    if (originalAssessmentItem == null) {
        showError("error.assessment.item");
        return;
    }
    QTI21QuestionType type = QTI21QuestionType.getType(originalAssessmentItem);
    File itemFile = null;
    try {
        AssessmentItemRef itemRef = new AssessmentItemRef(section);
        String itemId = IdentifierGenerator.newAsString(getTypePrefix(type));
        itemRef.setIdentifier(Identifier.parseString(itemId));
        itemFile = new File(unzippedDirRoot, itemId + ".xml");
        itemRef.setHref(new URI(itemFile.getName()));
        try (OutputStream out = new FileOutputStream(itemFile)) {
            // make the copy
            qtiService.qtiSerializer().serializeJqtiObject(originalAssessmentItem, out);
            // change identifier and title
            ResolvedAssessmentItem resolvedCopyItem = qtiService.loadAndResolveAssessmentItemForCopy(itemFile.toURI(), unzippedDirRoot);
            AssessmentItem copiedAssessmentItem = resolvedCopyItem.getRootNodeLookup().extractIfSuccessful();
            copiedAssessmentItem.setIdentifier(IdentifierGenerator.newAsString(getTypePrefix(type)));
            copiedAssessmentItem.setTitle(originalAssessmentItem.getTitle() + " (Copy)");
            qtiService.updateAssesmentObject(itemFile, resolvedCopyItem);
            // add to section
            section.getSectionParts().add(itemRef);
            Map<AssessmentItemRef, AssessmentItem> flyingObjects = Collections.singletonMap(itemRef, copiedAssessmentItem);
            doSaveAssessmentTest(ureq, flyingObjects);
            manifestBuilder.appendAssessmentItem(itemFile.getName());
            doSaveManifest();
        } catch (Exception e) {
            logError("", e);
        }
        updateTreeModel(false);
        TreeNode newItemNode = menuTree.getTreeModel().getNodeById(itemId);
        menuTree.setSelectedNode(newItemNode);
        menuTree.open(newItemNode);
        partEditorFactory(ureq, newItemNode);
    } catch (URISyntaxException e) {
        logError("", e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) AssertException(org.olat.core.logging.AssertException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QTI21QuestionType(org.olat.ims.qti21.model.QTI21QuestionType) File(java.io.File)

Example 37 with AssessmentSection

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

the class QTI21StatisticResourceResult method buildRecursively.

private TreeNode buildRecursively(AssessmentSection section, TreeNode parentNode) {
    GenericTreeNode sectionNode = new GenericTreeNode();
    sectionNode.setTitle(section.getTitle());
    sectionNode.setIconCssClass("o_icon o_mi_qtisection");
    sectionNode.setUserObject(section);
    parentNode.addChild(sectionNode);
    TreeNode firstItem = null;
    for (SectionPart part : section.getSectionParts()) {
        TreeNode itemNode = null;
        if (part instanceof AssessmentItemRef) {
            itemNode = buildRecursively((AssessmentItemRef) part, sectionNode);
        } else if (part instanceof AssessmentSection) {
            itemNode = buildRecursively((AssessmentSection) part, sectionNode);
        }
        if (firstItem == null) {
            firstItem = itemNode;
        }
    }
    sectionNode.setDelegate(firstItem);
    return firstItem;
}
Also used : SectionPart(uk.ac.ed.ph.jqtiplus.node.test.SectionPart) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)

Example 38 with AssessmentSection

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

the class QTI21StatisticResourceResult method buildRecursively.

private void buildRecursively(AssessmentTest test, GenericTreeNode rootTreeNode) {
    // list all test parts
    List<TestPart> parts = test.getTestParts();
    if (parts.size() == 1) {
        TreeNode firstItem = null;
        List<AssessmentSection> sections = test.getTestParts().get(0).getAssessmentSections();
        for (AssessmentSection section : sections) {
            TreeNode itemNode = buildRecursively(section, rootTreeNode);
            if (firstItem == null) {
                firstItem = itemNode;
            }
        }
    } else {
        int counter = 0;
        for (TestPart part : parts) {
            buildRecursively(part, ++counter, rootTreeNode);
        }
    }
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart)

Example 39 with AssessmentSection

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

the class QTI21StatisticResourceResult method buildRecursively.

private void buildRecursively(TestPart part, int pos, TreeNode parentNode) {
    GenericTreeNode partNode = new GenericTreeNode();
    partNode.setTitle(pos + ". Test part");
    partNode.setIconCssClass("o_icon o_qtiassessment_icon");
    partNode.setUserObject(part);
    parentNode.addChild(partNode);
    TreeNode firstItem = null;
    List<AssessmentSection> sections = part.getAssessmentSections();
    for (AssessmentSection section : sections) {
        TreeNode itemNode = buildRecursively(section, partNode);
        if (firstItem == null) {
            firstItem = itemNode;
        }
    }
    partNode.setDelegate(firstItem);
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)

Example 40 with AssessmentSection

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

the class AssessmentTestEditorAndComposerTreeModel method buildRecursively.

private void buildRecursively(AssessmentSection section, TreeNode parentNode) {
    GenericTreeNode sectionNode = new GenericTreeNode(section.getIdentifier().toString());
    sectionNode.setTitle(section.getTitle());
    sectionNode.setIconCssClass("o_icon o_mi_qtisection");
    sectionNode.setUserObject(section);
    parentNode.addChild(sectionNode);
    for (SectionPart part : section.getSectionParts()) {
        if (part instanceof AssessmentItemRef) {
            buildRecursively((AssessmentItemRef) part, sectionNode);
        } else if (part instanceof AssessmentSection) {
            buildRecursively((AssessmentSection) part, sectionNode);
        }
    }
}
Also used : SectionPart(uk.ac.ed.ph.jqtiplus.node.test.SectionPart) 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)

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