Search in sources :

Example 21 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

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 22 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

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 23 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAOTest method shouldGetItemsIsRater.

@Test
public void shouldGetItemsIsRater() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    QuestionItem item12 = createRandomItem(owner1);
    commentAndRatingService.createRating(owner1, item11, null, 2);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isRater()).isTrue();
    assertThat(filterByKey(loadedItems, item12).isRater()).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 24 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

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 25 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

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)

Aggregations

QuestionItem (org.olat.modules.qpool.QuestionItem)260 Test (org.junit.Test)160 Identity (org.olat.core.id.Identity)122 QItemType (org.olat.modules.qpool.model.QItemType)82 QuestionItemView (org.olat.modules.qpool.QuestionItemView)76 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)54 ArrayList (java.util.ArrayList)42 File (java.io.File)32 BusinessGroup (org.olat.group.BusinessGroup)32 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)32 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)30 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)28 URL (java.net.URL)24 Pool (org.olat.modules.qpool.Pool)20 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)16 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)16 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12