Search in sources :

Example 61 with AssessmentItemRef

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

the class AssessmentTestComposerController method doInsert.

private AssessmentItemRef doInsert(AssessmentSection section, AssessmentItem assessmentItem) throws URISyntaxException {
    AssessmentItemRef itemRef = new AssessmentItemRef(section);
    String itemId = assessmentItem.getIdentifier();
    itemRef.setIdentifier(Identifier.parseString(itemId));
    File itemFile = new File(unzippedDirRoot, itemId + ".xml");
    itemRef.setHref(new URI(itemFile.getName()));
    section.getSectionParts().add(itemRef);
    qtiService.persistAssessmentObject(itemFile, assessmentItem);
    URI testUri = resolvedAssessmentTest.getTestLookup().getSystemId();
    File testFile = new File(testUri);
    qtiService.updateAssesmentObject(testFile, resolvedAssessmentTest);
    manifestBuilder.appendAssessmentItem(itemFile.getName());
    doSaveManifest();
    return itemRef;
}
Also used : AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) File(java.io.File) URI(java.net.URI)

Example 62 with AssessmentItemRef

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

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)

Example 63 with AssessmentItemRef

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

the class AssessmentTestComposerController method doExportPool.

private void doExportPool() {
    TreeNode selectedNode = menuTree.getSelectedNode();
    if (selectedNode == null)
        return;
    AtomicInteger counter = new AtomicInteger();
    Object uobject = selectedNode.getUserObject();
    if (uobject instanceof AssessmentItemRef) {
        doExportPool((AssessmentItemRef) uobject);
        counter.incrementAndGet();
    } else if (uobject instanceof QtiNode) {
        QtiNode qtiNode = (QtiNode) uobject;
        QueryUtils.walkTree(new TreeWalkNodeHandler() {

            @Override
            public boolean handleNode(QtiNode node) {
                if (node instanceof AssessmentItemRef) {
                    doExportPool((AssessmentItemRef) node);
                    counter.incrementAndGet();
                }
                return true;
            }
        }, qtiNode);
    }
    if (counter.get() > 0) {
        showInfo("export.qpool.successful", counter.toString());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) TreeWalkNodeHandler(uk.ac.ed.ph.jqtiplus.utils.TreeWalkNodeHandler) QtiNode(uk.ac.ed.ph.jqtiplus.node.QtiNode)

Example 64 with AssessmentItemRef

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

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 65 with AssessmentItemRef

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

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)

Aggregations

AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)70 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)34 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)32 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)28 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)22 TreeNode (org.olat.core.gui.components.tree.TreeNode)20 File (java.io.File)18 URI (java.net.URI)18 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)18 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)18 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)12 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)12 TestPart (uk.ac.ed.ph.jqtiplus.node.test.TestPart)12 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)12 Identity (org.olat.core.id.Identity)10 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)10 SectionPart (uk.ac.ed.ph.jqtiplus.node.test.SectionPart)10 TestPlanNode (uk.ac.ed.ph.jqtiplus.state.TestPlanNode)10