Search in sources :

Example 1 with QuestionType

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;
}
Also used : Element(org.dom4j.Element) QuestionType(org.olat.modules.qpool.QuestionType) QItemType(org.olat.modules.qpool.model.QItemType)

Example 2 with QuestionType

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) Node(org.dom4j.Node) QuestionType(org.olat.modules.qpool.QuestionType) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) URL(java.net.URL) QItemType(org.olat.modules.qpool.model.QItemType) 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)

Example 3 with QuestionType

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();
}
Also used : QuestionType(org.olat.modules.qpool.QuestionType) QItemType(org.olat.modules.qpool.model.QItemType) HashSet(java.util.HashSet)

Example 4 with QuestionType

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) Node(org.dom4j.Node) QuestionType(org.olat.modules.qpool.QuestionType) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) URL(java.net.URL) QItemType(org.olat.modules.qpool.model.QItemType) 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)

Example 5 with QuestionType

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();
}
Also used : QuestionType(org.olat.modules.qpool.QuestionType) QItemType(org.olat.modules.qpool.model.QItemType) HashSet(java.util.HashSet)

Aggregations

QuestionType (org.olat.modules.qpool.QuestionType)6 QItemType (org.olat.modules.qpool.model.QItemType)6 File (java.io.File)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 Node (org.dom4j.Node)2 Test (org.junit.Test)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 XMLParser (org.olat.core.util.xml.XMLParser)2 IMSEntityResolver (org.olat.ims.resources.IMSEntityResolver)2 QuestionItem (org.olat.modules.qpool.QuestionItem)2 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)2