Search in sources :

Example 6 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class BinderDAO method deleteBinder.

public int deleteBinder(BinderRef binderRef) {
    int rows = userInformationsDAO.deleteBinderUserInfos(binderRef);
    BinderImpl binder = (BinderImpl) loadByKey(binderRef.getKey());
    List<Section> sections = new ArrayList<>(binder.getSections());
    for (Section section : sections) {
        List<Page> pages = new ArrayList<>(section.getPages());
        section.getPages().clear();
        section = dbInstance.getCurrentEntityManager().merge(section);
        for (Page page : pages) {
            if (page != null) {
                rows += pageDao.deletePage(page);
                rows += pageUserInfosDao.delete(page);
            }
        }
        rows += assessmentSectionDao.deleteAssessmentSections(section);
        Group baseGroup = section.getBaseGroup();
        rows += groupDao.removeMemberships(baseGroup);
        dbInstance.getCurrentEntityManager().remove(section);
        dbInstance.getCurrentEntityManager().remove(baseGroup);
        rows += 2;
    }
    binder.getSections().clear();
    Group baseGroup = binder.getBaseGroup();
    rows += groupDao.removeMemberships(baseGroup);
    dbInstance.getCurrentEntityManager().remove(binder);
    dbInstance.getCurrentEntityManager().remove(baseGroup);
    return rows + 2;
}
Also used : Group(org.olat.basesecurity.Group) ArrayList(java.util.ArrayList) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section)

Example 7 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class BinderDAO method createCopy.

public BinderImpl createCopy(BinderImpl template, RepositoryEntry entry, String subIdent) {
    BinderImpl binder = new BinderImpl();
    binder.setCreationDate(new Date());
    binder.setLastModified(binder.getCreationDate());
    binder.setTitle(template.getTitle());
    binder.setSummary(template.getSummary());
    binder.setImagePath(template.getImagePath());
    binder.setStatus(BinderStatus.open.name());
    binder.setBaseGroup(groupDao.createGroup());
    binder.setTemplate(template);
    binder.setCopyDate(binder.getCreationDate());
    if (entry != null) {
        binder.setEntry(entry);
    }
    if (StringHelper.containsNonWhitespace(subIdent)) {
        binder.setSubIdent(subIdent);
    }
    dbInstance.getCurrentEntityManager().persist(binder);
    binder.getSections().size();
    for (Section templateSection : template.getSections()) {
        Section section = createInternalSection(binder, templateSection);
        binder.getSections().add(section);
        dbInstance.getCurrentEntityManager().persist(section);
    }
    binder = dbInstance.getCurrentEntityManager().merge(binder);
    return binder;
}
Also used : BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Section(org.olat.modules.portfolio.Section) Date(java.util.Date)

Example 8 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class BinderDAOTest method createBinderWithSection_2steps.

@Test
public void createBinderWithSection_2steps() {
    String title = "Binder 2";
    String summary = "Binder with one section.";
    Binder binder = binderDao.createAndPersist(title, summary, null, null);
    dbInstance.commitAndCloseSession();
    String section1Title = "First section";
    String section1Desc = "My first section.";
    binder = binderDao.loadByKey(binder.getKey());
    Section section1 = binderDao.createSection(section1Title, section1Desc, null, null, binder);
    dbInstance.commitAndCloseSession();
    String section2Title = "Second section";
    String section2Desc = "My second section.";
    binder = binderDao.loadByKey(binder.getKey());
    Section section2 = binderDao.createSection(section2Title, section2Desc, null, null, binder);
    dbInstance.commitAndCloseSession();
    Binder reloadedBinder = binderDao.loadByKey(binder.getKey());
    List<Section> sections = ((BinderImpl) reloadedBinder).getSections();
    Assert.assertNotNull(sections);
    Assert.assertEquals(2, sections.size());
    Assert.assertEquals(section1, sections.get(0));
    Assert.assertEquals(section2, sections.get(1));
}
Also used : Binder(org.olat.modules.portfolio.Binder) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 9 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class PageDAOTest method loadPageByBody.

@Test
public void loadPageByBody() {
    BinderImpl binder = binderDao.createAndPersist("Binder body", "A binder with a page and a page body", null, null);
    Section section = binderDao.createSection("Section", "Body section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with body.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    Page reloadedPage = pageDao.loadByBody(page.getBody());
    Assert.assertNotNull(reloadedPage);
    Assert.assertEquals(page, reloadedPage);
}
Also used : BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 10 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class PageDAOTest method getPages_binder.

@Test
public void getPages_binder() {
    BinderImpl binder = binderDao.createAndPersist("Binder p2", "A binder with 2 page", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page1 = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    Page page2 = pageDao.createAndPersist("Page 2", "A page with content.", null, null, true, reloadedSection, null);
    Page page3 = pageDao.createAndPersist("Juno", "Juno is a spacecraft.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    // reload
    List<Page> sectionPages = pageDao.getPages(binder, null);
    Assert.assertNotNull(sectionPages);
    Assert.assertEquals(3, sectionPages.size());
    Assert.assertTrue(sectionPages.contains(page1));
    Assert.assertTrue(sectionPages.contains(page2));
    Assert.assertTrue(sectionPages.contains(page3));
    // reload
    List<Page> searchedPages = pageDao.getPages(binder, "juno");
    Assert.assertNotNull(searchedPages);
    Assert.assertEquals(1, searchedPages.size());
    Assert.assertFalse(searchedPages.contains(page1));
    Assert.assertFalse(searchedPages.contains(page2));
    Assert.assertTrue(searchedPages.contains(page3));
}
Also used : BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Aggregations

BinderImpl (org.olat.modules.portfolio.model.BinderImpl)64 Section (org.olat.modules.portfolio.Section)40 Test (org.junit.Test)38 Page (org.olat.modules.portfolio.Page)32 Identity (org.olat.core.id.Identity)22 Binder (org.olat.modules.portfolio.Binder)14 PageUserInformations (org.olat.modules.portfolio.PageUserInformations)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 OLATResource (org.olat.resource.OLATResource)10 ICourse (org.olat.course.ICourse)8 CourseNode (org.olat.course.nodes.CourseNode)8 PortfolioCourseNode (org.olat.course.nodes.PortfolioCourseNode)8 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)8 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)8 AssessedBinder (org.olat.modules.portfolio.model.AssessedBinder)8 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)8 Date (java.util.Date)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 PageBody (org.olat.modules.portfolio.PageBody)6 BigDecimal (java.math.BigDecimal)4