Search in sources :

Example 76 with Page

use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.

the class PortfolioServiceTest method syncBinder_move.

@Test
public void syncBinder_move() {
    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 assigments
    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 assigments
    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();
    List<Page> pages = portfolioService.getPages(binder, null);
    Assert.assertEquals(4, pages.size());
    // the author move an assigment
    portfolioService.moveAssignment(templateSection1, assignment1_1, templateSection2);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection2, assignment2_1, templateSection1);
    dbInstance.commitAndCloseSession();
    // check the move
    List<Assignment> templateAssignmentsSection1 = portfolioService.getAssignments(templateSection1, null);
    Assert.assertTrue(templateAssignmentsSection1.contains(assignment1_2));
    Assert.assertTrue(templateAssignmentsSection1.contains(assignment2_1));
    List<Assignment> templateAssignmentsSection2 = portfolioService.getAssignments(templateSection2, null);
    Assert.assertTrue(templateAssignmentsSection2.contains(assignment2_2));
    Assert.assertTrue(templateAssignmentsSection2.contains(assignment1_1));
    // synched and check the sections order
    SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
    Binder freshBinder = synchedBinder2.getBinder();
    List<Section> sections = portfolioService.getSections(freshBinder);
    Assert.assertEquals(3, sections.size());
    Section section0 = sections.get(0);
    Section section1 = sections.get(1);
    Section section2 = sections.get(2);
    Assert.assertEquals(templateSection0, section0.getTemplateReference());
    Assert.assertEquals(templateSection1, section1.getTemplateReference());
    Assert.assertEquals(templateSection2, section2.getTemplateReference());
    // load pages from section 1
    List<Page> pagesSection1 = portfolioService.getPages(section1);
    Assert.assertEquals(2, pagesSection1.size());
    Page page1_2 = pagesSection1.get(0);
    Page page2_1 = pagesSection1.get(1);
    Assert.assertTrue(page1_2.getTitle().equals("2.1 Assignment") || page1_2.getTitle().equals("1.2 Assignment"));
    Assert.assertTrue(page2_1.getTitle().equals("2.1 Assignment") || page2_1.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"));
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) 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 77 with Page

use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.

the class PageDAOTest method getPages_section.

@Test
public void getPages_section() {
    BinderImpl binder = binderDao.createAndPersist("Binder p2", "A binder with 2 page", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page1 = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    Page page2 = pageDao.createAndPersist("Page 2", "A page with content.", null, null, true, reloadedSection, null);
    Page page3 = pageDao.createAndPersist("Page 3", "A page with the demonstration of Hawking about black hole'evaporation.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    // reload
    List<Page> sectionPages = pageDao.getPages(reloadedSection);
    Assert.assertNotNull(sectionPages);
    Assert.assertEquals(3, sectionPages.size());
    Assert.assertTrue(sectionPages.contains(page1));
    Assert.assertTrue(sectionPages.contains(page2));
    Assert.assertTrue(sectionPages.contains(page3));
}
Also used : BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 78 with Page

use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.

the class PageDAOTest method createBinderWithSectionAndPage.

@Test
public void createBinderWithSectionAndPage() {
    BinderImpl binder = binderDao.createAndPersist("Binder p1", "A binder with a page", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("New page", "A brand new page.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(page);
    Assert.assertNotNull(page.getKey());
    Assert.assertNotNull(page.getCreationDate());
    Assert.assertNotNull(page.getLastModified());
    Assert.assertEquals("New page", page.getTitle());
    Assert.assertEquals("A brand new page.", page.getSummary());
}
Also used : BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 79 with Page

use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.

the class PageDAOTest method createBinderWithSectionAndPages.

@Test
public void createBinderWithSectionAndPages() {
    BinderImpl binder = binderDao.createAndPersist("Binder p1", "A binder with a page", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    for (int i = 0; i < 5; i++) {
        pageDao.createAndPersist("New page " + i, "A brand new page.", null, null, true, reloadedSection, null);
    }
    dbInstance.commitAndCloseSession();
    List<Page> pages = pageDao.getPages(binder, null);
    Assert.assertNotNull(pages);
    Assert.assertEquals(5, pages.size());
}
Also used : BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 80 with Page

use of org.olat.modules.portfolio.Page in project OpenOLAT by OpenOLAT.

the class PageDAOTest method moveParts.

@Test
public void moveParts() {
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, null, null);
    dbInstance.commitAndCloseSession();
    HTMLPart htmlPart = new HTMLPart();
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, htmlPart);
    dbInstance.commitAndCloseSession();
    TitlePart titlePart = new TitlePart();
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, titlePart, 0);
    dbInstance.commitAndCloseSession();
    SpacerPart spacePart = new SpacerPart();
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, spacePart, 0);
    dbInstance.commitAndCloseSession();
    // check the order
    List<PagePart> reloadedPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(reloadedPageParts);
    Assert.assertEquals(3, reloadedPageParts.size());
    Assert.assertEquals(spacePart, reloadedPageParts.get(0));
    Assert.assertEquals(titlePart, reloadedPageParts.get(1));
    Assert.assertEquals(htmlPart, reloadedPageParts.get(2));
    // move title part up
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveUpPart(reloadedBody, titlePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveUpPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveUpPageParts);
    Assert.assertEquals(3, moveUpPageParts.size());
    Assert.assertEquals(titlePart, moveUpPageParts.get(0));
    Assert.assertEquals(spacePart, moveUpPageParts.get(1));
    Assert.assertEquals(htmlPart, moveUpPageParts.get(2));
    // move space part down
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveDownPart(reloadedBody, spacePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveDownPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveDownPageParts);
    Assert.assertEquals(3, moveDownPageParts.size());
    Assert.assertEquals(titlePart, moveDownPageParts.get(0));
    Assert.assertEquals(htmlPart, moveDownPageParts.get(1));
    Assert.assertEquals(spacePart, moveDownPageParts.get(2));
    // not useful move space part down
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveDownPart(reloadedBody, spacePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveDownPageParts2 = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveDownPageParts2);
    Assert.assertEquals(3, moveDownPageParts2.size());
    Assert.assertEquals(titlePart, moveDownPageParts2.get(0));
    Assert.assertEquals(htmlPart, moveDownPageParts2.get(1));
    Assert.assertEquals(spacePart, moveDownPageParts2.get(2));
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) HTMLPart(org.olat.modules.portfolio.model.HTMLPart) TitlePart(org.olat.modules.portfolio.model.TitlePart) Page(org.olat.modules.portfolio.Page) PageBody(org.olat.modules.portfolio.PageBody) SpacerPart(org.olat.modules.portfolio.model.SpacerPart) Test(org.junit.Test)

Aggregations

Page (org.olat.modules.portfolio.Page)136 Section (org.olat.modules.portfolio.Section)98 Test (org.junit.Test)70 Identity (org.olat.core.id.Identity)64 Binder (org.olat.modules.portfolio.Binder)44 ArrayList (java.util.ArrayList)32 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)32 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)26 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)26 Assignment (org.olat.modules.portfolio.Assignment)24 RepositoryEntry (org.olat.repository.RepositoryEntry)22 HashMap (java.util.HashMap)20 SectionRef (org.olat.modules.portfolio.SectionRef)20 PageUserInformations (org.olat.modules.portfolio.PageUserInformations)18 AssessedPage (org.olat.modules.portfolio.model.AssessedPage)16 PageBody (org.olat.modules.portfolio.PageBody)14 OLATResourceable (org.olat.core.id.OLATResourceable)12 AccessRights (org.olat.modules.portfolio.model.AccessRights)12 CategoryToElement (org.olat.modules.portfolio.CategoryToElement)10 Date (java.util.Date)8