use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method syncBinder_moveInNewSection.
@Test
public void syncBinder_moveInNewSection() {
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());
SectionRef sectionRef0 = portfolioService.getSections(templateBinder).get(0);
// add 2 sections
SectionRef sectionRef1 = portfolioService.appendNewSection("1 section ", "Section 1", null, null, templateBinder);
SectionRef sectionRef2 = portfolioService.appendNewSection("2 section ", "Section 2", null, null, templateBinder);
dbInstance.commit();
// make 4 assignments
Section templateSection0 = portfolioService.getSection(sectionRef0);
Section templateSection1 = portfolioService.getSection(sectionRef1);
Section templateSection2 = portfolioService.getSection(sectionRef2);
Assignment assignment1_1 = portfolioService.addAssignment("1.1 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment1_2 = portfolioService.addAssignment("1.2 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment2_1 = portfolioService.addAssignment("2.1 Assignment", "", "", AssignmentType.essay, templateSection2, false, false, false, null);
Assignment assignment2_2 = portfolioService.addAssignment("2.2 Assignment", "", "", AssignmentType.essay, templateSection2, false, false, false, null);
dbInstance.commit();
List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
Assert.assertEquals(4, templateAssignments.size());
// a user take the binder and synched it a first time
Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "72", null);
dbInstance.commit();
SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(synchedBinder);
Assert.assertEquals(binder, synchedBinder.getBinder());
// start all assignments
List<Assignment> assignments = portfolioService.getAssignments(binder, null);
Assert.assertEquals(4, assignments.size());
for (Assignment assignment : assignments) {
portfolioService.startAssignment(assignment.getKey(), id);
dbInstance.commit();
}
dbInstance.commit();
// check that the student has it's 4 pages
List<Page> pages = portfolioService.getPages(binder, null);
Assert.assertEquals(4, pages.size());
// author create a new section and move an assignment
SectionRef sectionRef3 = portfolioService.appendNewSection("3 section ", "Section 3", null, null, templateBinder);
dbInstance.commit();
Section templateSection3 = portfolioService.getSection(sectionRef3);
Assignment assignment3_1 = portfolioService.addAssignment("3.1 Assignment", "", "", AssignmentType.essay, templateSection3, false, false, false, null);
dbInstance.commit();
// the author move an assigment
portfolioService.moveAssignment(templateSection1, assignment1_1, templateSection2);
dbInstance.commit();
portfolioService.moveAssignment(templateSection2, assignment2_1, templateSection3);
dbInstance.commitAndCloseSession();
// check the move
List<Assignment> templateAssignmentsSection1 = portfolioService.getAssignments(templateSection1, null);
Assert.assertTrue(templateAssignmentsSection1.contains(assignment1_2));
List<Assignment> templateAssignmentsSection2 = portfolioService.getAssignments(templateSection2, null);
Assert.assertTrue(templateAssignmentsSection2.contains(assignment2_2));
Assert.assertTrue(templateAssignmentsSection2.contains(assignment1_1));
List<Assignment> templateAssignmentsSection3 = portfolioService.getAssignments(templateSection3, null);
Assert.assertTrue(templateAssignmentsSection3.contains(assignment2_1));
Assert.assertTrue(templateAssignmentsSection3.contains(assignment3_1));
// synched and check the sections order
SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
Binder freshBinder = synchedBinder2.getBinder();
List<Section> sections = portfolioService.getSections(freshBinder);
Assert.assertEquals(4, sections.size());
Section section0 = sections.get(0);
Section section1 = sections.get(1);
Section section2 = sections.get(2);
Section section3 = sections.get(3);
Assert.assertEquals(templateSection0, section0.getTemplateReference());
Assert.assertEquals(templateSection1, section1.getTemplateReference());
Assert.assertEquals(templateSection2, section2.getTemplateReference());
Assert.assertEquals(templateSection3, section3.getTemplateReference());
// load pages from section 1
List<Page> pagesSection1 = portfolioService.getPages(section1);
Assert.assertEquals(1, pagesSection1.size());
Page page1_2 = pagesSection1.get(0);
Assert.assertTrue(page1_2.getTitle().equals("1.2 Assignment"));
// and pages from section 2
List<Page> pagesSection2 = portfolioService.getPages(section2);
Assert.assertEquals(2, pagesSection2.size());
Page page2_2 = pagesSection2.get(0);
Page page1_1 = pagesSection2.get(1);
Assert.assertTrue(page2_2.getTitle().equals("1.1 Assignment") || page2_2.getTitle().equals("2.2 Assignment"));
Assert.assertTrue(page1_1.getTitle().equals("1.1 Assignment") || page1_1.getTitle().equals("2.2 Assignment"));
// and pages from section 3
List<Page> pagesSection3 = portfolioService.getPages(section3);
Assert.assertEquals(1, pagesSection3.size());
Page page2_1 = pagesSection3.get(0);
Assert.assertTrue(page2_1.getTitle().equals("2.1 Assignment"));
List<Assignment> assignmentsSection3 = section3.getAssignments();
Assert.assertEquals(2, assignmentsSection3.size());
Assignment templateSynchedSection3a = assignmentsSection3.get(0).getTemplateReference();
Assignment templateSynchedSection3b = assignmentsSection3.get(1).getTemplateReference();
Assert.assertTrue(assignment3_1.equals(templateSynchedSection3a) || assignment3_1.equals(templateSynchedSection3b));
Assert.assertTrue(assignment2_1.equals(templateSynchedSection3a) || assignment2_1.equals(templateSynchedSection3b));
}
use of org.olat.modules.portfolio.Page 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.Page 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.Page in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method removeAssignment_usedOne.
@Test
public void removeAssignment_usedOne() {
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());
SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
dbInstance.commit();
// make 4 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);
Assignment assignment_3 = portfolioService.addAssignment("3 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_4 = portfolioService.addAssignment("4 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
dbInstance.commit();
List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
Assert.assertEquals(4, templateAssignments.size());
Assert.assertTrue(templateAssignments.contains(assignment_1));
Assert.assertTrue(templateAssignments.contains(assignment_2));
Assert.assertTrue(templateAssignments.contains(assignment_3));
Assert.assertTrue(templateAssignments.contains(assignment_4));
// 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);
portfolioService.startAssignment(assignments.get(0).getKey(), id);
portfolioService.startAssignment(assignments.get(1).getKey(), id);
portfolioService.startAssignment(assignments.get(2).getKey(), id);
portfolioService.startAssignment(assignments.get(3).getKey(), id);
dbInstance.commit();
List<Section> sections = portfolioService.getSections(binder);
List<Page> pages = portfolioService.getPages(sections.get(0));
Assert.assertEquals(4, pages.size());
// delete an assignment
boolean ok = portfolioService.deleteAssignment(assignment_3);
Assert.assertTrue(ok);
dbInstance.commitAndCloseSession();
// sync the binder
SynchedBinder reSynchedBinder = portfolioService.loadAndSyncBinder(binder);
binder = reSynchedBinder.getBinder();
dbInstance.commitAndCloseSession();
// deleting an assignment doesn't delete the pages
List<Page> allPages = portfolioService.getPages(sections.get(0));
Assert.assertEquals(4, allPages.size());
// sync twice
SynchedBinder reReSynchedBinder = portfolioService.loadAndSyncBinder(binder);
binder = reReSynchedBinder.getBinder();
dbInstance.commitAndCloseSession();
}
use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method deleteTemplateBinder.
@Test
public void deleteTemplateBinder() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-20");
RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
dbInstance.commitAndCloseSession();
Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
List<SectionRef> sections = new ArrayList<>();
for (int i = 0; i < 10; i++) {
SectionRef templateSectionRef = portfolioService.appendNewSection(i + ". section ", "Section " + i, null, null, templateBinder);
dbInstance.commit();
sections.add(templateSectionRef);
Section templateSection = portfolioService.getSection(templateSectionRef);
for (int j = 0; j < 10; j++) {
Assignment assignment = portfolioService.addAssignment(i + "_" + j + " Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assert.assertNotNull(assignment);
}
dbInstance.commit();
}
// collect the page
List<Page> assignmentPages = new ArrayList<>();
for (int k = 0; k < 10; k++) {
// get a binder from the template
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-13" + k);
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);
for (Assignment assignment : assignments) {
Assignment startedAssignment = portfolioService.startAssignment(assignment.getKey(), id);
Assert.assertNotNull(startedAssignment);
Page page = startedAssignment.getPage();
assignmentPages.add(page);
Assert.assertNotNull(page.getBody());
dbInstance.commit();
}
dbInstance.commitAndCloseSession();
}
// delete
boolean deleted = portfolioService.deleteBinderTemplate(templateBinder, templateEntry);
dbInstance.commit();
Assert.assertTrue(deleted);
// check that the pages exists
Assert.assertFalse(assignmentPages.isEmpty());
for (Page page : assignmentPages) {
Page reloadedPage = portfolioService.getPageByKey(page.getKey());
Assert.assertNotNull(reloadedPage);
Section section = reloadedPage.getSection();
Assert.assertNotNull(section);
}
}
Aggregations