Search in sources :

Example 51 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method shouldGetItemsNumberOfRating.

@Test
public void shouldGetItemsNumberOfRating() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    commentAndRatingService.createRating(createRandomIdentity(), item11, null, 2);
    commentAndRatingService.createRating(createRandomIdentity(), item11, null, 3);
    commentAndRatingService.createRating(createRandomIdentity(), item11, null, 4);
    commentAndRatingService.createRating(createRandomIdentity(), item11, null, 4);
    QuestionItem item12 = createRandomItem(owner1);
    commentAndRatingService.createRating(createRandomIdentity(), item12, null, 4);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).getNumberOfRatings()).isEqualTo(4);
}
Also used : 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 52 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByExcludeRater.

@Test
public void shouldGetItemsFilteredByExcludeRater() {
    QuestionItem item11 = createRandomItem(createRandomIdentity());
    QuestionItem item12 = createRandomItem(createRandomIdentity());
    QuestionItem item21 = createRandomItem(createRandomIdentity());
    QuestionItem item22 = createRandomItem(createRandomIdentity());
    QuestionItem item23 = createRandomItem(createRandomIdentity());
    Identity rater1 = createRandomIdentity();
    commentAndRatingService.createRating(createRandomIdentity(), item21, null, 2);
    commentAndRatingService.createRating(rater1, item21, null, 2);
    commentAndRatingService.createRating(rater1, item22, null, 2);
    commentAndRatingService.createRating(rater1, item23, null, 2);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setExcludeRated(rater1);
    ;
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(loadedItems).hasSize(2);
    assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item12)).doesNotContainAnyElementsOf(keysOf(item21, item22, item23));
    int countItems = qItemQueriesDao.countItems(params);
    assertThat(countItems).isEqualTo(2);
}
Also used : 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 53 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method shouldGetAllItemsByFormat.

@Test
public void shouldGetAllItemsByFormat() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = questionDao.createAndPersist(owner1, "QPool 1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    QuestionItem item12 = questionDao.createAndPersist(owner1, "QPool 2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    QuestionItem item13 = createRandomItem(owner1);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setFormat(QTIConstants.QTI_12_FORMAT);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(loadedItems).hasSize(2);
    assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item12)).doesNotContainAnyElementsOf(keysOf(item13));
}
Also used : 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 54 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method getFavoritItems_orderBy.

@Test
public void getFavoritItems_orderBy() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fav-item-" + UUID.randomUUID().toString());
    QuestionItem item1 = questionDao.createAndPersist(id, "NGC 55", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    QuestionItem item2 = questionDao.createAndPersist(id, "NGC 253", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    markManager.setMark(item1, id, null, "[QuestionItem:" + item1 + "]");
    markManager.setMark(item2, id, null, "[QuestionItem:" + item2 + "]");
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    // test order by
    for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
        SortKey sortAsc = new SortKey(order.name(), true);
        List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getFavoritItems(params, null, 0, -1, sortAsc);
        Assert.assertNotNull(ascOrderedItems);
        SortKey sortDesc = new SortKey(order.name(), false);
        List<QuestionItemView> descOrderedItems = qItemQueriesDao.getFavoritItems(params, null, 0, -1, sortDesc);
        Assert.assertNotNull(descOrderedItems);
    }
}
Also used : SortKey(org.olat.core.commons.persistence.SortKey) 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 55 with SearchQuestionItemParams

use of org.olat.modules.qpool.model.SearchQuestionItemParams 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)

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