Search in sources :

Example 16 with QuestionItemCollection

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());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)

Example 17 with QuestionItemCollection

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;
}
Also used : CollectionToItem(org.olat.modules.qpool.model.CollectionToItem) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Date(java.util.Date) HashSet(java.util.HashSet)

Example 18 with QuestionItemCollection

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());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 19 with QuestionItemCollection

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()));
}
Also used : ArrayList(java.util.ArrayList) QItemType(org.olat.modules.qpool.model.QItemType) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 20 with QuestionItemCollection

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

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