Search in sources :

Example 71 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAOTest method getSharedItemByResource.

@Test
public void getSharedItemByResource() {
    // create a group to share 2 items
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-2-" + UUID.randomUUID());
    BusinessGroup group1 = businessGroupDao.createAndPersist(id, "gdao-1", "gdao-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id, "gdao-2", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item = questionDao.createAndPersist(id, "Share-Item-3", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    dbInstance.commit();
    // share them
    List<OLATResource> resources = new ArrayList<>();
    resources.add(group1.getResource());
    resources.add(group2.getResource());
    questionDao.share(item, resources, false);
    // retrieve them
    List<QuestionItemView> sharedItems1 = qItemQueriesDao.getSharedItemByResource(id, group1.getResource(), null, null, 0, -1);
    Assert.assertNotNull(sharedItems1);
    Assert.assertEquals(1, sharedItems1.size());
    Assert.assertEquals(item.getKey(), sharedItems1.get(0).getKey());
    List<QuestionItemView> sharedItems2 = qItemQueriesDao.getSharedItemByResource(id, group2.getResource(), null, null, 0, -1);
    Assert.assertNotNull(sharedItems2);
    Assert.assertEquals(1, sharedItems2.size());
    Assert.assertEquals(item.getKey(), sharedItems2.get(0).getKey());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 72 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAOTest method getSharedItemByResource_orderBy.

@Test
public void getSharedItemByResource_orderBy() {
    // create a group to share 1 item
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-2-" + UUID.randomUUID());
    BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao-3", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item = questionDao.createAndPersist(id, "Share-Item-3", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    dbInstance.commit();
    // share them
    List<OLATResource> resources = new ArrayList<>();
    resources.add(group.getResource());
    questionDao.share(item, resources, false);
    dbInstance.commitAndCloseSession();
    // test order by
    for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
        SortKey sortAsc = new SortKey(order.name(), true);
        List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1, sortAsc);
        Assert.assertNotNull(ascOrderedItems);
        SortKey sortDesc = new SortKey(order.name(), false);
        List<QuestionItemView> descOrderedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1, sortDesc);
        Assert.assertNotNull(descOrderedItems);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) SortKey(org.olat.core.commons.persistence.SortKey) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 73 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAOTest method shouldGetItemsIsEditableInAShare.

@Test
public void shouldGetItemsIsEditableInAShare() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    QuestionItem item12 = createRandomItem(owner1);
    QuestionItem item13 = createRandomItem(owner1);
    BusinessGroup group = businessGroupDao.createAndPersist(owner1, "QPool", "QPool", -1, -1, false, false, false, false, false);
    List<OLATResource> groupResources = Arrays.asList(group.getResource());
    questionDao.share(item11, groupResources, true);
    questionDao.share(item12, groupResources, false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isEditableInShare()).isTrue();
    assertThat(filterByKey(loadedItems, item12).isEditableInShare()).isFalse();
    assertThat(filterByKey(loadedItems, item13).isEditableInShare()).isFalse();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) 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 74 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class ACFrontendManagerTest method makeAccessible.

@Test
public void makeAccessible() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("acc-" + UUID.randomUUID());
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    AccessMethod method = methods.get(0);
    RepositoryEntry re = createRepositoryEntry();
    Assert.assertNotNull(re);
    // create an offer to buy
    OLATResource randomOres = re.getOlatResource();
    Offer offer = acService.createOffer(randomOres, "Test auto access");
    offer.setAutoBooking(true);
    OfferAccess link = acService.createOfferAccess(offer, method);
    offer = acService.save(offer);
    acService.saveOfferAccess(link);
    dbInstance.commit();
    long start = System.nanoTime();
    AccessResult acResult = acService.isAccessible(re, id, false, true);
    Assert.assertNotNull(acResult);
    Assert.assertTrue(acResult.isAccessible());
    dbInstance.commit();
    CodeHelper.printNanoTime(start, "One click");
}
Also used : PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 75 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class ACOfferManagerTest method testFilter.

@Test
public void testFilter() {
    // create resources
    OLATResourceable testOreable1 = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres1 = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable1);
    assertNotNull(testOres1);
    OLATResourceable testOreable2 = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres2 = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable2);
    assertNotNull(testOres2);
    OLATResourceable testOreable3 = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres3 = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable3);
    assertNotNull(testOres3);
    dbInstance.commitAndCloseSession();
    // create  offers
    Offer offer1 = acOfferManager.createOffer(testOres1, "TestFilter 1");
    Offer offer2 = acOfferManager.createOffer(testOres2, "TestFilter 2");
    acOfferManager.saveOffer(offer1);
    acOfferManager.saveOffer(offer2);
    dbInstance.commitAndCloseSession();
    // filter by resources
    List<Long> resourceKeys = new ArrayList<Long>();
    resourceKeys.add(testOres1.getKey());
    resourceKeys.add(testOres2.getKey());
    resourceKeys.add(testOres3.getKey());
    Set<Long> filteredKeys = acOfferManager.filterResourceWithOffer(resourceKeys);
    assertNotNull(filteredKeys);
    assertEquals(2, filteredKeys.size());
    assertTrue(filteredKeys.contains(testOres1.getKey()));
    assertTrue(filteredKeys.contains(testOres2.getKey()));
    assertFalse(filteredKeys.contains(testOres3.getKey()));
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26