use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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();
}
}
}
use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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);
}
}
Aggregations