Search in sources :

Example 16 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.

the class AssessmentTestComposerController method doInsert.

private void doInsert(UserRequest ureq, List<QuestionItemView> items) {
    TreeNode selectedNode = menuTree.getSelectedNode();
    TreeNode sectionNode = getNearestSection(selectedNode);
    boolean allOk = true;
    String firstItemId = null;
    Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
    try {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        for (QuestionItemView item : items) {
            QuestionItemFull qItem = qti21QPoolServiceProvider.getFullQuestionItem(item);
            AssessmentItem assessmentItem = qti21QPoolServiceProvider.exportToQTIEditor(qItem, getLocale(), unzippedDirRoot);
            if (assessmentItem != null) {
                AssessmentItemRef itemRef = doInsert(section, assessmentItem);
                if (firstItemId == null) {
                    firstItemId = itemRef.getIdentifier().toString();
                }
                flyingObjects.put(itemRef, assessmentItem);
                ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
                metadata.appendMetadataFrom(qItem, assessmentItem, getLocale());
                metadata.setOpenOLATMetadataCopiedAt(new Date());
            } else {
                allOk &= false;
            }
        }
    } catch (IOException | URISyntaxException e) {
        showError("error.import.question");
        logError("", e);
    }
    if (!allOk) {
        showError("error.import.question");
    }
    if (firstItemId != null) {
        // persist metadata
        doSaveAssessmentTest(ureq, flyingObjects);
        doSaveManifest();
        updateTreeModel(false);
        TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
        menuTree.setSelectedNode(newItemNode);
        menuTree.open(newItemNode);
        partEditorFactory(ureq, newItemNode);
    }
}
Also used : HashMap(java.util.HashMap) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Date(java.util.Date) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 17 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.

the class QTIQPoolServiceProvider method exportToQTIEditor.

/**
 * Export to QTI editor an item from the pool. The ident of the item
 * is always regenerated as an UUID.
 * @param qitem
 * @param editorContainer
 * @return
 */
public Item exportToQTIEditor(QuestionItemShort qitem, VFSContainer editorContainer) {
    QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
    QuestionItemFull fullItem = questionItemDao.loadById(qitem.getKey());
    Element itemEl = processor.exportToQTIEditor(fullItem, editorContainer);
    Item exportedItem = (Item) new ParserManager().parse(itemEl);
    exportedItem.setIdent(QTIEditHelper.generateNewIdent(exportedItem.getIdent()));
    return exportedItem;
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) Element(org.dom4j.Element)

Example 18 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.

the class QTIExportProcessor method assembleTest.

/**
 * <li>List all items
 * <li>Rewrite path
 * <li>Assemble qti.xml
 * <li>Write files at new path
 * @param fullItems
 * @param zout
 */
public void assembleTest(List<QuestionItemFull> fullItems, ZipOutputStream zout) {
    ItemsAndMaterials itemAndMaterials = new ItemsAndMaterials();
    for (QuestionItemFull fullItem : fullItems) {
        collectMaterials(fullItem, itemAndMaterials);
    }
    try {
        byte[] buffer = new byte[FileUtils.BSIZE];
        // write qti.xml
        Element sectionEl = createSectionBasedAssessment("Assessment");
        for (Element itemEl : itemAndMaterials.getItemEls()) {
            // generate new ident per item
            String ident = getAttributeValue(itemEl, "ident");
            String exportIdent = QTIEditHelper.generateNewIdent(ident);
            itemEl.addAttribute("ident", exportIdent);
            sectionEl.add(itemEl);
        }
        zout.putNextEntry(new ZipEntry("qti.xml"));
        XMLWriter xw = new XMLWriter(zout, new OutputFormat("  ", true));
        xw.write(sectionEl.getDocument());
        zout.closeEntry();
        // write materials
        for (ItemMaterial material : itemAndMaterials.getMaterials()) {
            String exportPath = material.getExportUri();
            zout.putNextEntry(new ZipEntry(exportPath));
            InputStream in = material.getLeaf().getInputStream();
            int c;
            while ((c = in.read(buffer, 0, buffer.length)) != -1) {
                zout.write(buffer, 0, c);
            }
            IOUtils.closeQuietly(in);
            zout.closeEntry();
        }
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) InputStream(java.io.InputStream) Element(org.dom4j.Element) ZipEntry(java.util.zip.ZipEntry) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) XMLWriter(org.dom4j.io.XMLWriter)

Example 19 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.

the class QTIQPoolServiceProvider method assembleTest.

public void assembleTest(List<QuestionItemShort> items, ZipOutputStream zout) {
    List<Long> itemKeys = new ArrayList<>();
    for (QuestionItemShort item : items) {
        itemKeys.add(item.getKey());
    }
    List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
    QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
    processor.assembleTest(fullItems, zout);
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Example 20 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.

the class ExportQItemsZipResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    String label = "ExportItems";
    String file = StringHelper.transformDisplayNameToFileSystemName(label) + ".zip";
    String encodedFileName = StringHelper.urlEncodeUTF8(file);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName);
    hres.setHeader("Content-Description", encodedFileName);
    try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
        zout.setLevel(9);
        Set<String> names = new HashSet<>();
        QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
        for (QuestionItemFull item : items) {
            qpoolService.exportItem(item, zout, locale, names);
        }
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolService(org.olat.modules.qpool.QPoolService) ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)44 File (java.io.File)18 QuestionItem (org.olat.modules.qpool.QuestionItem)18 Test (org.junit.Test)16 VFSItem (org.olat.core.util.vfs.VFSItem)16 IOException (java.io.IOException)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 URL (java.net.URL)12 InputStream (java.io.InputStream)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 ZipOutputStream (java.util.zip.ZipOutputStream)8 Document (org.dom4j.Document)8 Node (org.dom4j.Node)8 XMLParser (org.olat.core.util.xml.XMLParser)8 IMSEntityResolver (org.olat.ims.resources.IMSEntityResolver)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 URISyntaxException (java.net.URISyntaxException)6 ArrayList (java.util.ArrayList)6 ZipEntry (java.util.zip.ZipEntry)6 Element (org.dom4j.Element)6