Search in sources :

Example 46 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method getItemsByAuthor_orderBy.

@Test
public void getItemsByAuthor_orderBy() {
    // create an author with 2 items
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-2-" + UUID.randomUUID().toString());
    QuestionItem item1 = questionDao.createAndPersist(id, "NGC 2171", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    QuestionItem item2 = questionDao.createAndPersist(id, "NGC 2172", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(item1);
    Assert.assertNotNull(item2);
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setAuthor(id);
    // test order by
    for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
        SortKey sortAsc = new SortKey(order.name(), true);
        List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getItemsByAuthor(params, null, 0, -1, sortAsc);
        Assert.assertNotNull(ascOrderedItems);
        SortKey sortDesc = new SortKey(order.name(), false);
        List<QuestionItemView> descOrderedItems = qItemQueriesDao.getItemsByAuthor(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 47 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByExcludAuthor.

@Test
public void shouldGetItemsFilteredByExcludAuthor() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    QuestionItem item12 = createRandomItem(owner1);
    QuestionItem item21 = createRandomItem(createRandomIdentity());
    QuestionItem item22 = createRandomItem(createRandomIdentity());
    QuestionItem item23 = createRandomItem(createRandomIdentity());
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setExcludeAuthor(owner1);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(loadedItems).hasSize(3);
    assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item21, item22, item23)).doesNotContainAnyElementsOf(keysOf(item11, item12));
    int countItems = qItemQueriesDao.countItems(params);
    assertThat(countItems).isEqualTo(3);
}
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 48 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method getFavoritItems.

@Test
public void getFavoritItems() {
    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);
    QuestionItem item3 = questionDao.createAndPersist(id, "NGC 292", 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);
    List<QuestionItemView> favorits = qItemQueriesDao.getFavoritItems(params, null, 0, -1);
    List<Long> favoritKeys = new ArrayList<>();
    for (QuestionItemView favorit : favorits) {
        favoritKeys.add(favorit.getKey());
    }
    Assert.assertNotNull(favorits);
    Assert.assertEquals(2, favorits.size());
    Assert.assertTrue(favoritKeys.contains(item1.getKey()));
    Assert.assertTrue(favoritKeys.contains(item2.getKey()));
    Assert.assertFalse(favoritKeys.contains(item3.getKey()));
    // limit to the first favorit
    List<QuestionItemView> limitedFavorits = qItemQueriesDao.getFavoritItems(params, Collections.singletonList(item1.getKey()), 0, -1);
    Assert.assertNotNull(limitedFavorits);
    Assert.assertEquals(1, limitedFavorits.size());
    Assert.assertEquals(item1.getKey(), limitedFavorits.get(0).getKey());
    // check the count
    int numOfFavorits = qItemQueriesDao.countFavoritItems(params);
    Assert.assertEquals(2, numOfFavorits);
}
Also used : ArrayList(java.util.ArrayList) 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 49 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByWithoutTaxonomyLevel.

@Test
public void shouldGetItemsFilteredByWithoutTaxonomyLevel() {
    Taxonomy taxonomy = taxonomyDao.createTaxonomy("QPool", "QPool", "", null);
    TaxonomyLevel taxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, null, null, taxonomy);
    TaxonomyLevel taxonomySubLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, taxonomyLevel, null, taxonomy);
    TaxonomyLevel otherTaxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, null, null, taxonomy);
    QuestionItemImpl item11 = createRandomItem(createRandomIdentity());
    item11.setTaxonomyLevel(taxonomyLevel);
    QuestionItemImpl item12 = createRandomItem(createRandomIdentity());
    item12.setTaxonomyLevel(taxonomySubLevel);
    QuestionItemImpl item21 = createRandomItem(createRandomIdentity());
    item21.setTaxonomyLevel(otherTaxonomyLevel);
    QuestionItem item22 = createRandomItem(createRandomIdentity());
    QuestionItem item23 = createRandomItem(createRandomIdentity());
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setWithoutTaxonomyLevelOnly(true);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(loadedItems).hasSize(2);
    assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item22, item23)).doesNotContainAnyElementsOf(keysOf(item11, item12, item21));
    int countItems = qItemQueriesDao.countItems(params);
    assertThat(countItems).isEqualTo(2);
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 50 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByLikeTaxonomyLevel.

@Test
public void shouldGetItemsFilteredByLikeTaxonomyLevel() {
    Taxonomy taxonomy = taxonomyDao.createTaxonomy("QPool", "QPool", "", null);
    TaxonomyLevel taxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, null, null, taxonomy);
    TaxonomyLevel taxonomySubLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, taxonomyLevel, null, taxonomy);
    TaxonomyLevel otherTaxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, null, null, taxonomy);
    QuestionItemImpl item11 = createRandomItem(createRandomIdentity());
    item11.setTaxonomyLevel(taxonomyLevel);
    QuestionItemImpl item12 = createRandomItem(createRandomIdentity());
    item12.setTaxonomyLevel(taxonomySubLevel);
    QuestionItemImpl item21 = createRandomItem(createRandomIdentity());
    item21.setTaxonomyLevel(otherTaxonomyLevel);
    QuestionItem item22 = createRandomItem(createRandomIdentity());
    QuestionItem item23 = createRandomItem(createRandomIdentity());
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setLikeTaxonomyLevel(taxonomyLevel);
    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 : Taxonomy(org.olat.modules.taxonomy.Taxonomy) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) 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