use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
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;
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class QuestionItemIndexer method fullIndex.
@Override
public void fullIndex(LifeFullIndexer indexWriter) {
QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
QuestionItemDocumentFactory docFactory = CoreSpringFactory.getImpl(QuestionItemDocumentFactory.class);
SearchResourceContext ctxt = new SearchResourceContext();
IndexWriter writer = null;
try {
writer = indexWriter.getAndLockWriter();
int counter = 0;
List<QuestionItemFull> items;
do {
items = qpoolService.getAllItems(counter, BATCH_SIZE);
for (QuestionItemFull item : items) {
Document doc = docFactory.createDocument(ctxt, item);
indexWriter.addDocument(doc, writer);
}
counter += items.size();
} while (items.size() == BATCH_SIZE);
} catch (Exception e) {
log.error("", e);
} finally {
indexWriter.releaseWriter(writer);
}
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class QTIImportProcessorTest method testImport_QTI12_processAttachments_matimg.
@Test
public void testImport_QTI12_processAttachments_matimg() throws IOException, URISyntaxException {
URL itemUrl = QTIImportProcessorTest.class.getResource("mchc_asmimr_106.zip");
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(3, 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 ("Rivers in Germany".equals(itemFull.getTitle())) {
Assert.assertFalse(exists(itemFull, "image1.gif"));
Assert.assertFalse(exists(itemFull, "image2.gif"));
Assert.assertFalse(exists(itemFull, "image3.gif"));
Assert.assertTrue(exists(itemFull, "images/image02.jpg"));
} else if ("Capital of France".equals(itemFull.getTitle())) {
Assert.assertTrue(exists(itemFull, "image1.gif"));
Assert.assertTrue(exists(itemFull, "image2.gif"));
Assert.assertFalse(exists(itemFull, "image3.gif"));
Assert.assertFalse(exists(itemFull, "images/image02.jpg"));
} else if ("Rivers in France question".equals(itemFull.getTitle())) {
Assert.assertFalse(exists(itemFull, "image1.gif"));
Assert.assertTrue(exists(itemFull, "image2.gif"));
Assert.assertTrue(exists(itemFull, "image3.gif"));
Assert.assertFalse(exists(itemFull, "images/image02.jpg"));
} else {
Assert.fail();
}
}
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
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());
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class QTIImportProcessorTest method testImport_OpenOLATTest_processAttachments_mattext.
@Test
public void testImport_OpenOLATTest_processAttachments_mattext() throws IOException, URISyntaxException {
URL itemUrl = QTIImportProcessorTest.class.getResource("oo_test_qti_attachments.zip");
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(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 (itemFull.getType().getType().equalsIgnoreCase(QuestionType.SC.name())) {
Assert.assertTrue(exists(itemFull, "media/image1.gif"));
Assert.assertTrue(exists(itemFull, "media/image2.gif"));
Assert.assertFalse(exists(itemFull, "media/image3.gif"));
} else if (itemFull.getType().getType().equalsIgnoreCase(QuestionType.MC.name())) {
Assert.assertFalse(exists(itemFull, "media/image1.gif"));
Assert.assertTrue(exists(itemFull, "media/image2.gif"));
Assert.assertTrue(exists(itemFull, "media/image3.gif"));
} else {
Assert.fail();
}
}
}
Aggregations