Search in sources :

Example 6 with PageBody

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

the class PageDAO method deletePage.

/**
 * The page cannot be detached (reload it if necessary).
 *
 * @param page
 * @return
 */
public int deletePage(Page page) {
    // nothing to do
    if (page == null || page.getKey() == null)
        return 0;
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(Page.class, page.getKey());
    PageBody body = page.getBody();
    String partQ = "delete from pfpagepart part where part.body.key=:bodyKey";
    int parts = dbInstance.getCurrentEntityManager().createQuery(partQ).setParameter("bodyKey", body.getKey()).executeUpdate();
    String assignmentQ = "delete from pfassignment assignment where assignment.page.key=:pageKey";
    int assignments = dbInstance.getCurrentEntityManager().createQuery(assignmentQ).setParameter("pageKey", page.getKey()).executeUpdate();
    int evaluations = evaluationFormSessionDao.deleteSessionForPortfolioEvaluation(body);
    dbInstance.getCurrentEntityManager().remove(page);
    dbInstance.getCurrentEntityManager().remove(body);
    int comments = userCommentsDAO.deleteAllComments(ores, null);
    return comments + parts + evaluations + assignments + 2;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) PageBody(org.olat.modules.portfolio.PageBody)

Example 7 with PageBody

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

the class PortfolioServiceImpl method moveDownPagePart.

@Override
public void moveDownPagePart(Page page, PagePart part) {
    PageBody body = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveDownPart(body, part);
}
Also used : PageBody(org.olat.modules.portfolio.PageBody)

Example 8 with PageBody

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

the class EvaluationFormResponseDAOTest method createResponseforPortfolio.

@Test
public void createResponseforPortfolio() {
    // prepare a test case with the binder up to the page body
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("eva-1");
    BinderImpl binder = binderDao.createAndPersist("Binder evaluation 1", "A binder with an evaluation", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commit();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with an evalutation.", null, null, true, reloadedSection, null);
    dbInstance.commit();
    RepositoryEntry formEntry = createFormEntry("Eva. form for responses");
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    EvaluationFormSession session = evaluationFormSessionDao.createSessionForPortfolio(id, reloadedBody, formEntry);
    dbInstance.commit();
    // create a response
    String responseIdentifier = UUID.randomUUID().toString();
    BigDecimal numericalValue = new BigDecimal("2.2");
    String stringuifiedResponse = numericalValue.toPlainString();
    Path fileResponse = Paths.get("this", "is", "a", "path");
    EvaluationFormResponse response = evaluationFormResponseDao.createResponse(responseIdentifier, numericalValue, stringuifiedResponse, fileResponse, session);
    dbInstance.commit();
    Assert.assertNotNull(response);
    Assert.assertNotNull(response.getKey());
    Assert.assertNotNull(response.getCreationDate());
    Assert.assertNotNull(response.getLastModified());
    Assert.assertEquals(session, response.getSession());
    Assert.assertEquals(numericalValue, response.getNumericalResponse());
    Assert.assertEquals(stringuifiedResponse, response.getStringuifiedResponse());
    Assert.assertEquals(fileResponse, response.getFileResponse());
    Assert.assertEquals(responseIdentifier, response.getResponseIdentifier());
}
Also used : Path(java.nio.file.Path) EvaluationFormSession(org.olat.modules.forms.EvaluationFormSession) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) EvaluationFormResponse(org.olat.modules.forms.EvaluationFormResponse) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 9 with PageBody

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

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

the class MediaDAOTest method usedInBinders.

@Test
public void usedInBinders() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
    Binder binder = portfolioService.createNewBinder("Binder p2", "A binder with 2 page", null, author);
    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);
    Media media = mediaDao.createMedia("Media", "Binder", "Une citation sur les classeurs", TextHandler.TEXT_MEDIA, "[Media:0]", null, 10, author);
    dbInstance.commitAndCloseSession();
    MediaPart mediaPart = new MediaPart();
    mediaPart.setMedia(media);
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, mediaPart);
    dbInstance.commitAndCloseSession();
    // reload
    List<BinderPageUsage> binders = mediaDao.usedInBinders(media);
    Assert.assertNotNull(binders);
    Assert.assertEquals(1, binders.size());
    Assert.assertTrue(binders.get(0).getBinderKey().equals(binder.getKey()));
}
Also used : Binder(org.olat.modules.portfolio.Binder) MediaPart(org.olat.modules.portfolio.model.MediaPart) BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) Media(org.olat.modules.portfolio.Media) Page(org.olat.modules.portfolio.Page) Identity(org.olat.core.id.Identity) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) Test(org.junit.Test)

Aggregations

PageBody (org.olat.modules.portfolio.PageBody)26 Test (org.junit.Test)14 Page (org.olat.modules.portfolio.Page)14 Section (org.olat.modules.portfolio.Section)8 HTMLPart (org.olat.modules.portfolio.model.HTMLPart)8 Identity (org.olat.core.id.Identity)6 PagePart (org.olat.modules.portfolio.PagePart)6 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)6 TitlePart (org.olat.modules.portfolio.model.TitlePart)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 EvaluationFormSession (org.olat.modules.forms.EvaluationFormSession)4 EvaluationFormController (org.olat.modules.forms.ui.EvaluationFormController)4 Assignment (org.olat.modules.portfolio.Assignment)4 PortfolioService (org.olat.modules.portfolio.PortfolioService)4 EvaluationFormPart (org.olat.modules.portfolio.model.EvaluationFormPart)4 MultiEvaluationFormController (org.olat.modules.portfolio.ui.MultiEvaluationFormController)4 File (java.io.File)2 BigDecimal (java.math.BigDecimal)2 Path (java.nio.file.Path)2 PersistenceHelper.makeFuzzyQueryString (org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString)2