use of org.olat.modules.qpool.QuestionType in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method processItemQuestionType.
private boolean processItemQuestionType(QuestionItemImpl poolItem, String ident, Element itemEl) {
boolean openolatFormat = false;
// question type: mc, sc...
QuestionType type = null;
// test with openolat ident
if (ident != null && ident.startsWith(ItemParser.ITEM_PREFIX_SCQ)) {
type = QuestionType.SC;
openolatFormat = true;
} else if (ident != null && ident.startsWith(ItemParser.ITEM_PREFIX_MCQ)) {
type = QuestionType.MC;
openolatFormat = true;
} else if (ident != null && ident.startsWith(ItemParser.ITEM_PREFIX_FIB)) {
type = QuestionType.FIB;
openolatFormat = true;
} else if (ident != null && ident.startsWith(ItemParser.ITEM_PREFIX_ESSAY)) {
type = QuestionType.ESSAY;
openolatFormat = true;
} else if (ident != null && ident.startsWith(ItemParser.ITEM_PREFIX_KPRIM)) {
type = QuestionType.KPRIM;
openolatFormat = true;
} else if (itemEl.selectNodes("//render_choice").size() == 1) {
Element lidEl = (Element) itemEl.selectSingleNode("//response_lid");
String rcardinality = getAttributeValue(lidEl, "rcardinality");
if ("Single".equals(rcardinality)) {
type = QuestionType.SC;
} else if ("Multiple".equals(rcardinality)) {
type = QuestionType.MC;
}
} else if (itemEl.selectNodes("//render_fib").size() == 1) {
type = QuestionType.FIB;
}
if (type != null) {
QItemType itemType = qItemTypeDao.loadByType(type.name());
poolItem.setType(itemType);
}
return openolatFormat;
}
use of org.olat.modules.qpool.QuestionType 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);
}
}
use of org.olat.modules.qpool.QuestionType in project openolat by klemens.
the class QItemTypeDAO method createDefaultTypes.
protected void createDefaultTypes() {
List<QItemType> types = getItemTypes();
Set<String> typeKeys = new HashSet<String>();
for (QItemType type : types) {
typeKeys.add(type.getType().toLowerCase());
}
for (QuestionType defaultType : QuestionType.values()) {
if (!typeKeys.contains(defaultType.name().toLowerCase())) {
create(defaultType.name(), false);
}
}
dbInstance.commitAndCloseSession();
}
use of org.olat.modules.qpool.QuestionType 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);
}
}
use of org.olat.modules.qpool.QuestionType in project OpenOLAT by OpenOLAT.
the class QItemTypeDAO method createDefaultTypes.
protected void createDefaultTypes() {
List<QItemType> types = getItemTypes();
Set<String> typeKeys = new HashSet<String>();
for (QItemType type : types) {
typeKeys.add(type.getType().toLowerCase());
}
for (QuestionType defaultType : QuestionType.values()) {
if (!typeKeys.contains(defaultType.name().toLowerCase())) {
create(defaultType.name(), false);
}
}
dbInstance.commitAndCloseSession();
}
Aggregations