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());
}
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);
}
}
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();
}
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");
}
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()));
}
Aggregations