Search in sources :

Example 76 with Binder

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

the class PortfolioServiceTest method syncBinder_moveAssignmentsInSection_multiple.

@Test
public void syncBinder_moveAssignmentsInSection_multiple() {
    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 sectionRef1 = portfolioService.getSections(templateBinder).get(0);
    dbInstance.commit();
    // make 4 assignments
    Section templateSection1 = portfolioService.getSection(sectionRef1);
    Assignment assignment_1_1 = portfolioService.addAssignment("1.1 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    Assignment assignment_1_2 = portfolioService.addAssignment("1.2 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    Assignment assignment_1_3 = portfolioService.addAssignment("1.3 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    Assignment assignment_1_4 = portfolioService.addAssignment("1.4 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    Assignment assignment_1_5 = portfolioService.addAssignment("1.5 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    Assignment assignment_1_6 = portfolioService.addAssignment("1.6 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    dbInstance.commit();
    List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
    Assert.assertEquals(6, templateAssignments.size());
    // a user take the binder and synched it a first time
    Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "74", 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(6, assignments.size());
    for (Assignment assignment : assignments) {
        portfolioService.startAssignment(assignment.getKey(), id);
        dbInstance.commit();
    }
    dbInstance.commit();
    // check that the student has it's 8 pages
    List<Page> pages = portfolioService.getPages(binder, null);
    Assert.assertEquals(6, pages.size());
    dbInstance.commit();
    // synched and check the sections order
    SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
    Binder freshBinder = synchedBinder2.getBinder();
    dbInstance.commitAndCloseSession();
    // ooops, someone deleted the assignment (simulate jump in the numbering of the list)
    List<Section> sections = portfolioService.getSections(freshBinder);
    List<Assignment> firstSectionAssignments = portfolioService.getAssignments(sections.get(0), null);
    dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(1));
    dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(2));
    dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(3));
    dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(5));
    dbInstance.commit();
    List<Assignment> firstSectionDeletedAssignments = portfolioService.getAssignments(sections.get(0), null);
    Assert.assertEquals(2, firstSectionDeletedAssignments.size());
    // synched and check the sections order
    SynchedBinder synchedBinder3 = portfolioService.loadAndSyncBinder(binder);
    Binder freshBinder3 = synchedBinder3.getBinder();
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(freshBinder3);
    List<Assignment> firstSectionAssignmentResynched = portfolioService.getAssignments(sections.get(0), null);
    List<Assignment> templateAssignmentsSynched = new ArrayList<>();
    Assert.assertEquals(6, firstSectionAssignmentResynched.size());
    for (Assignment firstSectionAssignment : firstSectionAssignmentResynched) {
        Assert.assertEquals(firstSectionAssignment.getTitle(), firstSectionAssignment.getTemplateReference().getTitle());
        templateAssignmentsSynched.add(firstSectionAssignment.getTemplateReference());
    }
    Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_1));
    Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_2));
    Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_3));
    Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_4));
    Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_5));
    Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_6));
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) ArrayList(java.util.ArrayList) 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 Binder

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

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 78 with Binder

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

the class PortfolioServiceTest method assignTemplate.

@Test
public void assignTemplate() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-7");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-8");
    // create a template
    String title = "Template binder";
    String summary = "Binder used as a template";
    Binder template = portfolioService.createNewBinder(title, summary, null, owner);
    dbInstance.commit();
    for (int i = 0; i < 4; i++) {
        portfolioService.appendNewSection("Section " + i, "Section " + i, null, null, template);
        dbInstance.commit();
    }
    dbInstance.commitAndCloseSession();
    List<Section> templateSections = portfolioService.getSections(template);
    Assert.assertNotNull(templateSections);
    Assert.assertEquals(4, templateSections.size());
    // user copy the template
    Binder binder = portfolioService.assignBinder(id, template, null, null, new Date());
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(binder);
    Assert.assertNotNull(binder.getKey());
    Assert.assertNotNull(binder.getCopyDate());
    Assert.assertNotNull(template.getTitle(), binder.getTitle());
    List<Section> reloadedSections = portfolioService.getSections(binder);
    Assert.assertNotNull(reloadedSections);
    Assert.assertEquals(4, reloadedSections.size());
    Assert.assertEquals(templateSections.get(0).getTitle(), reloadedSections.get(0).getTitle());
    Assert.assertEquals("Section 1", reloadedSections.get(1).getTitle());
    Assert.assertEquals(templateSections.get(2).getTitle(), reloadedSections.get(2).getTitle());
    Assert.assertEquals("Section 3", reloadedSections.get(3).getTitle());
    Assert.assertEquals(templateSections.get(0), ((SectionImpl) reloadedSections.get(0)).getTemplateReference());
    Assert.assertEquals(templateSections.get(1), ((SectionImpl) reloadedSections.get(1)).getTemplateReference());
    Assert.assertEquals(templateSections.get(2), ((SectionImpl) reloadedSections.get(2)).getTemplateReference());
    Assert.assertEquals(templateSections.get(3), ((SectionImpl) reloadedSections.get(3)).getTemplateReference());
}
Also used : SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) Identity(org.olat.core.id.Identity) Section(org.olat.modules.portfolio.Section) Date(java.util.Date) Test(org.junit.Test)

Example 79 with Binder

use of org.olat.modules.portfolio.Binder 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));
}
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 80 with Binder

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

the class PortfolioServiceTest method removeAssignment.

@Test
public void removeAssignment() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();
    // make the binder and the section
    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("3 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
    dbInstance.commitAndCloseSession();
    boolean ok = portfolioService.deleteAssignment(assignment_3);
    Assert.assertTrue(ok);
    dbInstance.commitAndCloseSession();
    List<Assignment> assignments = portfolioService.getSection(sectionRef).getAssignments();
    Assert.assertNotNull(assignments);
    Assert.assertEquals(3, assignments.size());
    Assert.assertTrue(assignments.contains(assignment_1));
    Assert.assertTrue(assignments.contains(assignment_2));
    Assert.assertFalse(assignments.contains(assignment_3));
    Assert.assertTrue(assignments.contains(assignment_4));
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SectionRef(org.olat.modules.portfolio.SectionRef) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Aggregations

Binder (org.olat.modules.portfolio.Binder)144 Section (org.olat.modules.portfolio.Section)72 Identity (org.olat.core.id.Identity)70 Test (org.junit.Test)68 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)58 Page (org.olat.modules.portfolio.Page)44 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Assignment (org.olat.modules.portfolio.Assignment)30 ArrayList (java.util.ArrayList)22 SectionRef (org.olat.modules.portfolio.SectionRef)22 AssessedBinder (org.olat.modules.portfolio.model.AssessedBinder)20 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)16 OLATResourceable (org.olat.core.id.OLATResourceable)14 BinderSecurityCallback (org.olat.modules.portfolio.BinderSecurityCallback)14 PortfolioService (org.olat.modules.portfolio.PortfolioService)14 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)14 AccessRights (org.olat.modules.portfolio.model.AccessRights)12 Date (java.util.Date)10 WindowControl (org.olat.core.gui.control.WindowControl)10 AssessmentSectionImpl (org.olat.modules.portfolio.model.AssessmentSectionImpl)8