use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method deleteSynchedBinder.
@Test
public void deleteSynchedBinder() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-12");
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-13");
RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
dbInstance.commitAndCloseSession();
// get section
Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
dbInstance.commit();
// make 2 assignments
Section templateSection = portfolioService.getSection(sectionRef);
Assignment assignment_1 = portfolioService.addAssignment("1 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_2 = portfolioService.addAssignment("2 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
dbInstance.commit();
List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
Assert.assertEquals(2, templateAssignments.size());
// synched and check the sections order
Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
binder = synchedBinder.getBinder();
dbInstance.commitAndCloseSession();
List<Assignment> assignments = portfolioService.getAssignments(binder, null);
Assignment startedAssignment_1 = portfolioService.startAssignment(assignments.get(0).getKey(), id);
Assignment startedAssignment_2 = portfolioService.startAssignment(assignments.get(1).getKey(), id);
Long startedPageKey_1 = startedAssignment_1.getPage().getKey();
Long startedPageKey_2 = startedAssignment_2.getPage().getKey();
dbInstance.commitAndCloseSession();
// add some comments
OLATResourceable startedPageOres_1 = OresHelper.createOLATResourceableInstance(Page.class, startedPageKey_1);
userCommentsDao.createComment(id, startedPageOres_1, null, "Hello");
// delete
boolean deleted = portfolioService.deleteBinder(binder);
dbInstance.commit();
Assert.assertTrue(deleted);
// check that the template is save
Assignment reloadAssignment_1 = assignmentDao.loadAssignmentByKey(assignment_1.getKey());
Assert.assertNotNull(reloadAssignment_1);
Assignment reloadAssignment_2 = assignmentDao.loadAssignmentByKey(assignment_2.getKey());
Assert.assertNotNull(reloadAssignment_2);
// check that the binder is really deleted
Binder reloadedBinder = binderDao.loadByKey(binder.getKey());
Assert.assertNull(reloadedBinder);
Assignment reloadStartedAssignment_1 = assignmentDao.loadAssignmentByKey(startedAssignment_1.getKey());
Assert.assertNull(reloadStartedAssignment_1);
Assignment reloadStartedAssignment_2 = assignmentDao.loadAssignmentByKey(startedAssignment_2.getKey());
Assert.assertNull(reloadStartedAssignment_2);
Page reloadedStartedPage_1 = pageDao.loadByKey(startedPageKey_1);
Assert.assertNull(reloadedStartedPage_1);
Page reloadedStartedPage_2 = pageDao.loadByKey(startedPageKey_2);
Assert.assertNull(reloadedStartedPage_2);
}
use of org.olat.core.id.OLATResourceable 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()));
}
use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class ACOfferManagerTest method testDeleteOffer.
@Test
public void testDeleteOffer() {
OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
assertNotNull(testOres);
dbInstance.commitAndCloseSession();
// create an offer
Offer offer = acOfferManager.createOffer(testOres, "TestDeleteOffer");
assertNotNull(offer);
assertEquals(OfferImpl.class, offer.getClass());
// and save the offer
acOfferManager.saveOffer(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// retrieve the offer
List<Offer> offers = acOfferManager.findOfferByResource(testOres, true, null);
assertNotNull(offers);
assertEquals(1, offers.size());
assertEquals(offer, offers.get(0));
dbInstance.commitAndCloseSession();
// delete the offer
acOfferManager.deleteOffer(offer);
dbInstance.commitAndCloseSession();
// try to retrieve the offer
List<Offer> noOffers = acOfferManager.findOfferByResource(testOres, true, null);
assertNotNull(noOffers);
assertEquals(0, noOffers.size());
dbInstance.commitAndCloseSession();
// retrieve all offers, deleted too
List<Offer> delOffers = acOfferManager.findOfferByResource(testOres, false, null);
assertNotNull(delOffers);
assertEquals(1, delOffers.size());
assertEquals(offer, delOffers.get(0));
assertEquals(false, delOffers.get(0).isValid());
dbInstance.commitAndCloseSession();
}
use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class ACOfferManagerTest method testFilterWithDelete.
@Test
public void testFilterWithDelete() {
// 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, "TestFilterWithDelete 1");
Offer offer2 = acOfferManager.createOffer(testOres2, "TestFilterWithDelete 2");
acOfferManager.saveOffer(offer1);
acOfferManager.saveOffer(offer2);
dbInstance.commitAndCloseSession();
// delete resource of offer 2
testOres2 = dbInstance.getCurrentEntityManager().find(OLATResourceImpl.class, testOres2.getKey());
dbInstance.deleteObject(testOres2);
// 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(1, filteredKeys.size());
assertTrue(filteredKeys.contains(testOres1.getKey()));
assertFalse(filteredKeys.contains(testOres2.getKey()));
assertFalse(filteredKeys.contains(testOres3.getKey()));
}
use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class ACOfferManagerTest method testSaveOffer.
@Test
public void testSaveOffer() {
// create a resource
OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
assertNotNull(testOres);
dbInstance.commitAndCloseSession();
// create an offer
Offer offer = acOfferManager.createOffer(testOres, "TestSaveOffer");
assertNotNull(offer);
assertEquals(OfferImpl.class, offer.getClass());
if (offer instanceof OfferImpl) {
OfferImpl offerImpl = (OfferImpl) offer;
offerImpl.setToken("token1");
}
offer.setValidFrom(new Date());
offer.setValidTo(new Date());
// and save the offer
acOfferManager.saveOffer(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// check if the offer is saved
List<Offer> offers = acOfferManager.findOfferByResource(testOres, true, null);
assertNotNull(offers);
assertEquals(1, offers.size());
Offer savedOffer = offers.get(0);
assertNotNull(savedOffer);
assertEquals(OfferImpl.class, savedOffer.getClass());
if (savedOffer instanceof OfferImpl) {
OfferImpl offerImpl = (OfferImpl) savedOffer;
assertEquals("token1", offerImpl.getToken());
}
assertNotNull(offer.getValidFrom());
assertNotNull(offer.getValidTo());
assertEquals(testOres.getResourceableId(), savedOffer.getResourceId());
assertEquals(testOres.getResourceableTypeName(), savedOffer.getResourceTypeName());
assertEquals("TestSaveOffer", savedOffer.getResourceDisplayName());
}
Aggregations