Search in sources :

Example 1 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.

the class QTIEditorPackageImpl method getQTIDocument.

/**
 * @return Reutrns the QTIDocument structure
 */
public QTIDocument getQTIDocument() {
    if (qtiDocument == null) {
        if (hasSerializedQTIDocument()) {
            qtiDocument = loadSerializedQTIDocument();
            resumed = true;
        } else {
            unzipPackage();
            Document doc = loadQTIDocument();
            if (doc != null) {
                ParserManager parser = new ParserManager();
                qtiDocument = (QTIDocument) parser.parse(doc);
                // grab assessment type
                Metadata meta = qtiDocument.getAssessment().getMetadata();
                String assessType = meta.getField(AssessmentInstance.QMD_LABEL_TYPE);
                if (assessType != null) {
                    qtiDocument.setSurvey(assessType.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY));
                }
                resumed = false;
            } else {
                qtiDocument = null;
            }
        }
    }
    return qtiDocument;
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) Metadata(org.olat.ims.qti.editor.beecom.objects.Metadata) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument)

Example 2 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.

the class QTI12To21Converter method isConvertible.

public static boolean isConvertible(OLATResource resource) {
    if (TestFileResource.TYPE_NAME.equals(resource.getResourceableTypeName())) {
        if (OnyxModule.isOnyxTest(resource)) {
            return true;
        }
        QTIDocument doc = TestFileResource.getQTIDocument(resource);
        if (doc == null) {
            return false;
        }
        boolean alien = false;
        @SuppressWarnings("unchecked") List<Item> items = doc.getAssessment().getItems();
        for (int i = 0; i < items.size(); i++) {
            Item item = items.get(i);
            alien |= item.isAlient();
        }
        return !alien;
    }
    return false;
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 3 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project openolat by klemens.

the class QTI12To21ConverterTest method convert.

@Test
public void convert() throws URISyntaxException, IOException, XmlResourceNotFoundException, ImsManifestException {
    QTIDocument doc = loadDocument("qti12_4questiontypes.xml");
    File exportDir = new File(WebappHelper.getTmpDir(), "qti12to21" + UUID.randomUUID());
    exportDir.mkdirs();
    QTI12To21Converter converter = new QTI12To21Converter(exportDir, Locale.ENGLISH);
    converter.convert(null, doc, null);
    int validAssessmentItems = 0;
    boolean validAssessmentTest = false;
    QtiContentPackageSummary readableManifest = null;
    File[] generatedFiles = exportDir.listFiles();
    for (File generatedFile : generatedFiles) {
        String filename = generatedFile.getName();
        if (filename.equals("imsmanifest.xml")) {
            readableManifest = new QtiContentPackageExtractor(exportDir).parse();
        } else if (filename.startsWith("test")) {
            validAssessmentTest = validateAssessmentTest(generatedFile);
        } else if (filename.endsWith(".xml")) {
            boolean validItem = validateAssessmentItem(generatedFile);
            if (validItem) {
                validAssessmentItems++;
            }
        }
    }
    // delete tmp
    FileUtils.deleteDirsAndFiles(exportDir.toPath());
    Assert.assertTrue(validAssessmentTest);
    Assert.assertEquals(4, validAssessmentItems);
    Assert.assertEquals(1, readableManifest.getTestResources().size());
    Assert.assertEquals(4, readableManifest.getItemResources().size());
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) QtiContentPackageSummary(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary) File(java.io.File) QtiContentPackageExtractor(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageExtractor) Test(org.junit.Test)

Example 4 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project openolat by klemens.

the class IQConfigurationController method needManualCorrectionQTI12.

private boolean needManualCorrectionQTI12(RepositoryEntry re) {
    boolean needManualCorrection = false;
    QTIDocument doc = TestFileResource.getQTIDocument(re.getOlatResource());
    if (doc != null && doc.getAssessment() != null) {
        Assessment ass = doc.getAssessment();
        // Sections with their Items
        List<Section> sections = ass.getSections();
        for (Section section : sections) {
            List<Item> items = section.getItems();
            for (Item item : items) {
                String ident = item.getIdent();
                if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
                    needManualCorrection = true;
                    break;
                }
            }
        }
    }
    return needManualCorrection;
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) Item(org.olat.ims.qti.editor.beecom.objects.Item) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 5 with QTIDocument

use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project openolat by klemens.

the class TestFileResource method getQTIDocument.

public static QTIDocument getQTIDocument(OLATResource resource) {
    File packageDir = FileResourceManager.getInstance().unzipFileResource(resource);
    File qtiFile = new File(packageDir, ImsRepositoryResolver.QTI_FILE);
    try (InputStream in = new FileInputStream(qtiFile)) {
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        Document doc = xmlParser.parse(in, true);
        ParserManager parser = new ParserManager();
        QTIDocument document = (QTIDocument) parser.parse(doc);
        return document;
    } catch (Exception e) {
        log.error("Exception when parsing input QTI input stream for ", e);
        return null;
    }
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMLParser(org.olat.core.util.xml.XMLParser) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) File(java.io.File) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)18 Document (org.dom4j.Document)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 ParserManager (org.olat.ims.qti.editor.beecom.parser.ParserManager)6 File (java.io.File)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 XMLParser (org.olat.core.util.xml.XMLParser)4 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)4 Section (org.olat.ims.qti.editor.beecom.objects.Section)4 IMSEntityResolver (org.olat.ims.resources.IMSEntityResolver)4 FileInputStream (java.io.FileInputStream)2 URISyntaxException (java.net.URISyntaxException)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 Metadata (org.olat.ims.qti.editor.beecom.objects.Metadata)2 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)2 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)2