Search in sources :

Example 11 with ManifestMetadataBuilder

use of org.olat.ims.qti21.model.xml.ManifestMetadataBuilder 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 12 with ManifestMetadataBuilder

use of org.olat.ims.qti21.model.xml.ManifestMetadataBuilder 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 13 with ManifestMetadataBuilder

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

Example 14 with ManifestMetadataBuilder

use of org.olat.ims.qti21.model.xml.ManifestMetadataBuilder 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 15 with ManifestMetadataBuilder

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

the class CorrectionAssessmentItemListController method loadModel.

private void loadModel(boolean reset, boolean lastSessions) {
    if (lastSessions) {
        model.loadLastSessions();
    }
    ResolvedAssessmentTest resolvedAssessmentTest = model.getResolvedAssessmentTest();
    List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getAssessmentItemRefs();
    List<CorrectionAssessmentItemRow> itemRows = new ArrayList<>(itemRefs.size());
    Map<String, CorrectionAssessmentItemRow> itemRefIdToRows = new HashMap<>();
    for (AssessmentItemRef itemRef : itemRefs) {
        ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        ManifestMetadataBuilder metadata = model.getMetadata(itemRef);
        FormLink toolsLink = uifactory.addFormLink("tools_" + (++counter), "tools", "", null, null, Link.NONTRANSLATED);
        toolsLink.setIconLeftCSS("o_icon o_icon_actions o_icon-lg");
        CorrectionAssessmentItemRow itemRow = new CorrectionAssessmentItemRow(itemRef, assessmentItem, metadata, toolsLink);
        toolsLink.setUserObject(itemRow);
        itemRows.add(itemRow);
        itemRefIdToRows.put(itemRef.getIdentifier().toString(), itemRow);
    }
    List<AssessmentItemSession> itemSessions = qtiService.getAssessmentItemSessions(model.getCourseEntry(), model.getSubIdent(), model.getTestEntry(), null);
    Map<ItemSessionKey, AssessmentItemSession> itemSessionMap = new HashMap<>();
    for (AssessmentItemSession itemSession : itemSessions) {
        AssessmentTestSession candidateSession = itemSession.getAssessmentTestSession();
        if (model.getReversedLastSessions().containsKey(candidateSession)) {
            // the map contains all test sessions the user is allowed to correct
            String itemRefIdentifier = itemSession.getAssessmentItemIdentifier();
            itemSessionMap.put(new ItemSessionKey(candidateSession.getKey(), itemRefIdentifier), itemSession);
        }
    }
    for (Map.Entry<Identity, AssessmentTestSession> entry : model.getLastSessions().entrySet()) {
        if (model.getLastSessions().containsKey(entry.getKey())) {
            TestSessionState testSessionState = model.getTestSessionStates().get(entry.getKey());
            for (Map.Entry<TestPlanNodeKey, ItemSessionState> itemEntry : testSessionState.getItemSessionStates().entrySet()) {
                String itemRefIdentifier = itemEntry.getKey().getIdentifier().toString();
                CorrectionAssessmentItemRow row = itemRefIdToRows.get(itemRefIdentifier);
                if (row != null) {
                    AssessmentItemSession itemSession = itemSessionMap.get(new ItemSessionKey(entry.getValue().getKey(), itemRefIdentifier));
                    appendStatistics(row, itemSession, itemEntry.getValue());
                }
            }
        }
    }
    tableModel.setObjects(itemRows);
    tableEl.reset(reset, reset, true);
}
Also used : TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ItemSessionKey(org.olat.ims.qti21.ui.assessment.model.ItemSessionKey) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) Identity(org.olat.core.id.Identity) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) CorrectionAssessmentItemRow(org.olat.ims.qti21.ui.assessment.model.CorrectionAssessmentItemRow) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) Map(java.util.Map) HashMap(java.util.HashMap) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Aggregations

ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)32 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)22 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)18 File (java.io.File)16 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)16 ResourceType (org.olat.imscp.xml.manifest.ResourceType)14 IOException (java.io.IOException)12 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)12 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)10 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)8 URI (java.net.URI)6 Path (java.nio.file.Path)6 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)6 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)6 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4