Search in sources :

Example 36 with QuestionItemView

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

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 37 with QuestionItemView

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

the class QItemQueriesDAOTest method getItemsOfPool.

@Test
public void getItemsOfPool() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool
    String poolTitle = "NGC-" + UUID.randomUUID().toString();
    Pool pool = poolDao.createPool(null, poolTitle, true);
    QuestionItem item = questionItemDao.createAndPersist(id, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    poolDao.addItemToPool(item, Collections.singletonList(pool), false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setPoolKey(pool.getKey());
    // retrieve
    List<QuestionItemView> items = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
    Assert.assertNotNull(items);
    Assert.assertEquals(1, items.size());
    Assert.assertTrue(items.get(0).getKey().equals(item.getKey()));
    // count
    int numOfItems = poolDao.countItemsInPool(params);
    Assert.assertEquals(1, numOfItems);
}
Also used : 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) Test(org.junit.Test)

Example 38 with QuestionItemView

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

the class QItemQueriesDAOTest method getItemsByAuthor.

@Test
public void getItemsByAuthor() {
    // 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();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setAuthor(id);
    // count the items of the author
    int numOfItems = questionDao.countItems(id);
    Assert.assertEquals(2, numOfItems);
    // retrieve the items of the author
    List<QuestionItemView> items = qItemQueriesDao.getItemsByAuthor(params, null, 0, -1);
    List<Long> itemKeys = new ArrayList<>();
    for (QuestionItemView item : items) {
        itemKeys.add(item.getKey());
    }
    Assert.assertNotNull(items);
    Assert.assertEquals(2, items.size());
    Assert.assertTrue(itemKeys.contains(item1.getKey()));
    Assert.assertTrue(itemKeys.contains(item2.getKey()));
    // check the count
    int count = qItemQueriesDao.countItemsByAuthor(params);
    Assert.assertEquals(2, count);
    // limit the list
    List<QuestionItemView> limitedItems = qItemQueriesDao.getItemsByAuthor(params, Collections.singletonList(item1.getKey()), 0, -1);
    Assert.assertNotNull(limitedItems);
    Assert.assertEquals(1, limitedItems.size());
    Assert.assertEquals(item1.getKey(), limitedItems.get(0).getKey());
}
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 39 with QuestionItemView

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByQuestionStatus.

@Test
public void shouldGetItemsFilteredByQuestionStatus() {
    QuestionStatus status = QuestionStatus.revised;
    QuestionItemImpl item11 = createRandomItem(createRandomIdentity());
    item11.setQuestionStatus(status);
    QuestionItemImpl item12 = createRandomItem(createRandomIdentity());
    item12.setQuestionStatus(status);
    QuestionItem item21 = createRandomItem(createRandomIdentity());
    QuestionItem item22 = createRandomItem(createRandomIdentity());
    QuestionItem item23 = createRandomItem(createRandomIdentity());
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setQuestionStatus(status);
    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 : QuestionStatus(org.olat.modules.qpool.QuestionStatus) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 40 with QuestionItemView

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByOnlyAuthor.

@Test
public void shouldGetItemsFilteredByOnlyAuthor() {
    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.setOnlyAuthor(owner1);
    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)

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