use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.
the class PortfolioServiceTest method removeAssignment.
@Test
public void removeAssignment() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
dbInstance.commitAndCloseSession();
// make the binder and the section
Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
dbInstance.commit();
// make 4 assignments
Section templateSection = portfolioService.getSection(sectionRef);
Assignment assignment_1 = portfolioService.addAssignment("1 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_2 = portfolioService.addAssignment("2 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_3 = portfolioService.addAssignment("3 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_4 = portfolioService.addAssignment("3 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
dbInstance.commitAndCloseSession();
boolean ok = portfolioService.deleteAssignment(assignment_3);
Assert.assertTrue(ok);
dbInstance.commitAndCloseSession();
List<Assignment> assignments = portfolioService.getSection(sectionRef).getAssignments();
Assert.assertNotNull(assignments);
Assert.assertEquals(3, assignments.size());
Assert.assertTrue(assignments.contains(assignment_1));
Assert.assertTrue(assignments.contains(assignment_2));
Assert.assertFalse(assignments.contains(assignment_3));
Assert.assertTrue(assignments.contains(assignment_4));
}
use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.
the class PortfolioServiceTest method removeAssignment_usedOne.
@Test
public void removeAssignment_usedOne() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-11");
RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
dbInstance.commitAndCloseSession();
// make 2 sections
Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
dbInstance.commit();
// make 4 assignments
Section templateSection = portfolioService.getSection(sectionRef);
Assignment assignment_1 = portfolioService.addAssignment("1 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_2 = portfolioService.addAssignment("2 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_3 = portfolioService.addAssignment("3 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
Assignment assignment_4 = portfolioService.addAssignment("4 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
dbInstance.commit();
List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
Assert.assertEquals(4, templateAssignments.size());
Assert.assertTrue(templateAssignments.contains(assignment_1));
Assert.assertTrue(templateAssignments.contains(assignment_2));
Assert.assertTrue(templateAssignments.contains(assignment_3));
Assert.assertTrue(templateAssignments.contains(assignment_4));
// synched and check the sections order
Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
binder = synchedBinder.getBinder();
dbInstance.commitAndCloseSession();
List<Assignment> assignments = portfolioService.getAssignments(binder, null);
portfolioService.startAssignment(assignments.get(0).getKey(), id);
portfolioService.startAssignment(assignments.get(1).getKey(), id);
portfolioService.startAssignment(assignments.get(2).getKey(), id);
portfolioService.startAssignment(assignments.get(3).getKey(), id);
dbInstance.commit();
List<Section> sections = portfolioService.getSections(binder);
List<Page> pages = portfolioService.getPages(sections.get(0));
Assert.assertEquals(4, pages.size());
// delete an assignment
boolean ok = portfolioService.deleteAssignment(assignment_3);
Assert.assertTrue(ok);
dbInstance.commitAndCloseSession();
// sync the binder
SynchedBinder reSynchedBinder = portfolioService.loadAndSyncBinder(binder);
binder = reSynchedBinder.getBinder();
dbInstance.commitAndCloseSession();
// deleting an assignment doesn't delete the pages
List<Page> allPages = portfolioService.getPages(sections.get(0));
Assert.assertEquals(4, allPages.size());
// sync twice
SynchedBinder reReSynchedBinder = portfolioService.loadAndSyncBinder(binder);
binder = reReSynchedBinder.getBinder();
dbInstance.commitAndCloseSession();
}
use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.
the class RestorePageController method formOK.
@Override
protected void formOK(UserRequest ureq) {
page = portfolioService.changePageStatus(page, PageStatus.draft, getIdentity(), Role.user);
SectionRef selectSection = getSelectedSection();
if ((page.getSection() == null && selectSection != null) || (page.getSection() != null && selectSection != null && !page.getSection().getKey().equals(selectSection.getKey()))) {
page = portfolioService.updatePage(page, selectSection);
}
fireEvent(ureq, Event.DONE_EVENT);
}
use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.
the class PageMetadataEditController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (page == null) {
String title = titleEl.getValue();
String summary = summaryEl.getValue();
SectionRef selectSection = getSelectedSection();
String imagePath = null;
if (imageUpload.getUploadFile() != null) {
imagePath = portfolioService.addPosterImageForPage(imageUpload.getUploadFile(), imageUpload.getUploadFileName());
}
PageImageAlign align = null;
if (imageAlignEl.isOneSelected()) {
align = PageImageAlign.valueOf(imageAlignEl.getSelectedKey());
}
page = portfolioService.appendNewPage(getIdentity(), title, summary, imagePath, align, selectSection);
} else {
page.setTitle(titleEl.getValue());
page.setSummary(summaryEl.getValue());
if (imageUpload.getUploadFile() != null) {
String imagePath = portfolioService.addPosterImageForPage(imageUpload.getUploadFile(), imageUpload.getUploadFileName());
page.setImagePath(imagePath);
} else if (imageUpload.getInitialFile() == null) {
page.setImagePath(null);
portfolioService.removePosterImage(page);
}
SectionRef selectSection = getSelectedSection();
SectionRef newParent = null;
if ((page.getSection() == null && selectSection != null) || (page.getSection() != null && selectSection != null && !page.getSection().getKey().equals(selectSection.getKey()))) {
newParent = selectSection;
}
if (imageAlignEl.isOneSelected()) {
page.setImageAlignment(PageImageAlign.valueOf(imageAlignEl.getSelectedKey()));
}
page = portfolioService.updatePage(page, newParent);
}
List<String> updatedCategories = categoriesEl.getValueList();
portfolioService.updateCategories(page, updatedCategories);
fireEvent(ureq, Event.DONE_EVENT);
}
use of org.olat.modules.portfolio.SectionRef in project openolat by klemens.
the class PageMetadataEditController method getSelectedSection.
private SectionRef getSelectedSection() {
SectionRef selectSection = null;
if (sectionsEl != null && sectionsEl.isOneSelected() && sectionsEl.isEnabled() && sectionsEl.isVisible()) {
String selectedKey = sectionsEl.getSelectedKey();
selectSection = new SectionKeyRef(new Long(selectedKey));
}
return selectSection;
}
Aggregations