Search in sources :

Example 21 with AssessmentSection

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

the class AssessmentTestHelper method visit.

/**
 * Go through the assessmentTest, visit recursively its test parts, sections and
 * assessment item refs.
 *
 * @param assessmentTest The assessment test to visit
 * @param visitor The visitor
 */
public static void visit(AssessmentTest assessmentTest, AssessmentTestVisitor visitor) {
    List<TestPart> testParts = assessmentTest.getTestParts();
    if (testParts != null && testParts.size() > 0) {
        for (TestPart testPart : testParts) {
            visitor.visit(testPart);
            List<AssessmentSection> sections = testPart.getAssessmentSections();
            if (sections != null && sections.size() > 0) {
                for (AssessmentSection section : sections) {
                    visit(section, visitor);
                }
            }
        }
    }
}
Also used : AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart)

Example 22 with AssessmentSection

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

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 23 with AssessmentSection

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

the class AssessmentTestComposerController method doDelete.

private void doDelete(UserRequest ureq, TreeNode selectedNode) {
    Object uobject = selectedNode.getUserObject();
    if (uobject instanceof TestPart) {
        doDeleteTestPart(ureq, (TestPart) uobject);
    } else if (uobject instanceof AssessmentSection) {
        AssessmentSection section = (AssessmentSection) uobject;
        if (checkAtLeastOneSection(section)) {
            doDeleteAssessmentSection(ureq, section);
        } else {
            showWarning("warning.atleastonesection");
        }
    } else if (uobject instanceof AssessmentItemRef) {
        doDeleteAssessmentItemRef(ureq, (AssessmentItemRef) uobject);
    } else {
        // cannot delete test or test part
        return;
    }
    doSaveAssessmentTest(ureq, null);
    doSaveManifest();
    updateTreeModel(false);
    if (selectedNode != null && selectedNode.getParent() != null) {
        TreeNode parentNode = (TreeNode) selectedNode.getParent();
        menuTree.setSelectedNode(parentNode);
        menuTree.open(parentNode);
        partEditorFactory(ureq, parentNode);
    }
}
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) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)

Example 24 with AssessmentSection

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

the class AssessmentTestComposerController method doDrop.

private void doDrop(UserRequest ureq, String droppedNodeId, String targetnodeId, boolean asChild) {
    TreeNode droppedNode = menuTree.getTreeModel().getNodeById(droppedNodeId);
    TreeNode targetNode = menuTree.getTreeModel().getNodeById(targetnodeId);
    if (droppedNode == null || targetNode == null)
        return;
    Object droppedObject = droppedNode.getUserObject();
    Object targetObject = targetNode.getUserObject();
    if (droppedObject == null || targetObject == null || droppedObject == targetObject)
        return;
    if (asChild) {
        if (droppedObject instanceof AssessmentItemRef && (targetObject instanceof AssessmentSection || targetObject instanceof AssessmentItemRef)) {
            AssessmentItemRef droppedItemRef = (AssessmentItemRef) droppedObject;
            droppedItemRef.getParentSection().getSectionParts().remove(droppedItemRef);
            if (targetObject instanceof AssessmentSection) {
                AssessmentSection targetSection = (AssessmentSection) targetObject;
                targetSection.getSectionParts().add(droppedItemRef);
            } else if (targetObject instanceof AssessmentItemRef) {
                AssessmentItemRef targetItemRef = (AssessmentItemRef) targetObject;
                AssessmentSection targetSection = targetItemRef.getParentSection();
                int pos = targetSection.getChildAbstractParts().indexOf(targetItemRef);
                targetSection.getChildAbstractParts().add(pos, droppedItemRef);
            }
        } else if (droppedObject instanceof AssessmentSection && (targetObject instanceof AssessmentSection || targetObject instanceof TestPart || (targetObject instanceof AssessmentTest && ((AssessmentTest) targetObject).getTestParts().size() == 1))) {
            AssessmentSection droppedSection = (AssessmentSection) droppedObject;
            if (droppedSection.getParentSection() != null) {
                droppedSection.getParentSection().getSectionParts().remove(droppedSection);
            } else {
                droppedSection.getParent().getChildAbstractParts().remove(droppedSection);
            }
            if (targetObject instanceof AssessmentSection) {
                AssessmentSection targetSection = (AssessmentSection) targetObject;
                targetSection.getChildAbstractParts().add(droppedSection);
            } else if (targetObject instanceof TestPart) {
                TestPart targetTestPart = (TestPart) targetObject;
                targetTestPart.getAssessmentSections().add(droppedSection);
            } else if (targetObject instanceof AssessmentTest) {
                TestPart targetTestPart = ((AssessmentTest) targetObject).getTestParts().get(0);
                targetTestPart.getAssessmentSections().add(droppedSection);
            }
        }
    } else {
        if (droppedObject instanceof AssessmentItemRef && targetObject instanceof AssessmentItemRef) {
            AssessmentItemRef droppedItemRef = (AssessmentItemRef) droppedObject;
            droppedItemRef.getParentSection().getSectionParts().remove(droppedItemRef);
            AssessmentItemRef targetItemRef = (AssessmentItemRef) targetObject;
            AssessmentSection targetSection = targetItemRef.getParentSection();
            int pos = targetSection.getChildAbstractParts().indexOf(targetItemRef) + 1;
            if (pos < 0) {
                targetSection.getChildAbstractParts().add(droppedItemRef);
            } else if (pos >= targetSection.getChildAbstractParts().size()) {
                targetSection.getChildAbstractParts().add(droppedItemRef);
            } else {
                targetSection.getChildAbstractParts().add(pos, droppedItemRef);
            }
        } else if (droppedObject instanceof AssessmentSection && targetObject instanceof AssessmentSection) {
            AssessmentSection droppedSection = (AssessmentSection) droppedObject;
            if (droppedSection.getParentSection() != null) {
                droppedSection.getParentSection().getSectionParts().remove(droppedSection);
            } else {
                droppedSection.getParent().getChildAbstractParts().remove(droppedSection);
            }
            AssessmentSection targetSection = (AssessmentSection) targetObject;
            if (targetSection.getParentSection() != null) {
                AssessmentSection targetParentSection = targetSection.getParentSection();
                int pos = targetParentSection.getChildAbstractParts().indexOf(targetSection) + 1;
                if (pos >= targetParentSection.getChildAbstractParts().size()) {
                    targetParentSection.getChildAbstractParts().add(droppedSection);
                } else {
                    targetParentSection.getChildAbstractParts().add(pos, droppedSection);
                }
            } else if (targetSection.getParent() instanceof TestPart) {
                TestPart targetTestPart = (TestPart) targetSection.getParent();
                int pos = targetTestPart.getChildAbstractParts().indexOf(targetSection) + 1;
                if (pos >= targetTestPart.getChildAbstractParts().size()) {
                    targetTestPart.getChildAbstractParts().add(droppedSection);
                } else {
                    targetTestPart.getChildAbstractParts().add(pos, droppedSection);
                }
            }
        }
    }
    // quickly saved the assessment test with wrong parent
    doSaveAssessmentTest(ureq, null);
    // reload a clean instance
    updateTreeModel(false);
    TreeNode droppedItemNode = menuTree.getTreeModel().getNodeById(droppedNode.getIdent());
    if (droppedItemNode != null) {
        menuTree.setSelectedNode(droppedItemNode);
        menuTree.open(droppedItemNode);
        partEditorFactory(ureq, droppedItemNode);
    }
}
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 25 with AssessmentSection

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

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)

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