Search in sources :

Example 36 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.

the class PoolDAO method removeFromPool.

public int removeFromPool(List<QuestionItemShort> items, Pool pool) {
    if (items == null || items.isEmpty())
        return 0;
    List<Long> keys = new ArrayList<Long>();
    for (QuestionItemShort item : items) {
        keys.add(item.getKey());
    }
    StringBuilder sb = new StringBuilder();
    sb.append("delete from qpool2item pool2item where pool2item.item.key in (:itemKeys) and pool2item.pool.key=:poolKey");
    return dbInstance.getCurrentEntityManager().createQuery(sb.toString()).setParameter("itemKeys", keys).setParameter("poolKey", pool.getKey()).executeUpdate();
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Example 37 with QuestionItemShort

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

the class TaxonomyLevelItemsSource method postImport.

@Override
public int postImport(List<QuestionItem> items, boolean editable) {
    if (items == null || items.isEmpty())
        return 0;
    for (QuestionItemShort item : items) {
        if (item instanceof QuestionItemImpl) {
            QuestionItemImpl itemImpl = (QuestionItemImpl) item;
            itemImpl.setTaxonomyLevel(taxonomyLevel);
        }
    }
    qpoolService.index(items);
    return items.size();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort)

Example 38 with QuestionItemShort

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

the class QuestionPoolServiceTest method deleteItems.

@Test
public void deleteItems() {
    // create a group to share 2 items
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-rm-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupDao.createAndPersist(id, "gdrm", "gdrm-desc", -1, -1, false, false, false, false, false);
    QuestionItem item1 = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    dbInstance.commit();
    // share them
    questionDao.share(item1, group.getResource());
    dbInstance.commitAndCloseSession();
    // delete the items
    List<QuestionItemShort> toDelete = new ArrayList<>();
    toDelete.add(item1);
    toDelete.add(item2);
    qpoolService.deleteItems(toDelete);
    // make sure that changes are committed
    dbInstance.commit();
    // check if they exists
    QuestionItem deletedItem1 = questionDao.loadById(item1.getKey());
    Assert.assertNull(deletedItem1);
    QuestionItem deletedItem2 = questionDao.loadById(item2.getKey());
    Assert.assertNull(deletedItem2);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 39 with QuestionItemShort

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

the class QuestionPoolServiceTest method createCollection.

@Test
public void createCollection() {
    // create an user with 2 items
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Owner-3-" + UUID.randomUUID().toString());
    QuestionItem item1 = questionDao.createAndPersist(id, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    QuestionItem item2 = questionDao.createAndPersist(id, "NGC 97", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    dbInstance.commit();
    // load the items of the collection
    List<QuestionItemShort> items = new ArrayList<>();
    items.add(item1);
    items.add(item2);
    QuestionItemCollection newColl = qpoolService.createCollection(id, "My private collection", items);
    Assert.assertNotNull(newColl);
    Assert.assertEquals("My private collection", newColl.getName());
    // check if it's alright
    dbInstance.commit();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    // retrieve the list of items in the collection
    int numOfItemsInCollection = qpoolService.countItemsOfCollection(newColl, params);
    Assert.assertEquals(2, numOfItemsInCollection);
    ResultInfos<QuestionItemView> itemsOfCollection = qpoolService.getItemsOfCollection(newColl, params, 0, -1);
    Assert.assertNotNull(itemsOfCollection);
    Assert.assertEquals(2, itemsOfCollection.getObjects().size());
    List<Long> itemKeys = new ArrayList<>();
    for (QuestionItemView item : itemsOfCollection.getObjects()) {
        itemKeys.add(item.getKey());
    }
    Assert.assertTrue(itemKeys.contains(item1.getKey()));
    Assert.assertTrue(itemKeys.contains(item2.getKey()));
}
Also used : ArrayList(java.util.ArrayList) QItemType(org.olat.modules.qpool.model.QItemType) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 40 with QuestionItemShort

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

the class PoolDAO method removeFromPools.

public int removeFromPools(List<? extends QuestionItemShort> items) {
    if (items == null || items.isEmpty())
        return 0;
    List<Long> keys = new ArrayList<>();
    for (QuestionItemShort item : items) {
        keys.add(item.getKey());
    }
    StringBuilder sb = new StringBuilder();
    sb.append("delete from qpool2item pool2item where pool2item.item.key in (:itemKeys)");
    return dbInstance.getCurrentEntityManager().createQuery(sb.toString()).setParameter("itemKeys", keys).executeUpdate();
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Aggregations

QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)76 ArrayList (java.util.ArrayList)52 QuestionItem (org.olat.modules.qpool.QuestionItem)28 Identity (org.olat.core.id.Identity)14 List (java.util.List)12 BusinessGroup (org.olat.group.BusinessGroup)12 Test (org.junit.Test)10 QPoolSPI (org.olat.modules.qpool.QPoolSPI)10 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 QItemType (org.olat.modules.qpool.model.QItemType)8 HashMap (java.util.HashMap)6 ExportFormatOptions (org.olat.modules.qpool.ExportFormatOptions)6 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)6 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionItemView (org.olat.modules.qpool.QuestionItemView)6 QItemList (org.olat.modules.qpool.model.QItemList)6 QItemEdited (org.olat.modules.qpool.ui.events.QItemEdited)6 QPoolEvent (org.olat.modules.qpool.ui.events.QPoolEvent)6 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)5 Path (javax.ws.rs.Path)4