Skip to content
Snippets Groups Projects
Commit 5a4fe701 authored by srosse's avatar srosse
Browse files

Merge OpenOLAT 11.4 to OpenOLAT default branch with c357e3e87c802556ee030460f017c39c34216765

parents 47785913 6c6d4d7e
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ import org.olat.core.id.Identity;
import org.olat.modules.portfolio.AssessmentSection;
import org.olat.modules.portfolio.BinderRef;
import org.olat.modules.portfolio.Section;
import org.olat.modules.portfolio.SectionRef;
import org.olat.modules.portfolio.model.AssessmentSectionImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -101,7 +102,7 @@ public class AssessmentSectionDAO {
return dbInstance.getCurrentEntityManager().merge(assessmentSection);
}
public int deleteAssessmentSections(Section section) {
public int deleteAssessmentSections(SectionRef section) {
String partQ = "delete from pfassessmentsection asection where asection.section.key=:sectionKey";
return dbInstance.getCurrentEntityManager()
.createQuery(partQ)
......
......@@ -567,10 +567,11 @@ public class BinderDAO {
}
public Binder deleteSection(Binder binder, Section section) {
List<Page> pages = section.getPages();
List<Page> pages = new ArrayList<>(section.getPages());
//delete pages
for(Page page:pages) {
pageDao.deletePage(page);
section.getPages().remove(page);
}
List<Assignment> assignments = new ArrayList<>(((SectionImpl)section).getAssignments());
......
......@@ -19,6 +19,7 @@
*/
package org.olat.modules.portfolio.manager;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
......@@ -896,4 +897,49 @@ public class PortfolioServiceTest extends OlatTestCase {
Page reloadedStartedPage_2 = pageDao.loadByKey(startedPageKey_2);
Assert.assertNull(reloadedStartedPage_2);
}
@Test
public void deleteSectionWithPages() {
// prepare a binder with 2 sections and some pages
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("del-binder-");
Binder binder = portfolioService.createNewBinder("Binder to delete", "Deletion", "", owner);
SectionRef sectionRef1 = portfolioService.appendNewSection("1. section ", "Section 1", null, null, binder);
dbInstance.commit();
SectionRef sectionRef2 = portfolioService.appendNewSection("2. section ", "Section 2", null, null, binder);
dbInstance.commit();
portfolioService.updateBinderUserInformations(binder, owner);
dbInstance.commit();
Section reloadedSection1 = portfolioService.getSection(sectionRef1);
List<Page> pagesSection1 = new ArrayList<>();
for(int i=0; i<10; i++) {
Page page = portfolioService.appendNewPage(owner, "New page", "A brand new page.", null, null, reloadedSection1);
pagesSection1.add(page);
}
Section reloadedSection2 = portfolioService.getSection(sectionRef2);
Page page2 = portfolioService.appendNewPage(owner, "New page", "A brand new page.", null, null, reloadedSection2);
Assert.assertNotNull(page2);
dbInstance.commitAndCloseSession();
// delete the section
portfolioService.deleteSection(binder, reloadedSection1);
dbInstance.commit();
//check if section 2 is still around
Section section2 = binderDao.loadSectionByKey(sectionRef2.getKey());
Assert.assertEquals(reloadedSection2, section2);
Page reloadedPage2 = pageDao.loadByKey(page2.getKey());
Assert.assertNotNull(reloadedPage2);
Assert.assertEquals(page2, reloadedPage2);
// check if section 1 is deleted
Section deletedSection1 = binderDao.loadSectionByKey(sectionRef1.getKey());
Assert.assertNull(deletedSection1);
for(Page pageSection1:pagesSection1) {
Page deletedPage = pageDao.loadByKey(pageSection1.getKey());
Assert.assertNull(deletedPage);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment