Search in sources :

Example 6 with SectionRef

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

the class RestorePageController method getSelectedSection.

private SectionRef getSelectedSection() {
    SectionRef selectSection = null;
    if (sectionsEl != null && sectionsEl.isOneSelected() && sectionsEl.isEnabled() && sectionsEl.isVisible()) {
        String selectedKey = sectionsEl.getSelectedKey();
        selectSection = new SectionKeyRef(new Long(selectedKey));
    }
    return selectSection;
}
Also used : SectionKeyRef(org.olat.modules.portfolio.model.SectionKeyRef) SectionRef(org.olat.modules.portfolio.SectionRef)

Example 7 with SectionRef

use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.

the class PortfolioServiceTest method deleteBinder.

@Test
public void deleteBinder() {
    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);
    Page page1 = portfolioService.appendNewPage(owner, "New page", "A brand new page.", null, null, reloadedSection1);
    Section reloadedSection2 = portfolioService.getSection(sectionRef2);
    Page page2 = portfolioService.appendNewPage(owner, "New page", "A brand new page.", null, null, reloadedSection2);
    Assert.assertNotNull(page1);
    Assert.assertNotNull(page2);
    dbInstance.commitAndCloseSession();
    // delete
    boolean deleted = portfolioService.deleteBinder(binder);
    dbInstance.commit();
    Assert.assertTrue(deleted);
}
Also used : SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) Page(org.olat.modules.portfolio.Page) Identity(org.olat.core.id.Identity) SectionRef(org.olat.modules.portfolio.SectionRef) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 8 with SectionRef

use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.

the class PortfolioServiceTest method deleteSectionWithPages_errorInNumbering.

/**
 * Check if we can delete a section where there is an error of numbering
 * in the list of pages.
 */
@Test
public void deleteSectionWithPages_errorInNumbering() {
    // 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 sectionRef = portfolioService.appendNewSection("1. section ", "Section 1", null, null, binder);
    dbInstance.commit();
    portfolioService.updateBinderUserInformations(binder, owner);
    dbInstance.commit();
    Section reloadedSection = portfolioService.getSection(sectionRef);
    List<Page> pagesSection = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Page page = portfolioService.appendNewPage(owner, "New page", "A brand new page.", null, null, reloadedSection);
        pagesSection.add(page);
    }
    dbInstance.commitAndCloseSession();
    // simulate a gap in numbering of the list
    Page pageToDelete = dbInstance.getCurrentEntityManager().getReference(PageImpl.class, pagesSection.get(4).getKey());
    dbInstance.getCurrentEntityManager().remove(pageToDelete);
    dbInstance.commitAndCloseSession();
    // delete the section
    portfolioService.deleteSection(binder, reloadedSection);
    dbInstance.commit();
    // check if the section and the pages are deleted
    Section deletedSection = binderDao.loadSectionByKey(sectionRef.getKey());
    Assert.assertNull(deletedSection);
    Page deletedPage = pageDao.loadByKey(pagesSection.get(4).getKey());
    Assert.assertNull(deletedPage);
    List<Page> deletedPages = pageDao.getPages(sectionRef);
    Assert.assertNotNull(deletedPages);
    Assert.assertTrue(deletedPages.isEmpty());
}
Also used : SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page) Identity(org.olat.core.id.Identity) SectionRef(org.olat.modules.portfolio.SectionRef) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 9 with SectionRef

use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.

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

Example 10 with SectionRef

use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.

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)

Aggregations

SectionRef (org.olat.modules.portfolio.SectionRef)32 Section (org.olat.modules.portfolio.Section)24 Test (org.junit.Test)22 Identity (org.olat.core.id.Identity)22 Binder (org.olat.modules.portfolio.Binder)22 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)22 Page (org.olat.modules.portfolio.Page)20 Assignment (org.olat.modules.portfolio.Assignment)16 RepositoryEntry (org.olat.repository.RepositoryEntry)16 ArrayList (java.util.ArrayList)8 SectionKeyRef (org.olat.modules.portfolio.model.SectionKeyRef)4 OLATResourceable (org.olat.core.id.OLATResourceable)2 PageImageAlign (org.olat.modules.portfolio.PageImageAlign)2