use of org.olat.modules.portfolio.Assignment in project openolat by klemens.
the class PortfolioServiceTest method syncBinder_moveAssignmentsInSection_multiple.
@Test
public void syncBinder_moveAssignmentsInSection_multiple() {
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 sectionRef1 = portfolioService.getSections(templateBinder).get(0);
dbInstance.commit();
// make 4 assignments
Section templateSection1 = portfolioService.getSection(sectionRef1);
Assignment assignment_1_1 = portfolioService.addAssignment("1.1 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment_1_2 = portfolioService.addAssignment("1.2 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment_1_3 = portfolioService.addAssignment("1.3 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment_1_4 = portfolioService.addAssignment("1.4 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment_1_5 = portfolioService.addAssignment("1.5 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
Assignment assignment_1_6 = portfolioService.addAssignment("1.6 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
dbInstance.commit();
List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
Assert.assertEquals(6, templateAssignments.size());
// a user take the binder and synched it a first time
Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "74", null);
dbInstance.commit();
SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(synchedBinder);
Assert.assertEquals(binder, synchedBinder.getBinder());
// start all assignments
List<Assignment> assignments = portfolioService.getAssignments(binder, null);
Assert.assertEquals(6, assignments.size());
for (Assignment assignment : assignments) {
portfolioService.startAssignment(assignment.getKey(), id);
dbInstance.commit();
}
dbInstance.commit();
// check that the student has it's 8 pages
List<Page> pages = portfolioService.getPages(binder, null);
Assert.assertEquals(6, pages.size());
dbInstance.commit();
// synched and check the sections order
SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
Binder freshBinder = synchedBinder2.getBinder();
dbInstance.commitAndCloseSession();
// ooops, someone deleted the assignment (simulate jump in the numbering of the list)
List<Section> sections = portfolioService.getSections(freshBinder);
List<Assignment> firstSectionAssignments = portfolioService.getAssignments(sections.get(0), null);
dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(1));
dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(2));
dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(3));
dbInstance.getCurrentEntityManager().remove(firstSectionAssignments.get(5));
dbInstance.commit();
List<Assignment> firstSectionDeletedAssignments = portfolioService.getAssignments(sections.get(0), null);
Assert.assertEquals(2, firstSectionDeletedAssignments.size());
// synched and check the sections order
SynchedBinder synchedBinder3 = portfolioService.loadAndSyncBinder(binder);
Binder freshBinder3 = synchedBinder3.getBinder();
dbInstance.commitAndCloseSession();
Assert.assertNotNull(freshBinder3);
List<Assignment> firstSectionAssignmentResynched = portfolioService.getAssignments(sections.get(0), null);
List<Assignment> templateAssignmentsSynched = new ArrayList<>();
Assert.assertEquals(6, firstSectionAssignmentResynched.size());
for (Assignment firstSectionAssignment : firstSectionAssignmentResynched) {
Assert.assertEquals(firstSectionAssignment.getTitle(), firstSectionAssignment.getTemplateReference().getTitle());
templateAssignmentsSynched.add(firstSectionAssignment.getTemplateReference());
}
Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_1));
Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_2));
Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_3));
Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_4));
Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_5));
Assert.assertTrue(templateAssignmentsSynched.contains(assignment_1_6));
}
use of org.olat.modules.portfolio.Assignment in project openolat by klemens.
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 klemens.
the class AssignmentDAOTest method loadAssignments_binder_search.
@Test
public void loadAssignments_binder_search() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("assign-3");
Binder binder = portfolioService.createNewBinder("Assignment binder 3", "Difficult!", null, owner);
dbInstance.commit();
portfolioService.appendNewSection("Section", "Assignment section", null, null, binder);
dbInstance.commit();
// create assignment
List<Section> sections = portfolioService.getSections(binder);
Assignment assignment = assignmentDao.createAssignment("Load assignment", "Load by binder", "The content unkown search", null, AssignmentType.essay, AssignmentStatus.template, sections.get(0), false, false, false, null);
dbInstance.commitAndCloseSession();
// search the assignment
List<Assignment> assignments = assignmentDao.loadAssignments(binder, "unkown");
Assert.assertNotNull(assignments);
Assert.assertEquals(1, assignments.size());
Assert.assertEquals(assignment, assignments.get(0));
// dummy search
List<Assignment> emptyAssignments = assignmentDao.loadAssignments(binder, "sdhfks");
Assert.assertNotNull(emptyAssignments);
Assert.assertEquals(0, emptyAssignments.size());
}
use of org.olat.modules.portfolio.Assignment in project openolat by klemens.
the class BinderPageListController method loadModel.
@Override
protected void loadModel(UserRequest ureq, String searchString) {
if (StringHelper.containsNonWhitespace(binder.getSummary())) {
summaryComp.setText(binder.getSummary());
flc.getFormItemComponent().put("summary", summaryCtrl.getInitialComponent());
} else {
flc.getFormItemComponent().remove("summary");
}
List<Section> sections = portfolioService.getSections(binder);
List<CategoryToElement> categorizedElements = portfolioService.getCategorizedSectionsAndPages(binder);
Map<OLATResourceable, List<Category>> categorizedElementMap = new HashMap<>();
Map<Section, Set<String>> sectionAggregatedCategoriesMap = new HashMap<>();
for (CategoryToElement categorizedElement : categorizedElements) {
List<Category> categories = categorizedElementMap.get(categorizedElement.getCategorizedResource());
if (categories == null) {
categories = new ArrayList<>();
categorizedElementMap.put(categorizedElement.getCategorizedResource(), categories);
}
categories.add(categorizedElement.getCategory());
}
// comments
Map<Long, Long> numberOfCommentsMap = portfolioService.getNumberOfComments(binder);
// assessment sections
List<AssessmentSection> assessmentSections = portfolioService.getAssessmentSections(binder, getIdentity());
Map<Section, AssessmentSection> sectionToAssessmentSectionMap = assessmentSections.stream().collect(Collectors.toMap(as -> as.getSection(), as -> as));
List<PortfolioElementRow> rows = new ArrayList<>();
// assignments
List<Assignment> assignments = portfolioService.getAssignments(binder, searchString);
Map<Section, List<Assignment>> sectionToAssignmentMap = new HashMap<>();
for (Assignment assignment : assignments) {
List<Assignment> assignmentList;
Section section = assignment.getSection();
if (sectionToAssignmentMap.containsKey(section)) {
assignmentList = sectionToAssignmentMap.get(section);
} else {
assignmentList = new ArrayList<>();
sectionToAssignmentMap.put(section, assignmentList);
}
assignmentList.add(assignment);
}
for (Assignment assignment : assignments) {
Section section = assignment.getSection();
if (assignment.getPage() == null && secCallback.canViewPendingAssignments(section)) {
List<Assignment> sectionAssignments = sectionToAssignmentMap.get(section);
PortfolioElementRow row = forgePendingAssignmentRow(assignment, section, sectionAssignments);
rows.add(row);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(row);
row.setNewEntryLink(newEntryButton);
}
}
}
boolean userInfos = secCallback.canPageUserInfosStatus();
Map<Long, PageUserInformations> userInfosToPage = new HashMap<>();
rowVC.contextPut("userInfos", Boolean.valueOf(userInfos));
if (userInfos) {
rowVC.contextPut("userInfosRenderer", new SharedPageStatusCellRenderer(getTranslator()));
List<PageUserInformations> userInfoList = portfolioService.getPageUserInfos(binder, getIdentity());
for (PageUserInformations userInfo : userInfoList) {
userInfosToPage.put(userInfo.getPage().getKey(), userInfo);
}
}
List<Page> pages = portfolioService.getPages(binder, searchString);
for (Page page : pages) {
boolean viewElement = secCallback.canViewElement(page);
boolean viewTitleElement = viewElement || secCallback.canViewTitleOfElement(page);
if (!viewTitleElement) {
continue;
}
Section section = page.getSection();
PortfolioElementRow pageRow = forgePageRow(ureq, page, sectionToAssessmentSectionMap.get(section), sectionToAssignmentMap.get(section), categorizedElementMap, numberOfCommentsMap, viewElement);
rows.add(pageRow);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(pageRow);
pageRow.setNewEntryLink(newEntryButton);
}
if (secCallback.canNewAssignment() && section != null) {
FormLink newAssignmentButton = uifactory.addFormLink("new.assignment." + (++counter), "new.assignment", "create.new.assignment", null, flc, Link.BUTTON);
newAssignmentButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_assignment");
newAssignmentButton.setUserObject(pageRow);
pageRow.setNewAssignmentLink(newAssignmentButton);
}
if (userInfos) {
PageUserInformations infos = userInfosToPage.get(page.getKey());
if (infos != null) {
pageRow.setUserInfosStatus(infos.getStatus());
}
}
if (section != null) {
Set<String> categories = sectionAggregatedCategoriesMap.get(section);
if (categories == null) {
categories = new HashSet<>();
sectionAggregatedCategoriesMap.put(section, categories);
}
if (pageRow.getPageCategories() != null && pageRow.getPageCategories().size() > 0) {
categories.addAll(pageRow.getPageCategories());
}
pageRow.setSectionCategories(categories);
}
}
// sections without pages
if (!StringHelper.containsNonWhitespace(searchString)) {
for (Section section : sections) {
if (!secCallback.canViewElement(section)) {
continue;
}
PortfolioElementRow sectionRow = forgeSectionRow(section, sectionToAssessmentSectionMap.get(section), sectionToAssignmentMap.get(section), categorizedElementMap);
rows.add(sectionRow);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(sectionRow);
sectionRow.setNewEntryLink(newEntryButton);
}
if (secCallback.canNewAssignment() && section != null) {
FormLink newAssignmentButton = uifactory.addFormLink("new.assignment." + (++counter), "new.assignment", "create.new.assignment", null, flc, Link.BUTTON);
newAssignmentButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_assignment");
newAssignmentButton.setUserObject(sectionRow);
sectionRow.setNewAssignmentLink(newAssignmentButton);
}
}
}
if (newSectionButton != null && rows.isEmpty()) {
flc.add("create.new.section", newSectionButton);
} else if (newSectionButton != null) {
flc.remove(newSectionButton);
}
if (newEntryLink != null && !newEntryLink.isVisible()) {
newEntryLink.setVisible(rows.size() > 0);
stackPanel.setDirty(true);
}
if (newAssignmentLink != null && !newAssignmentLink.isVisible()) {
newAssignmentLink.setVisible(rows.size() > 0);
stackPanel.setDirty(true);
}
// clean up the posters
disposeRows();
model.setObjects(rows);
if (filteringSection != null) {
doFilterSection(filteringSection);
} else {
tableEl.reloadData();
updateTimeline();
}
}
use of org.olat.modules.portfolio.Assignment in project openolat by klemens.
the class PortfolioServiceImpl method internalCopyTransientBinder.
private Binder internalCopyTransientBinder(Binder transientBinder, RepositoryEntry entry, String imagePath, boolean copy) {
Binder binder = binderDao.createAndPersist(transientBinder.getTitle(), transientBinder.getSummary(), imagePath, entry);
// copy sections
for (Section transientSection : ((BinderImpl) transientBinder).getSections()) {
SectionImpl section = binderDao.createSection(transientSection.getTitle(), transientSection.getDescription(), transientSection.getBeginDate(), transientSection.getEndDate(), binder);
List<Assignment> transientAssignments = ((SectionImpl) transientSection).getAssignments();
for (Assignment transientAssignment : transientAssignments) {
if (transientAssignment != null) {
File newStorage = portfolioFileStorage.generateAssignmentSubDirectory();
String storage = portfolioFileStorage.getRelativePath(newStorage);
assignmentDao.createAssignment(transientAssignment.getTitle(), transientAssignment.getSummary(), transientAssignment.getContent(), storage, transientAssignment.getAssignmentType(), transientAssignment.getAssignmentStatus(), section, transientAssignment.isOnlyAutoEvaluation(), transientAssignment.isReviewerSeeAutoEvaluation(), transientAssignment.isAnonymousExternalEvaluation(), transientAssignment.getFormEntry());
// copy attachments
File templateDirectory = portfolioFileStorage.getAssignmentDirectory(transientAssignment);
if (copy && templateDirectory != null) {
FileUtils.copyDirContentsToDir(templateDirectory, newStorage, false, "Assignment attachments");
}
}
}
}
return binder;
}
Aggregations