Search in sources :

Example 36 with SearchQuestionItemParams

use of org.olat.modules.qpool.model.SearchQuestionItemParams in project openolat by klemens.

the class PoolDAOTest method removeItemFromPool_paranoid.

@Test
public void removeItemFromPool_paranoid() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool
    String name1 = "NGC-" + UUID.randomUUID().toString();
    Pool pool1 = poolDao.createPool(null, name1, true);
    String name2 = "NGC-" + UUID.randomUUID().toString();
    Pool pool2 = poolDao.createPool(null, name2, true);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item1 = questionItemDao.createAndPersist(id, "Cluster of stars", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionItemDao.createAndPersist(id, "Nebula", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    poolDao.addItemToPool(item1, Collections.singletonList(pool1), false);
    poolDao.addItemToPool(item1, Collections.singletonList(pool2), false);
    poolDao.addItemToPool(item2, Collections.singletonList(pool1), false);
    poolDao.addItemToPool(item2, Collections.singletonList(pool2), false);
    dbInstance.commit();
    SearchQuestionItemParams params1 = new SearchQuestionItemParams(id, null);
    params1.setPoolKey(pool1.getKey());
    SearchQuestionItemParams params2 = new SearchQuestionItemParams(id, null);
    params2.setPoolKey(pool2.getKey());
    // check
    int numOfItems_1 = poolDao.countItemsInPool(params1);
    Assert.assertEquals(2, numOfItems_1);
    int numOfItems_2 = poolDao.countItemsInPool(params2);
    Assert.assertEquals(2, numOfItems_2);
    // remove
    poolDao.removeFromPool(Collections.<QuestionItemShort>singletonList(item1), pool2);
    dbInstance.commit();
    // check empty pool
    int numOfStayingItems_1 = poolDao.countItemsInPool(params1);
    Assert.assertEquals(2, numOfStayingItems_1);
    int numOfStayingItems_2 = poolDao.countItemsInPool(params2);
    Assert.assertEquals(1, numOfStayingItems_2);
    // check content
    List<QuestionItemView> items_1 = qItemQueriesDao.getItemsOfPool(params1, null, 0, -1);
    Assert.assertEquals(2, items_1.size());
    List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfPool(params2, null, 0, -1);
    Assert.assertEquals(1, items_2.size());
    Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
    // but item exists
    QuestionItem reloadedItem = questionItemDao.loadById(item1.getKey());
    Assert.assertNotNull(reloadedItem);
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) 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) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 37 with SearchQuestionItemParams

use of org.olat.modules.qpool.model.SearchQuestionItemParams in project openolat by klemens.

the class CollectionOfItemsSource method getItems.

@Override
public ResultInfos<QuestionItemView> getItems(String query, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) {
    SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles);
    params.setSearchString(query);
    params.setCondQueries(condQueries);
    if (StringHelper.containsNonWhitespace(restrictToFormat)) {
        params.setFormat(restrictToFormat);
    }
    return qpoolService.getItemsOfCollection(collection, params, firstResult, maxResults, orderBy);
}
Also used : SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams)

Example 38 with SearchQuestionItemParams

use of org.olat.modules.qpool.model.SearchQuestionItemParams in project openolat by klemens.

the class CollectionOfItemsSource method getItems.

@Override
public List<QuestionItemView> getItems(Collection<Long> key) {
    SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles);
    params.setItemKeys(key);
    if (StringHelper.containsNonWhitespace(restrictToFormat)) {
        params.setFormat(restrictToFormat);
    }
    ResultInfos<QuestionItemView> items = qpoolService.getItemsOfCollection(collection, params, 0, -1);
    return items.getObjects();
}
Also used : SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 39 with SearchQuestionItemParams

use of org.olat.modules.qpool.model.SearchQuestionItemParams in project openolat by klemens.

the class DefaultItemsSource method getItems.

@Override
public List<QuestionItemView> getItems(Collection<Long> keys) {
    SearchQuestionItemParams params = defaultParams.clone();
    params.setItemKeys(keys);
    ResultInfos<QuestionItemView> items = qpoolService.getItems(params, 0, -1);
    return items.getObjects();
}
Also used : SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 40 with SearchQuestionItemParams

use of org.olat.modules.qpool.model.SearchQuestionItemParams in project openolat by klemens.

the class SharedItemsSource method getItems.

@Override
public ResultInfos<QuestionItemView> getItems(String query, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) {
    SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles);
    params.setSearchString(query);
    params.setCondQueries(condQueries);
    if (StringHelper.containsNonWhitespace(restrictToFormat)) {
        params.setFormat(restrictToFormat);
    }
    return qpoolService.getSharedItemByResource(group.getResource(), params, firstResult, maxResults, orderBy);
}
Also used : SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams)

Aggregations

SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)72 QuestionItemView (org.olat.modules.qpool.QuestionItemView)62 Test (org.junit.Test)60 QuestionItem (org.olat.modules.qpool.QuestionItem)54 Identity (org.olat.core.id.Identity)50 Pool (org.olat.modules.qpool.Pool)12 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 QItemType (org.olat.modules.qpool.model.QItemType)8 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)8 ArrayList (java.util.ArrayList)6 SortKey (org.olat.core.commons.persistence.SortKey)6 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)6 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)4 BusinessGroup (org.olat.group.BusinessGroup)2 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)2 QuestionStatus (org.olat.modules.qpool.QuestionStatus)2 OLATResource (org.olat.resource.OLATResource)2