Search in sources :

Example 36 with QuestionItemCollection

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

the class QuestionPoolServiceImpl method createCollection.

@Override
public QuestionItemCollection createCollection(Identity owner, String collectionName, List<QuestionItemShort> initialItems) {
    QuestionItemCollection coll = collectionDao.createCollection(collectionName, owner);
    List<Long> keys = new ArrayList<>(initialItems.size());
    for (QuestionItemShort item : initialItems) {
        collectionDao.addItemToCollection(item, Collections.singletonList(coll));
        keys.add(item.getKey());
    }
    lifeIndexer.indexDocument(QItemDocument.TYPE, keys);
    return coll;
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Example 37 with QuestionItemCollection

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

the class CollectionDAO method deleteCollection.

public int deleteCollection(QuestionItemCollection collection) {
    StringBuilder sb = new StringBuilder();
    sb.append("delete from qcollection2item coll2item where coll2item.collection.key in (:collectionKey)");
    int count = dbInstance.getCurrentEntityManager().createQuery(sb.toString()).setParameter("collectionKey", collection.getKey()).executeUpdate();
    QuestionItemCollection coll = dbInstance.getCurrentEntityManager().getReference(ItemCollectionImpl.class, collection.getKey());
    dbInstance.getCurrentEntityManager().remove(coll);
    return 1 + count;
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection)

Example 38 with QuestionItemCollection

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

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)

Aggregations

QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)38 Test (org.junit.Test)20 Identity (org.olat.core.id.Identity)20 QuestionItem (org.olat.modules.qpool.QuestionItem)16 QItemType (org.olat.modules.qpool.model.QItemType)12 QuestionItemView (org.olat.modules.qpool.QuestionItemView)10 ArrayList (java.util.ArrayList)6 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 CollectionOfItemsSource (org.olat.modules.qpool.ui.datasource.CollectionOfItemsSource)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 SortKey (org.olat.core.commons.persistence.SortKey)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)2 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 BusinessGroup (org.olat.group.BusinessGroup)2 Pool (org.olat.modules.qpool.Pool)2 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)2