use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method syncBinder_move.
@Test
public void syncBinder_move() {
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 sectionRef0 = portfolioService.getSections(templateBinder).get(0);
// add 2 sections
SectionRef sectionRef1 = portfolioService.appendNewSection("1 section ", "Section 1", null, null, templateBinder);
SectionRef sectionRef2 = portfolioService.appendNewSection("2 section ", "Section 2", null, null, templateBinder);
dbInstance.commit();
// make 4 assigments
Section templateSection0 = portfolioService.getSection(sectionRef0);
Section templateSection1 = portfolioService.getSection(sectionRef1);
Section templateSection2 = portfolioService.getSection(sectionRef2);
Assignment assignment1_1 = portfolioService.addAssignment("1.1 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment1_2 = portfolioService.addAssignment("1.2 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment2_1 = portfolioService.addAssignment("2.1 Assignment", "", "", AssignmentType.essay, templateSection2, false, false, false, null);
Assignment assignment2_2 = portfolioService.addAssignment("2.2 Assignment", "", "", AssignmentType.essay, templateSection2, false, false, false, null);
dbInstance.commit();
List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
Assert.assertEquals(4, templateAssignments.size());
// a user take the binder and synched it a first time
Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "72", null);
dbInstance.commit();
SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(synchedBinder);
Assert.assertEquals(binder, synchedBinder.getBinder());
// start all assigments
List<Assignment> assignments = portfolioService.getAssignments(binder, null);
Assert.assertEquals(4, assignments.size());
for (Assignment assignment : assignments) {
portfolioService.startAssignment(assignment.getKey(), id);
dbInstance.commit();
}
dbInstance.commit();
List<Page> pages = portfolioService.getPages(binder, null);
Assert.assertEquals(4, pages.size());
// the author move an assigment
portfolioService.moveAssignment(templateSection1, assignment1_1, templateSection2);
dbInstance.commit();
portfolioService.moveAssignment(templateSection2, assignment2_1, templateSection1);
dbInstance.commitAndCloseSession();
// check the move
List<Assignment> templateAssignmentsSection1 = portfolioService.getAssignments(templateSection1, null);
Assert.assertTrue(templateAssignmentsSection1.contains(assignment1_2));
Assert.assertTrue(templateAssignmentsSection1.contains(assignment2_1));
List<Assignment> templateAssignmentsSection2 = portfolioService.getAssignments(templateSection2, null);
Assert.assertTrue(templateAssignmentsSection2.contains(assignment2_2));
Assert.assertTrue(templateAssignmentsSection2.contains(assignment1_1));
// synched and check the sections order
SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
Binder freshBinder = synchedBinder2.getBinder();
List<Section> sections = portfolioService.getSections(freshBinder);
Assert.assertEquals(3, sections.size());
Section section0 = sections.get(0);
Section section1 = sections.get(1);
Section section2 = sections.get(2);
Assert.assertEquals(templateSection0, section0.getTemplateReference());
Assert.assertEquals(templateSection1, section1.getTemplateReference());
Assert.assertEquals(templateSection2, section2.getTemplateReference());
// load pages from section 1
List<Page> pagesSection1 = portfolioService.getPages(section1);
Assert.assertEquals(2, pagesSection1.size());
Page page1_2 = pagesSection1.get(0);
Page page2_1 = pagesSection1.get(1);
Assert.assertTrue(page1_2.getTitle().equals("2.1 Assignment") || page1_2.getTitle().equals("1.2 Assignment"));
Assert.assertTrue(page2_1.getTitle().equals("2.1 Assignment") || page2_1.getTitle().equals("1.2 Assignment"));
// and pages from section 2
List<Page> pagesSection2 = portfolioService.getPages(section2);
Assert.assertEquals(2, pagesSection2.size());
Page page2_2 = pagesSection2.get(0);
Page page1_1 = pagesSection2.get(1);
Assert.assertTrue(page2_2.getTitle().equals("1.1 Assignment") || page2_2.getTitle().equals("2.2 Assignment"));
Assert.assertTrue(page1_1.getTitle().equals("1.1 Assignment") || page1_1.getTitle().equals("2.2 Assignment"));
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class AssignmentDAOTest method loadAssignments_section.
@Test
public void loadAssignments_section() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("assign-4");
Binder binder = portfolioService.createNewBinder("Assignment binder 4", "Difficult!", null, owner);
dbInstance.commit();
portfolioService.appendNewSection("Section", "Assignment section", null, null, binder);
dbInstance.commit();
// create assignment
List<Section> sections = portfolioService.getSections(binder);
Section section = sections.get(0);
Assignment assignment = assignmentDao.createAssignment("Load assignment", "Load by section", "The another content", null, AssignmentType.essay, AssignmentStatus.template, section, false, false, false, null);
dbInstance.commitAndCloseSession();
// load the assignment
List<Assignment> assignments = assignmentDao.loadAssignments(section, null);
Assert.assertNotNull(assignments);
Assert.assertEquals(1, assignments.size());
Assert.assertEquals(assignment, assignments.get(0));
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class AssignmentDAOTest method loadAssignments_section_search.
@Test
public void loadAssignments_section_search() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("assign-5");
Binder binder = portfolioService.createNewBinder("Assignment binder 5", "Difficult!", null, owner);
dbInstance.commit();
portfolioService.appendNewSection("Section", "Assignment section", null, null, binder);
dbInstance.commit();
// create assignment
List<Section> sections = portfolioService.getSections(binder);
Section section = sections.get(0);
Assignment assignment = assignmentDao.createAssignment("Load assignment", "Load by binder", "The little blabla to search", null, AssignmentType.essay, AssignmentStatus.template, section, false, false, false, null);
dbInstance.commitAndCloseSession();
// search the assignment
List<Assignment> assignments = assignmentDao.loadAssignments(section, "blabla");
Assert.assertNotNull(assignments);
Assert.assertEquals(1, assignments.size());
Assert.assertEquals(assignment, assignments.get(0));
// dummy search
List<Assignment> emptyAssignments = assignmentDao.loadAssignments(section, "wezruiwezi");
Assert.assertNotNull(emptyAssignments);
Assert.assertEquals(0, emptyAssignments.size());
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class AbstractPageListController method doMoveUpAssignment.
private void doMoveUpAssignment(UserRequest ureq, PortfolioElementRow row) {
Assignment assigment = row.getAssignment();
Section section = assigment.getSection();
section = portfolioService.moveUpAssignment(section, assigment);
loadModel(ureq, null);
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class AbstractPageListController method doDelete.
private void doDelete(PortfolioElementRow row) {
if (row.isPendingAssignment()) {
Assignment assignment = row.getAssignment();
portfolioService.deleteAssignment(assignment);
}
}
Aggregations