Search in sources :

Example 46 with QuestionItemView

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

the class QItemQueriesDAOTest method shouldGetItemsRating.

@Test
public void shouldGetItemsRating() {
    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);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).getRating()).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 47 with QuestionItemView

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

the class QItemQueriesDAOTest method shouldGetItemsIsAuthor.

@Test
public void shouldGetItemsIsAuthor() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    Identity owner2 = createRandomIdentity();
    QuestionItem item21 = createRandomItem(owner2);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isAuthor()).isTrue();
    assertThat(filterByKey(loadedItems, item21).isAuthor()).isFalse();
}
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 QuestionItemView

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

the class QItemQueriesDAOTest method shouldGetItemsIsTeacher.

@Test
public void shouldGetItemsIsTeacher() {
    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);
    Identity ownerAndTeacher = createRandomIdentity();
    taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.teach, taxonomyLevel, ownerAndTeacher, null);
    Identity teacher = createRandomIdentity();
    taxonomyCompetenceDao.createTaxonomyCompetence(TaxonomyCompetenceTypes.teach, taxonomyLevel, teacher, null);
    Identity noTeacher = createRandomIdentity();
    QuestionItemImpl item11 = createRandomItem(ownerAndTeacher);
    item11.setTaxonomyLevel(taxonomyLevel);
    QuestionItemImpl item12 = createRandomItem(ownerAndTeacher);
    item12.setTaxonomyLevel(taxonomySubLevel);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(ownerAndTeacher, null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isTeacher()).isTrue();
    assertThat(filterByKey(loadedItems, item12).isTeacher()).isTrue();
    params = new SearchQuestionItemParams(ownerAndTeacher, null);
    loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isTeacher()).isTrue();
    assertThat(filterByKey(loadedItems, item12).isTeacher()).isTrue();
    params = new SearchQuestionItemParams(noTeacher, null);
    loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isTeacher()).isFalse();
    assertThat(filterByKey(loadedItems, item12).isTeacher()).isFalse();
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) Test(org.junit.Test)

Example 49 with QuestionItemView

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

the class QItemQueriesDAOTest method getSharedItemByResource_subset.

@Test
public void getSharedItemByResource_subset() {
    // create a group to share 2 items
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-1-" + UUID.randomUUID());
    BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item1 = questionDao.createAndPersist(id, "Share-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    QuestionItem item2 = questionDao.createAndPersist(id, "Share-Item-2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    dbInstance.commit();
    // share them
    questionDao.share(item1, group.getResource());
    questionDao.share(item2, group.getResource());
    // retrieve them
    List<QuestionItemView> sharedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
    List<Long> sharedItemKeys = new ArrayList<>();
    for (QuestionItemView sharedItem : sharedItems) {
        sharedItemKeys.add(sharedItem.getKey());
    }
    Assert.assertNotNull(sharedItems);
    Assert.assertEquals(2, sharedItems.size());
    Assert.assertTrue(sharedItemKeys.contains(item1.getKey()));
    Assert.assertTrue(sharedItemKeys.contains(item2.getKey()));
    // retrieve limited sub set
    List<QuestionItemView> limitedSharedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), Collections.singletonList(item1.getKey()), null, 0, -1);
    Assert.assertNotNull(limitedSharedItems);
    Assert.assertEquals(1, limitedSharedItems.size());
    Assert.assertEquals(item1.getKey(), limitedSharedItems.get(0).getKey());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) 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 50 with QuestionItemView

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

the class QItemQueriesDAOTest method shouldGetItemsIsMarked.

@Test
public void shouldGetItemsIsMarked() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    QuestionItem item12 = createRandomItem(owner1);
    markManager.setMark(item11, owner1, null, "[QuestionItem:" + item11 + "]");
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isMarked()).isTrue();
    assertThat(filterByKey(loadedItems, item12).isMarked()).isFalse();
}
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)

Aggregations

QuestionItemView (org.olat.modules.qpool.QuestionItemView)118 Test (org.junit.Test)78 QuestionItem (org.olat.modules.qpool.QuestionItem)76 Identity (org.olat.core.id.Identity)72 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)62 ArrayList (java.util.ArrayList)34 QItemType (org.olat.modules.qpool.model.QItemType)18 BusinessGroup (org.olat.group.BusinessGroup)16 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)14 ItemWrapper (org.olat.modules.qpool.model.ItemWrapper)12 QItemViewEvent (org.olat.modules.qpool.ui.events.QItemViewEvent)12 SortKey (org.olat.core.commons.persistence.SortKey)10 MarkImpl (org.olat.core.commons.services.mark.impl.MarkImpl)10 Pool (org.olat.modules.qpool.Pool)10 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)10 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)8 SecurityGroupMembershipImpl (org.olat.basesecurity.SecurityGroupMembershipImpl)6 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)6 OLATResource (org.olat.resource.OLATResource)6