Search in sources :

Example 1 with QuestionItemFull

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

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

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

the class QTIQPoolServiceProvider method exportToEditorPackage.

public void exportToEditorPackage(QTIEditorPackageImpl editorPackage, List<QuestionItemShort> items, boolean newTest) {
    VFSContainer editorContainer = editorPackage.getBaseDir();
    List<Long> itemKeys = toKeys(items);
    List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
    Section section = editorPackage.getQTIDocument().getAssessment().getSections().get(0);
    if (newTest) {
        // remove autogenerated question
        section.getItems().clear();
    }
    QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
    for (QuestionItemFull fullItem : fullItems) {
        Element itemEl = processor.exportToQTIEditor(fullItem, editorContainer);
        Item item = (Item) new ParserManager().parse(itemEl);
        item.setIdent(QTIEditHelper.generateNewIdent(item.getIdent()));
        section.getItems().add(item);
    }
}
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) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 3 with QuestionItemFull

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

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

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

the class QTIImportProcessorTest method testImport_SC.

/**
 * This test check every methods of the import process in details
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void testImport_SC() throws IOException, URISyntaxException {
    URL itemUrl = QTIImportProcessorTest.class.getResource("mchc_i_002.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<DocInfos> docInfoList = proc.getDocInfos();
    Assert.assertNotNull(docInfoList);
    Assert.assertEquals(1, docInfoList.size());
    DocInfos docInfos = docInfoList.get(0);
    Assert.assertNotNull(docInfos);
    Assert.assertNotNull(docInfos.getFilename());
    Assert.assertNotNull(docInfos.getDocument());
    Assert.assertEquals("mchc_i_002.xml", docInfos.getFilename());
    // get the question DOM's
    List<ItemInfos> itemInfos = proc.getItemList(docInfos);
    Assert.assertNotNull(itemInfos);
    Assert.assertEquals(1, itemInfos.size());
    // process item, files...
    QuestionItemImpl item = proc.processItem(docInfos, itemInfos.get(0), null);
    Assert.assertNotNull(item);
    dbInstance.commitAndCloseSession();
    proc.processFiles(item, itemInfos.get(0), null);
    // reload and check what is saved
    QuestionItemFull reloadItem = questionItemDao.loadById(item.getKey());
    Assert.assertNotNull(reloadItem);
    Assert.assertNotNull(reloadItem.getCreationDate());
    Assert.assertNotNull(reloadItem.getLastModified());
    Assert.assertEquals(QuestionStatus.draft, reloadItem.getQuestionStatus());
    Assert.assertEquals(QTIConstants.QTI_12_FORMAT, reloadItem.getFormat());
    // title
    Assert.assertEquals("Standard Multiple Choice with Images Item", reloadItem.getTitle());
    // description -> qticomment
    Assert.assertEquals("This is a multiple-choice example with image content. The rendering is a standard radio button style. No response processing is incorporated.", reloadItem.getDescription());
    // question type
    Assert.assertNotNull(reloadItem.getType());
    Assert.assertEquals(QuestionType.SC.name().toLowerCase(), reloadItem.getType().getType());
    // check that the file is storead
    VFSContainer itemDir = qpoolFileStorage.getContainer(reloadItem.getDirectory());
    Assert.assertNotNull(itemDir);
    VFSItem qtiLeaf = itemDir.resolve(reloadItem.getRootFilename());
    Assert.assertNotNull(qtiLeaf);
    Assert.assertTrue(qtiLeaf instanceof VFSLeaf);
    Assert.assertTrue(qtiLeaf.exists());
    Assert.assertEquals(itemFile.length(), ((VFSLeaf) qtiLeaf).getSize());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) DocInfos(org.olat.ims.qti.qpool.QTIImportProcessor.DocInfos) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) ItemInfos(org.olat.ims.qti.qpool.QTIImportProcessor.ItemInfos) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 5 with QuestionItemFull

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

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)

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