Search in sources :

Example 51 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QuestionPoolUserDataDeletable method deleteUserData.

@Override
public void deleteUserData(Identity identity, String newDeletedUserName, File archivePath) {
    if (!qpoolModule.isDeleteQuestionsWithoutAuthor())
        return;
    List<QuestionItem> itemsWithOneAuthor = questionItemDao.getItemsWithOneAuthor(identity);
    qpoolService.deleteItems(itemsWithOneAuthor);
    for (QuestionItem item : itemsWithOneAuthor) {
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(null, Action.DELETE_QUESTION_ITEM);
        builder.withBefore(item);
        builder.withMessage("Author deleted");
        qpoolService.persist(builder.create());
    }
    String logMessage = getLogMessage(identity, itemsWithOneAuthor);
    log.info(logMessage);
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 52 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QTIImportProcessorTest method testImport_QTI12_metadata.

@Test
public void testImport_QTI12_metadata() throws IOException, URISyntaxException {
    URL itemUrl = QTIImportProcessorTest.class.getResource("mchc_i_001.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(1, items.size());
    dbInstance.commitAndCloseSession();
    // check metadata
    QuestionItem item = items.get(0);
    Assert.assertEquals("Standard Multiple Choice Item", item.getTitle());
    // qmd_levelofdifficulty
    QEducationalContext level = item.getEducationalContext();
    Assert.assertNotNull(level);
    Assert.assertEquals("basic", level.getLevel());
    // qmd_toolvendor
    Assert.assertEquals("QTITools", item.getEditor());
}
Also used : QEducationalContext(org.olat.modules.qpool.model.QEducationalContext) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem) URL(java.net.URL) Test(org.junit.Test)

Example 53 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QTIImportProcessorTest method testImport_QTI12_multipleItems.

@Test
public void testImport_QTI12_multipleItems() throws IOException, URISyntaxException {
    URL itemsUrl = QTIImportProcessorTest.class.getResource("multiple_items.zip");
    Assert.assertNotNull(itemsUrl);
    File itemFile = new File(itemsUrl.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 ("Export (blue)".equals(itemFull.getTitle())) {
            Assert.assertTrue(exists(itemFull, "media/blue.png"));
            Assert.assertFalse(exists(itemFull, "media/purple.png"));
        } else if ("Export (purple)".equals(itemFull.getTitle())) {
            Assert.assertFalse(exists(itemFull, "media/blue.png"));
            Assert.assertTrue(exists(itemFull, "media/purple.png"));
        } else {
            Assert.fail();
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) Node(org.dom4j.Node) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) URL(java.net.URL) 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 54 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QTIImportProcessorTest method testImport_QTI12_sidecarMetadata.

@Test
public void testImport_QTI12_sidecarMetadata() throws IOException, URISyntaxException {
    URL itemUrl = QTIImportProcessorTest.class.getResource("qitem_metadatas.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(1, items.size());
    dbInstance.commitAndCloseSession();
    // reload and check metadata
    QuestionItem item = questionItemDao.loadById(items.get(0).getKey());
    Assert.assertEquals("Une information en plus", item.getAdditionalInformations());
    Assert.assertEquals("formative", item.getAssessmentType());
    Assert.assertEquals("large", item.getCoverage());
    Assert.assertEquals(0, new BigDecimal("-0.1").compareTo(item.getDifferentiation()));
    Assert.assertEquals(0, new BigDecimal("0.45").compareTo(item.getDifficulty()));
    Assert.assertEquals("OpenOLAT", item.getEditor());
    Assert.assertEquals("9.4", item.getEditorVersion());
    QEducationalContext level = item.getEducationalContext();
    Assert.assertNotNull(level);
    Assert.assertEquals("University", level.getLevel());
    Assert.assertEquals("P5DT4H3M2S", item.getEducationalLearningTime());
    Assert.assertEquals("IMS QTI 1.2", item.getFormat());
    Assert.assertEquals("6bae65ac-f333-40ba-bdd0-13b54d016d59", item.getMasterIdentifier());
    Assert.assertFalse("6bae65ac-f333-40ba-bdd0-13b54d016d59".equals(item.getIdentifier()));
    Assert.assertEquals("sc", item.getItemType());
    Assert.assertEquals("1.01", item.getItemVersion());
    Assert.assertEquals("question export import Pluton", item.getKeywords());
    Assert.assertEquals("de", item.getLanguage());
    Assert.assertEquals(1, item.getNumOfAnswerAlternatives());
    Assert.assertNotNull(item.getQuestionStatus());
    Assert.assertEquals("review", item.getQuestionStatus().name());
    Assert.assertEquals(0, new BigDecimal("0.56").compareTo(item.getStdevDifficulty()));
    Assert.assertEquals("/Physique/Astronomie/Astrophysique/", item.getTaxonomicPath());
    Assert.assertEquals("Une question sur Pluton", item.getTitle());
    Assert.assertEquals(0, item.getUsage());
}
Also used : QEducationalContext(org.olat.modules.qpool.model.QEducationalContext) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem) URL(java.net.URL) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 55 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class CollectionDAOTest method addItemToCollectionById.

@Test
public void addItemToCollectionById() {
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-2-" + UUID.randomUUID().toString());
    QuestionItemCollection coll = collectionDao.createCollection("NGC collection 2", id);
    QuestionItem item = questionDao.createAndPersist(null, "NGC 89", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    dbInstance.commitAndCloseSession();
    // add the item to the collection
    collectionDao.addItemToCollection(item, singletonList(coll));
    // check if it's alright
    dbInstance.commit();
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Aggregations

QuestionItem (org.olat.modules.qpool.QuestionItem)260 Test (org.junit.Test)160 Identity (org.olat.core.id.Identity)122 QItemType (org.olat.modules.qpool.model.QItemType)82 QuestionItemView (org.olat.modules.qpool.QuestionItemView)76 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)54 ArrayList (java.util.ArrayList)42 File (java.io.File)32 BusinessGroup (org.olat.group.BusinessGroup)32 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)32 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)30 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)28 URL (java.net.URL)24 Pool (org.olat.modules.qpool.Pool)20 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)16 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)16 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12