Search in sources :

Example 16 with ManifestBuilder

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

the class QTI21QPoolServiceProvider method importExcelItem.

public QuestionItemImpl importExcelItem(Identity owner, AssessmentItemAndMetadata itemAndMetadata, Locale defaultLocale) {
    QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
    String editor = itemAndMetadata.getEditor();
    String editorVersion = itemAndMetadata.getEditorVersion();
    AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
    itemBuilder.build();
    AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
    QuestionItemImpl qitem = processor.processItem(assessmentItem, null, null, editor, editorVersion, itemAndMetadata);
    String originalItemFilename = qitem.getRootFilename();
    File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
    File itemFile = new File(itemStorage, originalItemFilename);
    qtiService.persistAssessmentObject(itemFile, assessmentItem);
    // create manifest
    ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
    ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
    ManifestMetadataBuilder metadataBuilder = manifest.getMetadataBuilder(resource, true);
    itemAndMetadata.toBuilder(metadataBuilder, defaultLocale);
    manifest.write(new File(itemStorage, "imsmanifest.xml"));
    return qitem;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResourceType(org.olat.imscp.xml.manifest.ResourceType) HotspotAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder) UploadAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.UploadAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) DrawingAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) 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) File(java.io.File) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Example 17 with ManifestBuilder

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

the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.

public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
    ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
    Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
    // single choice
    File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
    AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
    QtiSerializer qtiSerializer = qtiService.qtiSerializer();
    manifestBuilder.appendAssessmentItem(itemFile.getName());
    // test
    File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
    AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
    manifestBuilder.appendAssessmentTest(testFile.getName());
    // item -> test
    try {
        AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
        AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
    } catch (URISyntaxException e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(itemFile)) {
        qtiSerializer.serializeJqtiObject(assessmentItem, out);
    } catch (Exception e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(testFile)) {
        qtiSerializer.serializeJqtiObject(assessmentTest, out);
    } catch (Exception e) {
        log.error("", e);
    }
    manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) Translator(org.olat.core.gui.translator.Translator) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 18 with ManifestBuilder

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

the class QTI21IdentityListCourseNodeToolsController method doOpenCorrection.

private void doOpenCorrection(UserRequest ureq) {
    File unzippedDirRoot = FileResourceManager.getInstance().unzipFileResource(testEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    ManifestBuilder manifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
    TestSessionState testSessionState = qtiService.loadTestSessionState(lastSession);
    Map<Identity, AssessmentTestSession> lastSessionMap = new HashMap<>();
    lastSessionMap.put(assessedIdentity, lastSession);
    CorrectionOverviewModel model = new CorrectionOverviewModel(courseEntry, testCourseNode.getIdent(), testEntry, resolvedAssessmentTest, manifestBuilder, lastSessionMap, Collections.singletonMap(assessedIdentity, testSessionState));
    correctionCtrl = new CorrectionIdentityAssessmentItemListController(ureq, getWindowControl(), stackPanel, model, lastSession, assessedIdentity);
    listenTo(correctionCtrl);
    stackPanel.pushController(translate("tool.correction"), correctionCtrl);
}
Also used : CorrectionOverviewModel(org.olat.ims.qti21.ui.assessment.CorrectionOverviewModel) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) CorrectionIdentityAssessmentItemListController(org.olat.ims.qti21.ui.assessment.CorrectionIdentityAssessmentItemListController) HashMap(java.util.HashMap) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) Identity(org.olat.core.id.Identity) File(java.io.File)

Example 19 with ManifestBuilder

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

the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.

public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
    ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
    Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
    // single choice
    File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
    AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
    QtiSerializer qtiSerializer = qtiService.qtiSerializer();
    manifestBuilder.appendAssessmentItem(itemFile.getName());
    // test
    File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
    AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
    manifestBuilder.appendAssessmentTest(testFile.getName());
    // item -> test
    try {
        AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
        AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
    } catch (URISyntaxException e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(itemFile)) {
        qtiSerializer.serializeJqtiObject(assessmentItem, out);
    } catch (Exception e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(testFile)) {
        qtiSerializer.serializeJqtiObject(assessmentTest, out);
    } catch (Exception e) {
        log.error("", e);
    }
    manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) Translator(org.olat.core.gui.translator.Translator) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 20 with ManifestBuilder

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

the class QTI21ExportProcessor method process.

public void process(QuestionItemFull qitem, ZipOutputStream zout) {
    String dir = qitem.getDirectory();
    File rootDirectory = qpoolFileStorage.getDirectory(dir);
    String rootDir = "qitem_" + qitem.getKey();
    File imsmanifest = new File(rootDirectory, "imsmanifest.xml");
    ManifestBuilder manifestBuilder;
    if (imsmanifest.exists()) {
        manifestBuilder = ManifestBuilder.read(imsmanifest);
    } else {
        manifestBuilder = new ManifestBuilder();
    }
    File resourceFile = new File(rootDirectory, qitem.getRootFilename());
    URI assessmentItemUri = resourceFile.toURI();
    ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(assessmentItemUri, rootDirectory);
    enrichWithMetadata(qitem, resolvedAssessmentItem, manifestBuilder);
    try {
        zout.putNextEntry(new ZipEntry(rootDir + "/imsmanifest.xml"));
        manifestBuilder.write(new ShieldOutputStream(zout));
        zout.closeEntry();
    } catch (Exception e) {
        log.error("", e);
    }
    try {
        Files.walkFileTree(rootDirectory.toPath(), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String filename = file.getFileName().toString();
                if (!"imsmanifest.xml".equals(filename) && !filename.startsWith(".")) {
                    String relPath = rootDirectory.toPath().relativize(file).toString();
                    ZipUtil.addFileToZip(rootDir + "/" + relPath, file, zout);
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : Path(java.nio.file.Path) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) ZipEntry(java.util.zip.ZipEntry) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)28 File (java.io.File)26 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)18 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)18 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)16 IOException (java.io.IOException)14 ResourceType (org.olat.imscp.xml.manifest.ResourceType)14 URISyntaxException (java.net.URISyntaxException)10 Path (java.nio.file.Path)8 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)8 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)8 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)8 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)8 FileOutputStream (java.io.FileOutputStream)6 URI (java.net.URI)6 AssessmentItemMetadata (org.olat.ims.qti21.model.xml.AssessmentItemMetadata)6 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)6 FileVisitResult (java.nio.file.FileVisitResult)4 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4 ArrayList (java.util.ArrayList)4