Search in sources :

Example 11 with ManifestBuilder

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

the class QTI21AssessmentDetailsController method doCorrection.

private void doCorrection(UserRequest ureq, AssessmentTestSession session) {
    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(session);
    CorrectionOverviewModel model = new CorrectionOverviewModel(entry, subIdent, testEntry, resolvedAssessmentTest, manifestBuilder, Collections.singletonMap(assessedIdentity, session), Collections.singletonMap(assessedIdentity, testSessionState));
    correctionCtrl = new CorrectionIdentityAssessmentItemListController(ureq, getWindowControl(), stackPanel, model, session, assessedIdentity);
    listenTo(correctionCtrl);
    stackPanel.pushController(translate("correction"), correctionCtrl);
}
Also used : CorrectionOverviewModel(org.olat.ims.qti21.ui.assessment.CorrectionOverviewModel) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) CorrectionIdentityAssessmentItemListController(org.olat.ims.qti21.ui.assessment.CorrectionIdentityAssessmentItemListController) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 12 with ManifestBuilder

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

the class QTI21ExportProcessor method enrichWithMetadata.

public void enrichWithMetadata(QuestionItemFull qitem, ResolvedAssessmentItem resolvedAssessmentItem, ManifestBuilder manifestBuilder) {
    ResourceType resource = manifestBuilder.getResourceTypeByHref(qitem.getRootFilename());
    if (resource == null) {
        resource = manifestBuilder.appendAssessmentItem(qitem.getRootFilename());
    }
    ManifestMetadataBuilder metadataBuilder = manifestBuilder.getMetadataBuilder(resource, true);
    metadataBuilder.appendMetadataFrom(qitem, resolvedAssessmentItem, locale);
}
Also used : ResourceType(org.olat.imscp.xml.manifest.ResourceType) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Example 13 with ManifestBuilder

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

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)

Example 14 with ManifestBuilder

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

the class QTI21QPoolServiceProvider method importRepositoryEntry.

public List<QuestionItem> importRepositoryEntry(Identity owner, RepositoryEntry repositoryEntry, Locale defaultLocale) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(repositoryEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, true);
    ManifestBuilder clonedManifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
    List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getAssessmentItemRefs();
    List<QuestionItem> importedItems = new ArrayList<>(itemRefs.size());
    for (AssessmentItemRef itemRef : itemRefs) {
        ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
        RootNodeLookup<AssessmentItem> rootNode = resolvedAssessmentItem.getItemLookup();
        URI itemUri = rootNode.getSystemId();
        File itemFile = new File(itemUri);
        String relativePathToManifest = unzippedDirRoot.toPath().relativize(itemFile.toPath()).toString();
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        ResourceType resource = clonedManifestBuilder.getResourceTypeByHref(relativePathToManifest);
        ManifestMetadataBuilder metadata = clonedManifestBuilder.getMetadataBuilder(resource, true);
        QuestionItem qitem = importAssessmentItemRef(owner, assessmentItem, itemFile, metadata, defaultLocale);
        importedItems.add(qitem);
    }
    return importedItems;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) ArrayList(java.util.ArrayList) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResourceType(org.olat.imscp.xml.manifest.ResourceType) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) URI(java.net.URI) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) FileResourceManager(org.olat.fileresource.FileResourceManager) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 15 with ManifestBuilder

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

the class QTI21QPoolServiceProvider method importAssessmentItemRef.

/**
 * Very important, the ManifestMetadataBuilder will be changed, it need to be a clone
 *
 * @param owner The future owner of the question
 * @param assessmentItem The assessment item to convert
 * @param itemFile The file where the assessment item is saved
 * @param clonedMetadataBuilder The metadata builder need to be a clone!
 * @param fUnzippedDirRoot The directory of the assessment item or the assessment test.
 * @param defaultLocale The locale used by some translation
 * @return
 */
public QuestionItem importAssessmentItemRef(Identity owner, AssessmentItem assessmentItem, File itemFile, ManifestMetadataBuilder clonedMetadataBuilder, Locale defaultLocale) {
    QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
    AssessmentItemMetadata metadata = new AssessmentItemMetadata(clonedMetadataBuilder);
    String editor = null;
    String editorVersion = null;
    if (StringHelper.containsNonWhitespace(assessmentItem.getToolName())) {
        editor = assessmentItem.getToolName();
    }
    if (StringHelper.containsNonWhitespace(assessmentItem.getToolVersion())) {
        editorVersion = assessmentItem.getToolVersion();
    }
    String originalItemFilename = itemFile.getName();
    QuestionItemImpl qitem = processor.processItem(assessmentItem, null, originalItemFilename, editor, editorVersion, metadata);
    // storage
    File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
    FileUtils.copyDirContentsToDir(itemFile, itemStorage, false, "QTI21 import item xml in pool");
    // create manifest
    ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
    ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
    ManifestMetadataBuilder exportedMetadataBuilder = manifest.getMetadataBuilder(resource, true);
    exportedMetadataBuilder.setMetadata(clonedMetadataBuilder.getMetadata());
    manifest.write(new File(itemStorage, "imsmanifest.xml"));
    // process material
    File materialDirRoot = itemFile.getParentFile();
    List<String> materials = ImportExportHelper.getMaterials(assessmentItem);
    for (String material : materials) {
        if (material.indexOf("://") < 0) {
            // material can be an external URL
            try {
                File materialFile = new File(materialDirRoot, material);
                if (materialFile.isFile() && materialFile.exists()) {
                    File itemMaterialFile = new File(itemStorage, material);
                    if (!itemMaterialFile.getParentFile().exists()) {
                        itemMaterialFile.getParentFile().mkdirs();
                    }
                    Files.copy(materialFile.toPath(), itemMaterialFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                }
            } catch (IOException e) {
                log.error("", e);
            }
        }
    }
    return qitem;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) AssessmentItemMetadata(org.olat.ims.qti21.model.xml.AssessmentItemMetadata) ResourceType(org.olat.imscp.xml.manifest.ResourceType) IOException(java.io.IOException) File(java.io.File) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

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