Search in sources :

Example 31 with Assignment

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

the class PortfolioServiceImpl method deleteAssignment.

@Override
public boolean deleteAssignment(Assignment assignment) {
    Assignment reloadedAssignment = assignmentDao.loadAssignmentByKey(assignment.getKey());
    Section reloadedSection = reloadedAssignment.getSection();
    boolean removed = false;
    if (reloadedSection != null) {
        removed = ((SectionImpl) reloadedSection).getAssignments().remove(reloadedAssignment);
    }
    assignmentDao.deleteAssignment(reloadedAssignment);
    if (removed) {
        binderDao.updateSection(reloadedSection);
    }
    return true;
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) SectionImpl(org.olat.modules.portfolio.model.SectionImpl) AssessmentSectionImpl(org.olat.modules.portfolio.model.AssessmentSectionImpl)

Example 32 with Assignment

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

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

Example 34 with Assignment

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

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)

Example 35 with Assignment

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

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();
}
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)

Aggregations

Assignment (org.olat.modules.portfolio.Assignment)78 Section (org.olat.modules.portfolio.Section)48 Binder (org.olat.modules.portfolio.Binder)30 Identity (org.olat.core.id.Identity)28 Test (org.junit.Test)26 Page (org.olat.modules.portfolio.Page)26 ArrayList (java.util.ArrayList)24 RepositoryEntry (org.olat.repository.RepositoryEntry)20 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)18 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)18 SectionRef (org.olat.modules.portfolio.SectionRef)16 File (java.io.File)8 HashMap (java.util.HashMap)8 List (java.util.List)8 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 SectionImpl (org.olat.modules.portfolio.model.SectionImpl)8 PortfolioElementRow (org.olat.modules.portfolio.ui.model.PortfolioElementRow)8 Link (org.olat.core.gui.components.link.Link)6