Search in sources :

Example 56 with QItemType

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);
    }
}
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 57 with QItemType

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

Example 58 with QItemType

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

Example 59 with QItemType

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

Example 60 with QItemType

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

Aggregations

QItemType (org.olat.modules.qpool.model.QItemType)118 Test (org.junit.Test)94 QuestionItem (org.olat.modules.qpool.QuestionItem)82 Identity (org.olat.core.id.Identity)58 BusinessGroup (org.olat.group.BusinessGroup)22 QuestionItemView (org.olat.modules.qpool.QuestionItemView)18 Pool (org.olat.modules.qpool.Pool)12 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)12 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)12 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 HttpResponse (org.apache.http.HttpResponse)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)8 QEducationalContext (org.olat.modules.qpool.model.QEducationalContext)8 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)8 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionType (org.olat.modules.qpool.QuestionType)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 InputStream (java.io.InputStream)4