Search in sources :

Example 71 with Section

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

the class PortfolioServiceTest method binderAndSectionAndPageAccessRights.

@Test
public void binderAndSectionAndPageAccessRights() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-3");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-4");
    Identity reviewer = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-5");
    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, coach, PortfolioRoles.coach);
    dbInstance.commit();
    List<Page> pages = portfolioService.getPages(section);
    Page page = pages.get(0);
    portfolioService.addAccessRights(page, reviewer, PortfolioRoles.reviewer);
    // load right
    List<AccessRights> rights = portfolioService.getAccessRights(binder);
    Assert.assertNotNull(rights);
    Assert.assertEquals(4, rights.size());
    boolean foundOwner = false;
    boolean foundCoach = false;
    boolean foundReviewer = false;
    for (AccessRights right : rights) {
        if (PortfolioRoles.owner.equals(right.getRole()) && owner.equals(right.getIdentity())) {
            foundOwner = true;
        } else if (PortfolioRoles.coach.equals(right.getRole()) && coach.equals(right.getIdentity())) {
            foundCoach = true;
        } else if (PortfolioRoles.reviewer.equals(right.getRole()) && reviewer.equals(right.getIdentity())) {
            foundReviewer = true;
        }
    }
    Assert.assertTrue(foundOwner);
    Assert.assertTrue(foundCoach);
    Assert.assertTrue(foundReviewer);
}
Also used : AccessRights(org.olat.modules.portfolio.model.AccessRights) 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) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 72 with Section

use of org.olat.modules.portfolio.Section 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 73 with Section

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

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());
}
Also used : AccessRights(org.olat.modules.portfolio.model.AccessRights) 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) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 74 with Section

use of org.olat.modules.portfolio.Section 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 75 with Section

use of org.olat.modules.portfolio.Section 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

Section (org.olat.modules.portfolio.Section)190 Page (org.olat.modules.portfolio.Page)100 Test (org.junit.Test)86 Identity (org.olat.core.id.Identity)80 Binder (org.olat.modules.portfolio.Binder)72 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)68 Assignment (org.olat.modules.portfolio.Assignment)48 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)40 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)38 ArrayList (java.util.ArrayList)36 RepositoryEntry (org.olat.repository.RepositoryEntry)26 SectionRef (org.olat.modules.portfolio.SectionRef)24 HashMap (java.util.HashMap)22 Date (java.util.Date)16 PageUserInformations (org.olat.modules.portfolio.PageUserInformations)14 BigDecimal (java.math.BigDecimal)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 SectionImpl (org.olat.modules.portfolio.model.SectionImpl)12 PortfolioElementRow (org.olat.modules.portfolio.ui.model.PortfolioElementRow)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10