Search in sources :

Example 26 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method getItems_all.

@Test
public void getItems_all() {
    // create an author with 2 items
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-all-" + UUID.randomUUID().toString());
    QuestionItem item = questionDao.createAndPersist(id, "NGC all", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
    dbInstance.commitAndCloseSession();
    // retrieve all items
    List<QuestionItemFull> items = questionDao.getAllItems(0, -1);
    Assert.assertNotNull(items);
    Assert.assertTrue(items.size() >= 1);
    Assert.assertTrue(items.contains(item));
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 27 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method export.

@Override
public MediaResource export(List<QuestionItemShort> items, ExportFormatOptions format, Locale locale) {
    MediaResource mr = null;
    if (DefaultExportFormat.ZIP_EXPORT_FORMAT.equals(format)) {
        List<Long> keys = toKeys(items);
        List<QuestionItemFull> fullItems = questionItemDao.loadByIds(keys);
        mr = new ExportQItemsZipResource("UTF-8", locale, fullItems);
    // make a zip with all items
    } else {
        QPoolSPI selectedSp = null;
        List<QPoolSPI> sps = qpoolModule.getQuestionPoolProviders();
        for (QPoolSPI sp : sps) {
            if (sp.getTestExportFormats().contains(format)) {
                selectedSp = sp;
                break;
            }
        }
        if (selectedSp != null) {
            mr = selectedSp.exportTest(items, format, locale);
        }
    }
    return mr;
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolSPI(org.olat.modules.qpool.QPoolSPI) MediaResource(org.olat.core.gui.media.MediaResource)

Example 28 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method exportItem.

@Override
public void exportItem(QuestionItemShort item, ZipOutputStream zout, Locale locale, Set<String> names) {
    QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
    if (provider == null) {
        log.error("Not found provider for this format: " + item.getFormat());
    } else {
        QuestionItemFull fullItem;
        if (item instanceof QuestionItemFull) {
            fullItem = (QuestionItemFull) item;
        } else {
            fullItem = questionItemDao.loadById(item.getKey());
        }
        provider.exportItem(fullItem, zout, locale, names);
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolSPI(org.olat.modules.qpool.QPoolSPI)

Example 29 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

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)

Example 30 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

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)

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