use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class CollectionListController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
List<QuestionItemCollection> colls = qpoolService.getCollections(getIdentity());
// add the table
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("collection.name", 0));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("collection.creationDate", 1));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("select", translate("select"), "select-coll"));
model = new CollectionsDataModel(colls, columnsModel);
collectionsTable = uifactory.addTableElement(getWindowControl(), "collections", model, getTranslator(), formLayout);
collectionsTable.setMultiSelect(true);
collectionsTable.setRendererType(FlexiTableRendererType.classic);
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsCont.setRootForm(mainForm);
formLayout.add(buttonsCont);
selectButton = uifactory.addFormLink("select", buttonsCont, Link.BUTTON);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class CollectionDAO method addItemToCollection.
/**
* Add an item to a collection
* @param itemKey
* @param collection
* @return true if the item is in the collection after the call
*/
public boolean addItemToCollection(QuestionItemShort item, List<QuestionItemCollection> collections) {
QuestionItemImpl lockedItem = questionItemDao.loadForUpdate(item);
if (lockedItem == null) {
return false;
}
Set<QuestionItemCollection> uniqueCollections = new HashSet<>(collections);
for (QuestionItemCollection collection : uniqueCollections) {
if (!isInCollection(collection, lockedItem)) {
CollectionToItem coll2Item = new CollectionToItem();
coll2Item.setCreationDate(new Date());
coll2Item.setCollection(collection);
coll2Item.setItem(lockedItem);
dbInstance.getCurrentEntityManager().persist(coll2Item);
}
}
dbInstance.commit();
return true;
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method getItemsOfCollection.
@Test
public void getItemsOfCollection() {
// create a collection with 2 items
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-3-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 3", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, qItemType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 97", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, qItemType);
collectionDao.addItemToCollection(item1, singletonList(coll));
collectionDao.addItemToCollection(item2, singletonList(coll));
// check if it's alright
dbInstance.commit();
// load the items of the collection
List<QuestionItemView> items = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1);
List<Long> itemKeys = new ArrayList<>();
for (QuestionItemView item : items) {
itemKeys.add(item.getKey());
}
Assert.assertNotNull(items);
Assert.assertEquals(2, items.size());
Assert.assertTrue(itemKeys.contains(item1.getKey()));
Assert.assertTrue(itemKeys.contains(item2.getKey()));
// count them
int numOfItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(2, numOfItems);
// load limit sub set
List<QuestionItemView> limitedItems = qItemQueriesDao.getItemsOfCollection(id, coll, Collections.singletonList(item1.getKey()), null, 0, -1);
Assert.assertNotNull(limitedItems);
Assert.assertEquals(1, limitedItems.size());
Assert.assertEquals(item1.getKey(), limitedItems.get(0).getKey());
}
use of org.olat.modules.qpool.QuestionItemCollection 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.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class CollectionDAOTest method removeFromCollection_paranoid.
@Test
public void removeFromCollection_paranoid() {
// create 2 collections with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
QuestionItemCollection coll1 = collectionDao.createCollection("NGC collection 8", id);
QuestionItemCollection coll2 = collectionDao.createCollection("NGC collection 9", 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", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll1));
collectionDao.addItemToCollection(item1, singletonList(coll2));
collectionDao.addItemToCollection(item2, singletonList(coll1));
collectionDao.addItemToCollection(item2, singletonList(coll2));
dbInstance.commit();
// check if it's alright
int numOfItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfItems_1);
int numOfItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(2, numOfItems_2);
// remove
collectionDao.removeItemFromCollection(Collections.<QuestionItemShort>singletonList(item1), coll2);
dbInstance.commitAndCloseSession();
// check if the item has been removed
int numOfStayingItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfStayingItems_1);
int numOfStayingItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(1, numOfStayingItems_2);
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll2, null, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
Aggregations