Search in sources :

Example 6 with AssessmentSection

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

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

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

the class AssessmentTestComposerController method doNewSection.

private void doNewSection(UserRequest ureq, TreeNode selectedNode) {
    AbstractPart parentPart;
    TreeNode sectionNode = getNearestSection(selectedNode);
    if (sectionNode != null) {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        parentPart = section.getParent();
    } else if (selectedNode.getUserObject() instanceof TestPart) {
        parentPart = (TestPart) selectedNode.getUserObject();
    } else {
        TreeNode rootNode = menuTree.getTreeModel().getRootNode();
        AssessmentTest assessmentTest = (AssessmentTest) rootNode.getUserObject();
        List<TestPart> parts = assessmentTest.getTestParts();
        if (parts != null && parts.size() > 0) {
            parentPart = parts.get(0);
        } else {
            showWarning("error.cannot.create.section");
            return;
        }
    }
    AssessmentSection newSection;
    if (parentPart instanceof TestPart) {
        newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (TestPart) parentPart);
    } else if (parentPart instanceof AssessmentSection) {
        newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (AssessmentSection) parentPart);
    } else {
        showWarning("error.cannot.create.section");
        return;
    }
    // save the test
    URI testUri = resolvedAssessmentTest.getTestLookup().getSystemId();
    File testFile = new File(testUri);
    qtiService.updateAssesmentObject(testFile, resolvedAssessmentTest);
    assessmentChanged(ureq);
    // reload the test
    updateTreeModel(false);
    TreeNode newSectionNode = menuTree.getTreeModel().getNodeById(newSection.getIdentifier().toString());
    menuTree.setSelectedNode(newSectionNode);
    menuTree.open(newSectionNode);
    partEditorFactory(ureq, newSectionNode);
}
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) AbstractPart(uk.ac.ed.ph.jqtiplus.node.test.AbstractPart) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) File(java.io.File)

Example 8 with AssessmentSection

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

the class AssessmentTestComposerController method partEditorFactory.

private void partEditorFactory(UserRequest ureq, TreeNode selectedNode) {
    // remove old one
    if (currentEditorCtrl != null) {
        mainVC.remove(currentEditorCtrl.getInitialComponent());
        removeAsListenerAndDispose(currentEditorCtrl);
        currentEditorCtrl = null;
    }
    // fill with the new
    mainVC.contextPut("cssClass", selectedNode.getIconCssClass());
    if (Settings.isDebuging()) {
        mainVC.contextPut("identifier", selectedNode.getIdent());
    }
    mainVC.contextPut("title", selectedNode.getTitle());
    mainVC.contextPut("restrictedEdit", restrictedEdit);
    Object uobject = selectedNode.getUserObject();
    if (uobject instanceof AssessmentTest) {
        AssessmentTest test = (AssessmentTest) uobject;
        URI testURI = resolvedAssessmentTest.getTestLookup().getSystemId();
        File testFile = new File(testURI);
        TestPart uniqueTestPart = test.getTestParts().size() == 1 ? test.getTestParts().get(0) : null;
        currentEditorCtrl = new AssessmentTestEditorController(ureq, getWindowControl(), assessmentTestBuilder, uniqueTestPart, unzippedDirRoot, unzippedContRoot, testFile, restrictedEdit);
    } else if (uobject instanceof TestPart) {
        currentEditorCtrl = new AssessmentTestPartEditorController(ureq, getWindowControl(), (TestPart) uobject, restrictedEdit, assessmentTestBuilder.isEditable());
    } else if (uobject instanceof AssessmentSection) {
        URI testURI = resolvedAssessmentTest.getTestLookup().getSystemId();
        File testFile = new File(testURI);
        currentEditorCtrl = new AssessmentSectionEditorController(ureq, getWindowControl(), (AssessmentSection) uobject, unzippedDirRoot, unzippedContRoot, testFile, restrictedEdit, assessmentTestBuilder.isEditable());
    } else if (uobject instanceof AssessmentItemRef) {
        AssessmentItemRef itemRef = (AssessmentItemRef) uobject;
        ResolvedAssessmentItem item = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
        if (item == null || item.getItemLookup() == null) {
            currentEditorCtrl = new BadResourceController(ureq, getWindowControl(), null, unzippedDirRoot, itemRef.getHref());
        } else if (item.getItemLookup().getBadResourceException() != null) {
            currentEditorCtrl = new BadResourceController(ureq, getWindowControl(), item.getItemLookup().getBadResourceException(), unzippedDirRoot, itemRef.getHref());
        } else {
            URI itemUri = resolvedAssessmentTest.getSystemIdByItemRefMap().get(itemRef);
            File itemFile = new File(itemUri);
            ManifestMetadataBuilder metadata = getMetadataBuilder(itemRef);
            currentEditorCtrl = new AssessmentItemEditorController(ureq, getWindowControl(), testEntry, item, itemRef, metadata, unzippedDirRoot, unzippedContRoot, itemFile, restrictedEdit);
        }
    }
    if (deleteLink != null) {
        if (uobject instanceof AssessmentSection || uobject instanceof AssessmentItemRef) {
            deleteLink.setEnabled(true);
        } else if (uobject instanceof TestPart) {
            TestPart testPart = (TestPart) uobject;
            deleteLink.setEnabled(testPart.getParent().getTestParts().size() > 1);
        } else {
            deleteLink.setEnabled(false);
        }
    }
    if (copyLink != null) {
        copyLink.setEnabled(uobject instanceof AssessmentItemRef);
    }
    if (currentEditorCtrl != null) {
        listenTo(currentEditorCtrl);
        mainVC.put("content", currentEditorCtrl.getInitialComponent());
    } else {
        mainVC.put("content", new Panel("empty"));
    }
}
Also used : URI(java.net.URI) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) StackedPanel(org.olat.core.gui.components.panel.StackedPanel) SimpleStackedPanel(org.olat.core.gui.components.panel.SimpleStackedPanel) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) Panel(org.olat.core.gui.components.panel.Panel) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) 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) File(java.io.File)

Example 9 with AssessmentSection

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

the class AssessmentTestComposerController method doDeleteTestPart.

private void doDeleteTestPart(UserRequest ureq, TestPart testPart) {
    List<AssessmentSection> sections = new ArrayList<>(testPart.getAssessmentSections());
    for (AssessmentSection section : sections) {
        doDeleteAssessmentSection(ureq, section);
    }
    testPart.getParent().getTestParts().remove(testPart);
}
Also used : AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) ArrayList(java.util.ArrayList)

Example 10 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(TestPart part, int pos, TreeNode parentNode) {
    GenericTreeNode partNode = new GenericTreeNode(part.getIdentifier().toString());
    partNode.setTitle(pos + ". Test part");
    partNode.setIconCssClass("o_icon o_qtiassessment_icon");
    partNode.setUserObject(part);
    parentNode.addChild(partNode);
    List<AssessmentSection> sections = part.getAssessmentSections();
    for (AssessmentSection section : sections) {
        buildRecursively(section, partNode);
    }
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)

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