use of org.olat.modules.qpool.model.QItemType 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.model.QItemType in project openolat by klemens.
the class QTIImportProcessor method processMetadataField.
/**
* <ul>
* <li>qmd_computerscored</li>
* <li>qmd_feedbackpermitted</li>
* <li>qmd_hintspermitted</li>
* <li>qmd_itemtype -> (check is made on the content of the item)</li>
* <li>qmd_levelofdifficulty -> educational context</li>
* <li>qmd_maximumscore</li>
* <li>qmd_renderingtype</li>
* <li>qmd_responsetype</li>
* <li>qmd_scoringpermitted</li>
* <li>qmd_solutionspermitted</li>
* <li>qmd_status</li>
* <li>qmd_timedependence</li>
* <li>qmd_timelimit</li>
* <li>qmd_toolvendor -> editor</li>
* <li>qmd_topic</li>
* <li>qmd_material</li>
* <li>qmd_typeofsolution</li>
* <li>qmd_weighting</li>
* </ul>
* @param poolItem
* @param labelEl
* @param entryEl
*/
private void processMetadataField(QuestionItemImpl poolItem, Element labelEl, Element entryEl) {
String label = labelEl.getText();
String entry = entryEl.getText();
if (QTIConstants.META_LEVEL_OF_DIFFICULTY.equals(label)) {
if (StringHelper.containsNonWhitespace(entry)) {
QEducationalContext context = qEduContextDao.loadByLevel(entry);
if (context == null) {
context = qEduContextDao.create(entry, true);
}
poolItem.setEducationalContext(context);
}
} else if (QTIConstants.META_ITEM_TYPE.equals(label)) {
if (poolItem.getType() == null && StringHelper.containsNonWhitespace(entry)) {
// some heuristic
String typeStr = entry;
if (typeStr.equalsIgnoreCase("MCQ") || typeStr.equalsIgnoreCase("Multiple choice")) {
typeStr = QuestionType.MC.name();
} else if (typeStr.equalsIgnoreCase("SCQ") || typeStr.equalsIgnoreCase("Single choice")) {
typeStr = QuestionType.SC.name();
} else if (typeStr.equalsIgnoreCase("fill-in") || typeStr.equals("Fill-in-the-Blank") || typeStr.equalsIgnoreCase("Fill-in-Blank") || typeStr.equalsIgnoreCase("Fill In the Blank")) {
typeStr = QuestionType.FIB.name();
} else if (typeStr.equalsIgnoreCase("Essay")) {
typeStr = QuestionType.ESSAY.name();
}
QItemType type = qItemTypeDao.loadByType(entry);
if (type == null) {
type = qItemTypeDao.create(entry, true);
}
poolItem.setType(type);
}
} else if (QTIConstants.META_TOOLVENDOR.equals(label)) {
poolItem.setEditor(entry);
}
}
use of org.olat.modules.qpool.model.QItemType 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.model.QItemType in project openolat by klemens.
the class QItemTypeDAO method create.
public QItemType create(String type, boolean deletable) {
QItemType itemType = new QItemType();
itemType.setCreationDate(new Date());
itemType.setType(type.toLowerCase());
itemType.setDeletable(deletable);
dbInstance.getCurrentEntityManager().persist(itemType);
return itemType;
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class MetaUIFactory method getQItemTypeKeyValues.
public static KeyValues getQItemTypeKeyValues(Translator translator, QPoolService qpoolService) {
List<QItemType> types = qpoolService.getAllItemTypes();
String[] typeKeys = new String[types.size()];
String[] typeValues = new String[types.size()];
int count = 0;
for (QItemType type : types) {
typeKeys[count] = type.getType();
String translation = translator.translate("item.type." + type.getType().toLowerCase());
if (translation.length() > 128) {
typeValues[count] = typeKeys[count];
} else {
typeValues[count] = translation;
}
count++;
}
return new KeyValues(typeKeys, typeValues);
}
Aggregations