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());
}
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);
}
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;
}
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;
}
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()));
}
Aggregations