Search in sources :

Example 1 with PagePart

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

the class PageDAO method moveUpPart.

public void moveUpPart(PageBody body, PagePart part) {
    body.getParts().size();
    int index = body.getParts().indexOf(part);
    if (index > 0) {
        PagePart reloadedPart = body.getParts().remove(index);
        body.getParts().add(index - 1, reloadedPart);
    } else if (index < 0) {
        body.getParts().add(0, part);
    }
    ((PageBodyImpl) body).setLastModified(new Date());
    dbInstance.getCurrentEntityManager().merge(body);
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) PageBodyImpl(org.olat.modules.portfolio.model.PageBodyImpl) Date(java.util.Date)

Example 2 with PagePart

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

the class PageDAO method removePart.

public void removePart(PageBody body, PagePart part) {
    PagePart aPart = dbInstance.getCurrentEntityManager().getReference(part.getClass(), part.getKey());
    body.getParts().size();
    body.getParts().remove(aPart);
    dbInstance.getCurrentEntityManager().remove(aPart);
    ((PageBodyImpl) body).setLastModified(new Date());
    dbInstance.getCurrentEntityManager().merge(body);
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) PageBodyImpl(org.olat.modules.portfolio.model.PageBodyImpl) Date(java.util.Date)

Example 3 with PagePart

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

the class PageDAOTest method createBinderWithSectionAndPageAndPart.

@Test
public void createBinderWithSectionAndPageAndPart() {
    BinderImpl binder = binderDao.createAndPersist("Binder p1", "A binder with a page", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    HTMLPart htmlPart = new HTMLPart();
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, htmlPart);
    dbInstance.commitAndCloseSession();
    // reload
    Page reloadedPage = pageDao.loadByKey(page.getKey());
    Assert.assertNotNull(reloadedPage);
    List<PagePart> parts = reloadedPage.getBody().getParts();
    Assert.assertNotNull(parts);
    Assert.assertEquals(1, parts.size());
    Assert.assertEquals(htmlPart, parts.get(0));
    // reload only pages
    List<PagePart> onlyParts = pageDao.getParts(page.getBody());
    Assert.assertNotNull(onlyParts);
    Assert.assertEquals(1, onlyParts.size());
    Assert.assertEquals(htmlPart, onlyParts.get(0));
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) HTMLPart(org.olat.modules.portfolio.model.HTMLPart) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) Test(org.junit.Test)

Example 4 with PagePart

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

the class PageDAOTest method moveParts.

@Test
public void moveParts() {
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, null, null);
    dbInstance.commitAndCloseSession();
    HTMLPart htmlPart = new HTMLPart();
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, htmlPart);
    dbInstance.commitAndCloseSession();
    TitlePart titlePart = new TitlePart();
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, titlePart, 0);
    dbInstance.commitAndCloseSession();
    SpacerPart spacePart = new SpacerPart();
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, spacePart, 0);
    dbInstance.commitAndCloseSession();
    // check the order
    List<PagePart> reloadedPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(reloadedPageParts);
    Assert.assertEquals(3, reloadedPageParts.size());
    Assert.assertEquals(spacePart, reloadedPageParts.get(0));
    Assert.assertEquals(titlePart, reloadedPageParts.get(1));
    Assert.assertEquals(htmlPart, reloadedPageParts.get(2));
    // move title part up
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveUpPart(reloadedBody, titlePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveUpPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveUpPageParts);
    Assert.assertEquals(3, moveUpPageParts.size());
    Assert.assertEquals(titlePart, moveUpPageParts.get(0));
    Assert.assertEquals(spacePart, moveUpPageParts.get(1));
    Assert.assertEquals(htmlPart, moveUpPageParts.get(2));
    // move space part down
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveDownPart(reloadedBody, spacePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveDownPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveDownPageParts);
    Assert.assertEquals(3, moveDownPageParts.size());
    Assert.assertEquals(titlePart, moveDownPageParts.get(0));
    Assert.assertEquals(htmlPart, moveDownPageParts.get(1));
    Assert.assertEquals(spacePart, moveDownPageParts.get(2));
    // not useful move space part down
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveDownPart(reloadedBody, spacePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveDownPageParts2 = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveDownPageParts2);
    Assert.assertEquals(3, moveDownPageParts2.size());
    Assert.assertEquals(titlePart, moveDownPageParts2.get(0));
    Assert.assertEquals(htmlPart, moveDownPageParts2.get(1));
    Assert.assertEquals(spacePart, moveDownPageParts2.get(2));
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) HTMLPart(org.olat.modules.portfolio.model.HTMLPart) TitlePart(org.olat.modules.portfolio.model.TitlePart) Page(org.olat.modules.portfolio.Page) PageBody(org.olat.modules.portfolio.PageBody) SpacerPart(org.olat.modules.portfolio.model.SpacerPart) Test(org.junit.Test)

Example 5 with PagePart

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

the class PageDAOTest method createBinderWithSectionAndPageAndPart.

@Test
public void createBinderWithSectionAndPageAndPart() {
    BinderImpl binder = binderDao.createAndPersist("Binder p1", "A binder with a page", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    HTMLPart htmlPart = new HTMLPart();
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, htmlPart);
    dbInstance.commitAndCloseSession();
    // reload
    Page reloadedPage = pageDao.loadByKey(page.getKey());
    Assert.assertNotNull(reloadedPage);
    List<PagePart> parts = reloadedPage.getBody().getParts();
    Assert.assertNotNull(parts);
    Assert.assertEquals(1, parts.size());
    Assert.assertEquals(htmlPart, parts.get(0));
    // reload only pages
    List<PagePart> onlyParts = pageDao.getParts(page.getBody());
    Assert.assertNotNull(onlyParts);
    Assert.assertEquals(1, onlyParts.size());
    Assert.assertEquals(htmlPart, onlyParts.get(0));
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) HTMLPart(org.olat.modules.portfolio.model.HTMLPart) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) Test(org.junit.Test)

Aggregations

PagePart (org.olat.modules.portfolio.PagePart)12 Date (java.util.Date)6 Test (org.junit.Test)6 Page (org.olat.modules.portfolio.Page)6 PageBody (org.olat.modules.portfolio.PageBody)6 HTMLPart (org.olat.modules.portfolio.model.HTMLPart)6 PageBodyImpl (org.olat.modules.portfolio.model.PageBodyImpl)6 TitlePart (org.olat.modules.portfolio.model.TitlePart)4 Section (org.olat.modules.portfolio.Section)2 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)2 SpacerPart (org.olat.modules.portfolio.model.SpacerPart)2