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