use of org.olat.modules.portfolio.Binder in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method deleteSectionWithPages.
@Test
public void deleteSectionWithPages() {
// prepare a binder with 2 sections and some pages
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("del-binder-");
Binder binder = portfolioService.createNewBinder("Binder to delete", "Deletion", "", owner);
SectionRef sectionRef1 = portfolioService.appendNewSection("1. section ", "Section 1", null, null, binder);
dbInstance.commit();
SectionRef sectionRef2 = portfolioService.appendNewSection("2. section ", "Section 2", null, null, binder);
dbInstance.commit();
portfolioService.updateBinderUserInformations(binder, owner);
dbInstance.commit();
Section reloadedSection1 = portfolioService.getSection(sectionRef1);
List<Page> pagesSection1 = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Page page = portfolioService.appendNewPage(owner, "New page", "A brand new page.", null, null, reloadedSection1);
pagesSection1.add(page);
}
Section reloadedSection2 = portfolioService.getSection(sectionRef2);
Page page2 = portfolioService.appendNewPage(owner, "New page", "A brand new page.", null, null, reloadedSection2);
Assert.assertNotNull(page2);
dbInstance.commitAndCloseSession();
// delete the section
portfolioService.deleteSection(binder, reloadedSection1);
dbInstance.commit();
// check if section 2 is still around
Section section2 = binderDao.loadSectionByKey(sectionRef2.getKey());
Assert.assertEquals(reloadedSection2, section2);
Page reloadedPage2 = pageDao.loadByKey(page2.getKey());
Assert.assertNotNull(reloadedPage2);
Assert.assertEquals(page2, reloadedPage2);
// check if section 1 is deleted
Section deletedSection1 = binderDao.loadSectionByKey(sectionRef1.getKey());
Assert.assertNull(deletedSection1);
for (Page pageSection1 : pagesSection1) {
Page deletedPage = pageDao.loadByKey(pageSection1.getKey());
Assert.assertNull(deletedPage);
}
}
use of org.olat.modules.portfolio.Binder in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method binderAndSectionAndPageAccessRights_byIdentity.
@Test
public void binderAndSectionAndPageAccessRights_byIdentity() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-5");
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-6");
String title = "My published binder";
String summary = "My live";
Binder binder = portfolioService.createNewBinder(title, summary, null, owner);
dbInstance.commit();
portfolioService.appendNewSection("Section", "Coached section", null, null, binder);
dbInstance.commit();
List<Section> sections = portfolioService.getSections(binder);
Section section = sections.get(0);
portfolioService.appendNewPage(owner, "Reviewed page", "", null, null, section);
portfolioService.addAccessRights(section, identity, PortfolioRoles.coach);
dbInstance.commit();
List<Page> pages = portfolioService.getPages(section);
Page page = pages.get(0);
portfolioService.addAccessRights(page, identity, PortfolioRoles.reviewer);
// load right
List<AccessRights> rights = portfolioService.getAccessRights(binder, identity);
Assert.assertNotNull(rights);
Assert.assertEquals(2, rights.size());
}
use of org.olat.modules.portfolio.Binder in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method syncBinder.
@Test
public void syncBinder() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-11");
RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
dbInstance.commitAndCloseSession();
// make 2 sections
Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
// add 2 sections
for (int i = 0; i < 2; i++) {
portfolioService.appendNewSection("Section " + i, "Section " + i, null, null, templateBinder);
dbInstance.commit();
}
List<Section> templateSections = portfolioService.getSections(templateBinder);
Assert.assertNotNull(templateSections);
Assert.assertEquals(3, templateSections.size());
// user get a the binder from the template
Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "ac-234", new Date());
dbInstance.commit();
Assert.assertNotNull(binder);
boolean inUse = portfolioService.isTemplateInUse(templateBinder, templateEntry, "ac-234");
Assert.assertTrue(inUse);
// update the template with 2 more sections
for (int i = 2; i < 4; i++) {
portfolioService.appendNewSection("Section " + i, "Section " + i, null, null, templateBinder);
dbInstance.commit();
}
SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
Assert.assertNotNull(synchedBinder);
dbInstance.commit();
Assert.assertTrue(synchedBinder.isChanged());
Assert.assertEquals(binder, synchedBinder.getBinder());
List<Section> synchedSections = portfolioService.getSections(synchedBinder.getBinder());
Assert.assertEquals(5, synchedSections.size());
}
use of org.olat.modules.portfolio.Binder in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method binderAccessRights.
@Test
public void binderAccessRights() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-2");
String title = "My private binder";
String summary = "My live";
Binder binder = portfolioService.createNewBinder(title, summary, null, owner);
dbInstance.commitAndCloseSession();
// load right
List<AccessRights> rights = portfolioService.getAccessRights(binder);
Assert.assertNotNull(rights);
Assert.assertEquals(1, rights.size());
AccessRights ownerRight = rights.get(0);
Assert.assertEquals(binder.getKey(), ownerRight.getBinderKey());
Assert.assertEquals(owner, ownerRight.getIdentity());
Assert.assertEquals(PortfolioRoles.owner, ownerRight.getRole());
}
use of org.olat.modules.portfolio.Binder in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method searchOwnedBinders.
@Test
public void searchOwnedBinders() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("binder-owner-");
Binder binder = portfolioService.createNewBinder("Binder 2", "Binder with one section.", null, owner);
dbInstance.commitAndCloseSession();
portfolioService.appendNewSection("First section", "My first section.", null, null, binder);
dbInstance.commitAndCloseSession();
portfolioService.appendNewSection("Second section", "My second section.", null, null, binder);
dbInstance.commitAndCloseSession();
List<Section> sections = portfolioService.getSections(binder);
for (int i = 0; i < 2; i++) {
Section section = sections.get(1);
portfolioService.appendNewPage(owner, "Page-1-" + i, "", null, null, section);
portfolioService.appendNewPage(owner, "Page-2-" + i, "", null, null, section);
}
List<BinderStatistics> rows = portfolioService.searchOwnedBinders(owner);
Assert.assertNotNull(rows);
Assert.assertEquals(1, rows.size());
BinderStatistics myBinder = rows.get(0);
Assert.assertEquals(2, myBinder.getNumOfSections());
Assert.assertEquals(4, myBinder.getNumOfPages());
}
Aggregations