Search in sources :

Example 6 with AssessmentTestBuilder

use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project OpenOLAT by OpenOLAT.

the class QTI12To21Converter method convert.

public AssessmentTest convert(VFSContainer originalContainer, QTIDocument doc, QTI21DeliveryOptions qti21Options) throws URISyntaxException {
    Assessment assessment = doc.getAssessment();
    AssessmentTest assessmentTest = new AssessmentTest();
    String assessmentTestIdentifier = IdentifierGenerator.newAssessmentTestFilename();
    File testFile = new File(unzippedDirRoot, assessmentTestIdentifier + ".xml");
    manifest.appendAssessmentTest(testFile.getName());
    assessmentTest.setIdentifier(assessmentTestIdentifier);
    assessmentTest.setTitle(assessment.getTitle());
    assessmentTest.setToolName(QTI21Constants.TOOLNAME);
    assessmentTest.setToolVersion(Settings.getVersion());
    convertDuration((Duration) assessment.getDuration(), assessmentTest);
    TestPart testPart = AssessmentTestFactory.createTestPart(assessmentTest);
    ItemSessionControl itemSessionControl = testPart.getItemSessionControl();
    Control tmpControl = QTIEditHelper.getControl(assessment);
    if (tmpControl.getSolution() == Control.CTRL_YES) {
        itemSessionControl.setShowSolution(Boolean.TRUE);
    }
    if (qti21Options != null) {
        qti21Options.setHideFeedbacks(false);
        if (assessment.isInheritControls() && tmpControl.getFeedback() != Control.CTRL_YES) {
            qti21Options.setHideFeedbacks(true);
        }
    }
    AssessmentTestBuilder assessmentTestBuilder = new AssessmentTestBuilder(assessmentTest);
    // root
    List<Section> sections = assessment.getSections();
    for (Section section : sections) {
        convert(section, testPart);
    }
    // this are lost in QTI 2.1
    // assessment.getSelection_ordering().getOrderType();
    // assessment.getSelection_ordering().getSelectionNumber();
    OutcomesProcessing outcomesProcessing = assessment.getOutcomes_processing();
    if (outcomesProcessing != null) {
        String cutValue = outcomesProcessing.getField(OutcomesProcessing.CUTVALUE);
        if (StringHelper.containsNonWhitespace(cutValue)) {
            try {
                assessmentTestBuilder.setCutValue(Double.valueOf(cutValue));
            } catch (NumberFormatException e) {
                log.error("Cannot parse cut value: " + cutValue, e);
            }
        }
    }
    assessmentTestBuilder.setMaxScore(atomicMaxScore.doubleValue());
    assessmentTest = assessmentTestBuilder.build();
    persistAssessmentObject(testFile, assessmentTest);
    manifest.write(new File(unzippedDirRoot, "imsmanifest.xml"));
    copyMaterial(originalContainer);
    return assessmentTest;
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) AssessmentTestBuilder(org.olat.ims.qti21.model.xml.AssessmentTestBuilder) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) OutcomesProcessing(org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing) File(java.io.File) Section(org.olat.ims.qti.editor.beecom.objects.Section) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)

Example 7 with AssessmentTestBuilder

use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project openolat by klemens.

the class QTI21EditForm method update.

protected void update(RepositoryEntry testEntry) {
    Double minValue = null;
    Double maxValue = null;
    Double cutValue = null;
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
    if (assessmentTest != null) {
        AssessmentTestBuilder testBuilder = new AssessmentTestBuilder(assessmentTest);
        maxValue = testBuilder.getMaxScore();
        cutValue = testBuilder.getCutValue();
        if (maxValue != null && "OpenOLAT".equals(assessmentTest.getToolName())) {
            minValue = 0d;
        }
    }
    // Put values to module configuration
    minScoreEl.setValue(minValue == null ? "" : AssessmentHelper.getRoundedScore(minValue));
    minScoreEl.setVisible(minValue != null);
    maxScoreEl.setValue(maxValue == null ? "" : AssessmentHelper.getRoundedScore(maxValue));
    maxScoreEl.setVisible(maxValue != null);
    cutValueEl.setValue(cutValue == null ? "" : AssessmentHelper.getRoundedScore(cutValue));
    cutValueEl.setVisible(cutValue != null);
    update();
}
Also used : ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) AssessmentTestBuilder(org.olat.ims.qti21.model.xml.AssessmentTestBuilder) FileResourceManager(org.olat.fileresource.FileResourceManager) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 8 with AssessmentTestBuilder

use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project openolat by klemens.

the class QTI12To21Converter method convert.

public AssessmentTest convert(VFSContainer originalContainer, QTIDocument doc, QTI21DeliveryOptions qti21Options) throws URISyntaxException {
    Assessment assessment = doc.getAssessment();
    AssessmentTest assessmentTest = new AssessmentTest();
    String assessmentTestIdentifier = IdentifierGenerator.newAssessmentTestFilename();
    File testFile = new File(unzippedDirRoot, assessmentTestIdentifier + ".xml");
    manifest.appendAssessmentTest(testFile.getName());
    assessmentTest.setIdentifier(assessmentTestIdentifier);
    assessmentTest.setTitle(assessment.getTitle());
    assessmentTest.setToolName(QTI21Constants.TOOLNAME);
    assessmentTest.setToolVersion(Settings.getVersion());
    convertDuration((Duration) assessment.getDuration(), assessmentTest);
    TestPart testPart = AssessmentTestFactory.createTestPart(assessmentTest);
    ItemSessionControl itemSessionControl = testPart.getItemSessionControl();
    Control tmpControl = QTIEditHelper.getControl(assessment);
    if (tmpControl.getSolution() == Control.CTRL_YES) {
        itemSessionControl.setShowSolution(Boolean.TRUE);
    }
    if (qti21Options != null) {
        qti21Options.setHideFeedbacks(false);
        if (assessment.isInheritControls() && tmpControl.getFeedback() != Control.CTRL_YES) {
            qti21Options.setHideFeedbacks(true);
        }
    }
    AssessmentTestBuilder assessmentTestBuilder = new AssessmentTestBuilder(assessmentTest);
    // root
    List<Section> sections = assessment.getSections();
    for (Section section : sections) {
        convert(section, testPart);
    }
    // this are lost in QTI 2.1
    // assessment.getSelection_ordering().getOrderType();
    // assessment.getSelection_ordering().getSelectionNumber();
    OutcomesProcessing outcomesProcessing = assessment.getOutcomes_processing();
    if (outcomesProcessing != null) {
        String cutValue = outcomesProcessing.getField(OutcomesProcessing.CUTVALUE);
        if (StringHelper.containsNonWhitespace(cutValue)) {
            try {
                assessmentTestBuilder.setCutValue(Double.valueOf(cutValue));
            } catch (NumberFormatException e) {
                log.error("Cannot parse cut value: " + cutValue, e);
            }
        }
    }
    assessmentTestBuilder.setMaxScore(atomicMaxScore.doubleValue());
    assessmentTest = assessmentTestBuilder.build();
    persistAssessmentObject(testFile, assessmentTest);
    manifest.write(new File(unzippedDirRoot, "imsmanifest.xml"));
    copyMaterial(originalContainer);
    return assessmentTest;
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) AssessmentTestBuilder(org.olat.ims.qti21.model.xml.AssessmentTestBuilder) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) OutcomesProcessing(org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing) File(java.io.File) Section(org.olat.ims.qti.editor.beecom.objects.Section) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)

Example 9 with AssessmentTestBuilder

use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project openolat by klemens.

the class QTI21ExportProcessor method assembleTest.

public void assembleTest(List<QuestionItemFull> fullItems, File directory) {
    try {
        QtiSerializer qtiSerializer = qtiService.qtiSerializer();
        // imsmanifest
        ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
        // assessment test
        DoubleAdder atomicMaxScore = new DoubleAdder();
        AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest("Assessment test from pool", "Section");
        String assessmentTestFilename = assessmentTest.getIdentifier() + ".xml";
        manifest.appendAssessmentTest(assessmentTestFilename);
        // make a section
        AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
        // assessment items
        for (QuestionItemFull qitem : fullItems) {
            File resourceDirectory = qpoolFileStorage.getDirectory(qitem.getDirectory());
            File itemFile = new File(resourceDirectory, qitem.getRootFilename());
            ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(itemFile.toURI(), resourceDirectory);
            AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
            assessmentItem.setIdentifier(QTI21QuestionType.generateNewIdentifier(assessmentItem.getIdentifier()));
            // save the item in its own container
            String container = qitem.getKey().toString();
            File containerDir = new File(directory, container);
            containerDir.mkdirs();
            File newItemFile = new File(containerDir, assessmentItem.getIdentifier() + ".xml");
            String newItemFilename = container + "/" + newItemFile.getName();
            qtiService.persistAssessmentObject(newItemFile, assessmentItem);
            AssessmentTestFactory.appendAssessmentItem(section, newItemFilename);
            manifest.appendAssessmentItem(newItemFilename);
            ManifestMetadataBuilder metadata = manifest.getResourceBuilderByHref(newItemFilename);
            metadata.appendMetadataFrom(qitem, resolvedAssessmentItem, locale);
            Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
            if (maxScore != null) {
                atomicMaxScore.add(maxScore.doubleValue());
            }
            // write materials
            AssessmentItemsAndResources materials = new AssessmentItemsAndResources();
            ImportExportHelper.getMaterials(assessmentItem, itemFile, materials);
            for (ItemMaterial material : materials.getMaterials()) {
                String exportPath = material.getExportUri();
                File originalFile = material.getFile();
                File exportFile = new File(containerDir, exportPath);
                if (!exportFile.getParentFile().exists()) {
                    exportFile.getParentFile().mkdirs();
                }
                FileUtils.bcopy(originalFile, exportFile, "Copy material QTI 2.1");
            }
        }
        AssessmentTestBuilder assessmentTestBuilder = new AssessmentTestBuilder(assessmentTest);
        double sumMaxScore = atomicMaxScore.sum();
        if (sumMaxScore > 0.0d) {
            assessmentTestBuilder.setMaxScore(sumMaxScore);
        }
        assessmentTest = assessmentTestBuilder.build();
        try (FileOutputStream out = new FileOutputStream(new File(directory, assessmentTestFilename))) {
            qtiSerializer.serializeJqtiObject(assessmentTest, out);
        } catch (Exception e) {
            log.error("", e);
        }
        manifest.write(new File(directory, "imsmanifest.xml"));
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) ItemMaterial(org.olat.ims.qti21.pool.ImportExportHelper.ItemMaterial) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) AssessmentTestBuilder(org.olat.ims.qti21.model.xml.AssessmentTestBuilder) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) AssessmentItemsAndResources(org.olat.ims.qti21.pool.ImportExportHelper.AssessmentItemsAndResources) DoubleAdder(java.util.concurrent.atomic.DoubleAdder) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 10 with AssessmentTestBuilder

use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder 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)

Aggregations

File (java.io.File)8 AssessmentTestBuilder (org.olat.ims.qti21.model.xml.AssessmentTestBuilder)8 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)8 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)6 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)4 TestPart (uk.ac.ed.ph.jqtiplus.node.test.TestPart)4 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)4 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)4 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 DoubleAdder (java.util.concurrent.atomic.DoubleAdder)2 Panel (org.olat.core.gui.components.panel.Panel)2 SimpleStackedPanel (org.olat.core.gui.components.panel.SimpleStackedPanel)2 StackedPanel (org.olat.core.gui.components.panel.StackedPanel)2 TooledStackedPanel (org.olat.core.gui.components.stack.TooledStackedPanel)2 FileResourceManager (org.olat.fileresource.FileResourceManager)2 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)2 Control (org.olat.ims.qti.editor.beecom.objects.Control)2