Search in sources :

Example 21 with QuestionItemCollection

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

the class CollectionDAOTest method removeFromCollections.

@Test
public void removeFromCollections() {
    // create a collection with 2 items
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
    QuestionItemCollection coll = collectionDao.createCollection("NGC collection 10", id);
    QuestionItem item1 = questionDao.createAndPersist(null, "NGC 107", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    QuestionItem item2 = questionDao.createAndPersist(null, "NGC 108", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    collectionDao.addItemToCollection(item1, singletonList(coll));
    collectionDao.addItemToCollection(item2, singletonList(coll));
    dbInstance.commit();
    // check if it's alright
    int numOfItems = collectionDao.countItemsOfCollection(coll, null);
    Assert.assertEquals(2, numOfItems);
    // remove
    collectionDao.deleteItemFromCollections(Collections.<QuestionItemShort>singletonList(item1));
    dbInstance.commitAndCloseSession();
    // check if the item has been removed
    int numOfStayingItems = collectionDao.countItemsOfCollection(coll, null);
    Assert.assertEquals(1, numOfStayingItems);
    List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1);
    Assert.assertEquals(1, items_2.size());
    Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 22 with QuestionItemCollection

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

the class CollectionDAOTest method countItemsOfCollection.

@Test
public void countItemsOfCollection() {
    // create 2 collections with 2 items
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
    QuestionItemCollection coll = collectionDao.createCollection("NGC collection 8", id);
    QuestionItem item1 = questionDao.createAndPersist(null, "NGC 103", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    QuestionItem item2 = questionDao.createAndPersist(null, "NGC 104", QTI21Constants.QTI_21_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    collectionDao.addItemToCollection(item1, singletonList(coll));
    collectionDao.addItemToCollection(item2, singletonList(coll));
    dbInstance.commit();
    // check if it's alright
    int numOfItems = collectionDao.countItemsOfCollection(coll, null);
    Assert.assertEquals(2, numOfItems);
    int numOfItems_21 = collectionDao.countItemsOfCollection(coll, QTI21Constants.QTI_21_FORMAT);
    Assert.assertEquals(1, numOfItems_21);
}
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)

Example 23 with QuestionItemCollection

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

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 24 with QuestionItemCollection

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

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 25 with QuestionItemCollection

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

the class QuestionListController method doCreateCollection.

private void doCreateCollection(UserRequest ureq, String name, List<QuestionItemShort> items) {
    QuestionItemCollection coll = qpoolService.createCollection(getIdentity(), name, items);
    fireEvent(ureq, new QPoolEvent(QPoolEvent.COLL_CREATED, coll.getKey()));
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QPoolEvent(org.olat.modules.qpool.ui.events.QPoolEvent)

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