Search in sources :

Example 11 with QuestionItemFull

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

the class QTI21QPoolServiceProvider method loadQuestionFullItems.

private List<QuestionItemFull> loadQuestionFullItems(List<QuestionItemShort> items) {
    List<Long> itemKeys = toKeys(items);
    List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
    Map<Long, QuestionItemFull> fullItemMap = new HashMap<>();
    for (QuestionItemFull fullItem : fullItems) {
        fullItemMap.put(fullItem.getKey(), fullItem);
    }
    // reorder the fullItems;
    List<QuestionItemFull> reorderedFullItems = new ArrayList<>(fullItems.size());
    for (QuestionItemShort item : items) {
        QuestionItemFull itemFull = fullItemMap.get(item.getKey());
        if (itemFull != null) {
            reorderedFullItems.add(itemFull);
        }
    }
    return reorderedFullItems;
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) HashMap(java.util.HashMap) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Example 12 with QuestionItemFull

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

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 13 with QuestionItemFull

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

the class QTIImportProcessorTest method testImport_QTI12_multipleItems.

@Test
public void testImport_QTI12_multipleItems() throws IOException, URISyntaxException {
    URL itemsUrl = QTIImportProcessorTest.class.getResource("multiple_items.zip");
    Assert.assertNotNull(itemsUrl);
    File itemFile = new File(itemsUrl.toURI());
    // get the document informations
    QTIImportProcessor proc = new QTIImportProcessor(owner, Locale.ENGLISH, itemFile.getName(), itemFile);
    List<QuestionItem> items = proc.process();
    Assert.assertNotNull(items);
    Assert.assertEquals(2, items.size());
    dbInstance.commitAndCloseSession();
    // check the files
    for (QuestionItem item : items) {
        QuestionItemFull itemFull = (QuestionItemFull) item;
        String dir = itemFull.getDirectory();
        String file = itemFull.getRootFilename();
        VFSContainer itemContainer = qpoolFileStorage.getContainer(dir);
        Assert.assertNotNull(itemContainer);
        VFSItem itemLeaf = itemContainer.resolve(file);
        Assert.assertNotNull(itemLeaf);
        Assert.assertTrue(itemLeaf instanceof VFSLeaf);
        // try to parse it
        InputStream is = ((VFSLeaf) itemLeaf).getInputStream();
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        Document doc = xmlParser.parse(is, false);
        Node itemNode = doc.selectSingleNode("questestinterop/item");
        Assert.assertNotNull(itemNode);
        // check the attachments
        if ("Export (blue)".equals(itemFull.getTitle())) {
            Assert.assertTrue(exists(itemFull, "media/blue.png"));
            Assert.assertFalse(exists(itemFull, "media/purple.png"));
        } else if ("Export (purple)".equals(itemFull.getTitle())) {
            Assert.assertFalse(exists(itemFull, "media/blue.png"));
            Assert.assertTrue(exists(itemFull, "media/purple.png"));
        } else {
            Assert.fail();
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) Node(org.dom4j.Node) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) URL(java.net.URL) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) XMLParser(org.olat.core.util.xml.XMLParser) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 14 with QuestionItemFull

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

the class QTIImportProcessorTest method testImport_OpenOLATTest_process.

@Test
public void testImport_OpenOLATTest_process() throws IOException, URISyntaxException {
    URL itemUrl = QTIImportProcessorTest.class.getResource("oo_test_qti.xml");
    Assert.assertNotNull(itemUrl);
    File itemFile = new File(itemUrl.toURI());
    // get the document informations
    QTIImportProcessor proc = new QTIImportProcessor(owner, Locale.ENGLISH, itemFile.getName(), itemFile);
    List<QuestionItem> items = proc.process();
    Assert.assertNotNull(items);
    Assert.assertEquals(4, items.size());
    dbInstance.commitAndCloseSession();
    // check
    int sc = 0;
    int mc = 0;
    int kprim = 0;
    int fib = 0;
    for (QuestionItem item : items) {
        Assert.assertEquals(QTIConstants.QTI_12_FORMAT, item.getFormat());
        QItemType itemType = item.getType();
        Assert.assertNotNull(itemType);
        QuestionType type = QuestionType.valueOf(itemType.getType().toUpperCase());
        if (type != null) {
            switch(type) {
                case SC:
                    sc++;
                    break;
                case MC:
                    mc++;
                    break;
                case KPRIM:
                    kprim++;
                    break;
                case FIB:
                    fib++;
                    break;
                default:
                    {
                        Assert.fail("No question type");
                    }
            }
        }
    }
    Assert.assertEquals("1 single choice", 1, sc);
    Assert.assertEquals("1 multiple choice", 1, mc);
    Assert.assertEquals("1 krpim", 1, kprim);
    Assert.assertEquals("1 fill-in-blanck", 1, fib);
    // check the files
    for (QuestionItem item : items) {
        QuestionItemFull itemFull = (QuestionItemFull) item;
        String dir = itemFull.getDirectory();
        String file = itemFull.getRootFilename();
        VFSContainer itemContainer = qpoolFileStorage.getContainer(dir);
        Assert.assertNotNull(itemContainer);
        VFSItem itemLeaf = itemContainer.resolve(file);
        Assert.assertNotNull(itemLeaf);
        Assert.assertTrue(itemLeaf instanceof VFSLeaf);
        // try to parse it
        InputStream is = ((VFSLeaf) itemLeaf).getInputStream();
        XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
        Document doc = xmlParser.parse(is, false);
        Node itemNode = doc.selectSingleNode("questestinterop/item");
        Assert.assertNotNull(itemNode);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) Node(org.dom4j.Node) QuestionType(org.olat.modules.qpool.QuestionType) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) URL(java.net.URL) QItemType(org.olat.modules.qpool.model.QItemType) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) XMLParser(org.olat.core.util.xml.XMLParser) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 15 with QuestionItemFull

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

the class QTIExportProcessorTest method testImport_QTI12_metadata.

@Test
public void testImport_QTI12_metadata() throws IOException, URISyntaxException {
    // first import
    URL itemUrl = QTIExportProcessorTest.class.getResource("mchc_asmimr_106.zip");
    Assert.assertNotNull(itemUrl);
    File itemFile = new File(itemUrl.toURI());
    QTIImportProcessor proc = new QTIImportProcessor(owner, Locale.ENGLISH, itemFile.getName(), itemFile);
    List<QuestionItem> items = proc.process();
    Assert.assertNotNull(items);
    dbInstance.commitAndCloseSession();
    // after export
    QTIExportProcessor exportProc = new QTIExportProcessor(qpoolFileStorage);
    List<QuestionItemFull> fullItems = questionItemDao.loadByIds(Collections.singletonList(items.get(0).getKey()));
    OutputStream out = new ByteArrayOutputStream();
    ZipOutputStream zout = new ZipOutputStream(out);
    exportProc.assembleTest(fullItems, zout);
    IOUtils.closeQuietly(zout);
    IOUtils.closeQuietly(out);
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem) URL(java.net.URL) Test(org.junit.Test)

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