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