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