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