Search in sources :

Example 11 with SectionRef

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

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

Example 13 with SectionRef

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

the class RestorePageController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    page = portfolioService.changePageStatus(page, PageStatus.draft, getIdentity(), Role.user);
    SectionRef selectSection = getSelectedSection();
    if ((page.getSection() == null && selectSection != null) || (page.getSection() != null && selectSection != null && !page.getSection().getKey().equals(selectSection.getKey()))) {
        page = portfolioService.updatePage(page, selectSection);
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : SectionRef(org.olat.modules.portfolio.SectionRef)

Example 14 with SectionRef

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

the class PageMetadataEditController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (page == null) {
        String title = titleEl.getValue();
        String summary = summaryEl.getValue();
        SectionRef selectSection = getSelectedSection();
        String imagePath = null;
        if (imageUpload.getUploadFile() != null) {
            imagePath = portfolioService.addPosterImageForPage(imageUpload.getUploadFile(), imageUpload.getUploadFileName());
        }
        PageImageAlign align = null;
        if (imageAlignEl.isOneSelected()) {
            align = PageImageAlign.valueOf(imageAlignEl.getSelectedKey());
        }
        page = portfolioService.appendNewPage(getIdentity(), title, summary, imagePath, align, selectSection);
    } else {
        page.setTitle(titleEl.getValue());
        page.setSummary(summaryEl.getValue());
        if (imageUpload.getUploadFile() != null) {
            String imagePath = portfolioService.addPosterImageForPage(imageUpload.getUploadFile(), imageUpload.getUploadFileName());
            page.setImagePath(imagePath);
        } else if (imageUpload.getInitialFile() == null) {
            page.setImagePath(null);
            portfolioService.removePosterImage(page);
        }
        SectionRef selectSection = getSelectedSection();
        SectionRef newParent = null;
        if ((page.getSection() == null && selectSection != null) || (page.getSection() != null && selectSection != null && !page.getSection().getKey().equals(selectSection.getKey()))) {
            newParent = selectSection;
        }
        if (imageAlignEl.isOneSelected()) {
            page.setImageAlignment(PageImageAlign.valueOf(imageAlignEl.getSelectedKey()));
        }
        page = portfolioService.updatePage(page, newParent);
    }
    List<String> updatedCategories = categoriesEl.getValueList();
    portfolioService.updateCategories(page, updatedCategories);
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : PageImageAlign(org.olat.modules.portfolio.PageImageAlign) SectionRef(org.olat.modules.portfolio.SectionRef)

Example 15 with SectionRef

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

the class PageMetadataEditController 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)

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