Search in sources :

Example 31 with SearchQuestionItemParams

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

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

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

Example 34 with SearchQuestionItemParams

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByWithoutAuthor.

@Test
public void shouldGetItemsFilteredByWithoutAuthor() {
    QuestionItem item11 = createRandomItem(null);
    QuestionItem item12 = createRandomItem(createRandomIdentity());
    QuestionItem item21 = createRandomItem(null);
    QuestionItem item22 = createRandomItem(createRandomIdentity());
    QuestionItem item23 = createRandomItem(createRandomIdentity());
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setWithoutAuthorOnly(true);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(loadedItems).hasSize(2);
    assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item21)).doesNotContainAnyElementsOf(keysOf(item12, item22, item23));
    int countItems = qItemQueriesDao.countItems(params);
    assertThat(countItems).isEqualTo(2);
}
Also used : SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 35 with SearchQuestionItemParams

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

the class PoolDAOTest method removeItemFromPools.

@Test
public void removeItemFromPools() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool with an item
    String poolName = "NGC-" + UUID.randomUUID().toString();
    Pool pool = poolDao.createPool(null, poolName, true);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item = questionItemDao.createAndPersist(id, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    poolDao.addItemToPool(item, Collections.singletonList(pool), false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setPoolKey(pool.getKey());
    // check the pool and remove the items
    List<QuestionItemView> items = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
    Assert.assertEquals(1, items.size());
    List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(items.get(0));
    int count = poolDao.removeFromPools(toDelete);
    Assert.assertEquals(1, count);
    dbInstance.commitAndCloseSession();
    // check if the pool is empty
    List<QuestionItemView> emptyItems = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
    Assert.assertTrue(emptyItems.isEmpty());
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) 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)

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