use of org.olat.modules.portfolio.Page 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.modules.portfolio.Page in project OpenOLAT by OpenOLAT.
the class CategoryDAOTest method getCategorizedSectionsAndPages.
@Test
public void getCategorizedSectionsAndPages() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-1");
Binder binder = portfolioService.createNewBinder("Binder about Verne", "A binder with a single page", null, author);
Section section = binderDao.createSection("Section", "First section", null, null, binder);
dbInstance.commitAndCloseSession();
Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
Page page = pageDao.createAndPersist("Jules Verne", "Deux ans de vacances", null, null, true, reloadedSection, null);
dbInstance.commitAndCloseSession();
List<String> categoriesSection = new ArrayList<>();
categoriesSection.add("Jules");
categoriesSection.add("Verne");
portfolioService.updateCategories(section, categoriesSection);
List<String> categoriesPage = new ArrayList<>();
categoriesPage.add("Aventure");
categoriesPage.add("Vacances");
portfolioService.updateCategories(page, categoriesPage);
dbInstance.commitAndCloseSession();
// load by section
List<CategoryToElement> categories = categoryDao.getCategorizedSectionAndPages(section);
Assert.assertNotNull(categories);
Assert.assertEquals(4, categories.size());
// load by binder
List<CategoryToElement> categoriesByBinder = categoryDao.getCategorizedSectionsAndPages(binder);
Assert.assertNotNull(categoriesByBinder);
Assert.assertEquals(4, categoriesByBinder.size());
}
use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.
the class CategoryDAOTest method getCategorizedOwnedPages.
@Test
public void getCategorizedOwnedPages() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-1");
Binder binder = portfolioService.createNewBinder("Binder p2", "A binder with 2 page", null, author);
Section section = binderDao.createSection("Section", "First section", null, null, binder);
dbInstance.commitAndCloseSession();
Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
Page page1 = pageDao.createAndPersist("Jules Verne", "Cing semaine en ballon", null, null, true, reloadedSection, null);
Page page2 = pageDao.createAndPersist("J. Verne", "Une ville flottante", null, null, true, reloadedSection, null);
Page page3 = pageDao.createAndPersist("Verne", "Les Tribulations d'un Chinois en Chine", null, null, true, reloadedSection, null);
dbInstance.commitAndCloseSession();
List<String> categories1 = new ArrayList<>();
categories1.add("Jules");
categories1.add("Verne");
categories1.add("Aventure");
categories1.add("Voyage");
portfolioService.updateCategories(page1, categories1);
List<String> categories2 = new ArrayList<>();
categories2.add("Jules");
categories2.add("Verne");
categories2.add("Anticipation");
categories2.add("Technologie");
portfolioService.updateCategories(page2, categories2);
List<String> categories3 = new ArrayList<>();
categories3.add("Jules");
categories3.add("Verne");
categories3.add("Aventure");
categories3.add("Chine");
portfolioService.updateCategories(page3, categories3);
dbInstance.commitAndCloseSession();
List<CategoryToElement> categories = categoryDao.getCategorizedOwnedPages(author);
Assert.assertNotNull(categories);
Assert.assertEquals(12, categories.size());
}
use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.
the class PageDAOTest method loadPageByBody.
@Test
public void loadPageByBody() {
BinderImpl binder = binderDao.createAndPersist("Binder body", "A binder with a page and a page body", null, null);
Section section = binderDao.createSection("Section", "Body section", null, null, binder);
dbInstance.commitAndCloseSession();
Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
Page page = pageDao.createAndPersist("Page 1", "A page with body.", null, null, true, reloadedSection, null);
dbInstance.commitAndCloseSession();
Page reloadedPage = pageDao.loadByBody(page.getBody());
Assert.assertNotNull(reloadedPage);
Assert.assertEquals(page, reloadedPage);
}
use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.
the class PageDAOTest method getMembers.
@Test
public void getMembers() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-1");
// an owned binder
Page page = portfolioService.appendNewPage(author, "Page 3", "A page with content.", null, null, null);
dbInstance.commitAndCloseSession();
// reload
List<Identity> owners = pageDao.getMembers(page, PortfolioRoles.owner.name());
Assert.assertNotNull(owners);
Assert.assertEquals(1, owners.size());
Assert.assertEquals(author, owners.get(0));
}
Aggregations