Search in sources :

Example 86 with OLATResourceable

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);
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) OLATResourceable(org.olat.core.id.OLATResourceable) Page(org.olat.modules.portfolio.Page) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SectionRef(org.olat.modules.portfolio.SectionRef) Section(org.olat.modules.portfolio.Section) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Test(org.junit.Test)

Example 87 with OLATResourceable

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()));
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 88 with OLATResourceable

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();
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 89 with OLATResourceable

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()));
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) OLATResourceImpl(org.olat.resource.OLATResourceImpl) Test(org.junit.Test)

Example 90 with OLATResourceable

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());
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) Test(org.junit.Test)

Aggregations

OLATResourceable (org.olat.core.id.OLATResourceable)924 WindowControl (org.olat.core.gui.control.WindowControl)304 Test (org.junit.Test)158 Identity (org.olat.core.id.Identity)154 RepositoryEntry (org.olat.repository.RepositoryEntry)130 ContextEntry (org.olat.core.id.context.ContextEntry)82 ArrayList (java.util.ArrayList)68 OLATResource (org.olat.resource.OLATResource)60 Controller (org.olat.core.gui.control.Controller)48 Date (java.util.Date)46 AssertException (org.olat.core.logging.AssertException)32 StateSite (org.olat.core.id.context.StateSite)30 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)30 ICourse (org.olat.course.ICourse)30 CourseNode (org.olat.course.nodes.CourseNode)28 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)28 BusinessControl (org.olat.core.id.context.BusinessControl)24 BusinessGroup (org.olat.group.BusinessGroup)24 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)22 BinderSecurityCallback (org.olat.modules.portfolio.BinderSecurityCallback)22