use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class BinderDAO method deleteSection.
public Binder deleteSection(Binder binder, Section section) {
List<Page> pages = new ArrayList<>(section.getPages());
// delete pages
for (Page page : pages) {
if (page != null) {
pageDao.deletePage(page);
pageUserInfosDao.delete(page);
section.getPages().remove(page);
}
}
List<Assignment> assignments = assignmentDao.loadAssignments(section, null);
for (Assignment assignment : assignments) {
assignmentDao.deleteAssignmentReference(assignment);
}
assignmentDao.deleteAssignmentBySection(section);
assessmentSectionDao.deleteAssessmentSections(section);
// remove reference via template
String sb = "update pfsection section set section.templateReference=null where section.templateReference.key=:sectionKey";
dbInstance.getCurrentEntityManager().createQuery(sb).setParameter("sectionKey", section.getKey()).executeUpdate();
((BinderImpl) binder).getSections().remove(section);
dbInstance.getCurrentEntityManager().remove(section);
return dbInstance.getCurrentEntityManager().merge(binder);
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class BinderDAO method syncWithTemplate.
public Binder syncWithTemplate(BinderImpl template, BinderImpl binder, AtomicBoolean changes) {
binder.setImagePath(template.getImagePath());
binder.setSummary(template.getSummary());
List<Section> templateSections = template.getSections();
Map<Assignment, Section> assignmentTemplateToSectionTemplatesMap = new HashMap<>();
for (Section templateSection : templateSections) {
for (Assignment assignment : templateSection.getAssignments()) {
assignmentTemplateToSectionTemplatesMap.put(assignment, templateSection);
}
}
List<Section> currentSections = binder.getSections();
List<Section> leadingSections = new ArrayList<>(binder.getSections());
Map<Section, Section> templateToSectionsMap = new HashMap<>();
for (Section currentSection : currentSections) {
Section templateRef = currentSection.getTemplateReference();
if (templateRef != null) {
templateToSectionsMap.put(templateRef, currentSection);
}
}
currentSections.clear();
for (int i = 0; i < templateSections.size(); i++) {
SectionImpl templateSection = (SectionImpl) templateSections.get(i);
SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
if (currentSection != null) {
leadingSections.remove(currentSection);
currentSections.add(currentSection);
syncSectionMetadata(templateSection, currentSection);
templateToSectionsMap.put(templateSection, currentSection);
} else {
SectionImpl section = createInternalSection(binder, templateSection);
currentSections.add(section);
dbInstance.getCurrentEntityManager().persist(section);
templateToSectionsMap.put(templateSection, section);
}
}
currentSections.addAll(leadingSections);
// sync moving assignments
for (int i = 0; i < templateSections.size(); i++) {
SectionImpl templateSection = (SectionImpl) templateSections.get(i);
SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
syncMovingAssignments(templateSection, currentSection, templateToSectionsMap);
}
// sync assignments
for (int i = 0; i < templateSections.size(); i++) {
SectionImpl templateSection = (SectionImpl) templateSections.get(i);
SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
syncAssignments(templateSection, currentSection);
}
// update all sections
for (int i = 0; i < templateSections.size(); i++) {
SectionImpl templateSection = (SectionImpl) templateSections.get(i);
SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
currentSection = dbInstance.getCurrentEntityManager().merge(currentSection);
}
binder = dbInstance.getCurrentEntityManager().merge(binder);
changes.set(true);
return binder;
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class BinderDAO method syncMovingAssignments.
private void syncMovingAssignments(SectionImpl templateSection, SectionImpl currentSection, Map<Section, Section> templateToSectionsMap) {
List<Assignment> templateAssignments = new ArrayList<>(templateSection.getAssignments());
for (Iterator<Assignment> currentAssignmentIt = currentSection.getAssignments().iterator(); currentAssignmentIt.hasNext(); ) {
if (currentAssignmentIt.next() == null) {
currentAssignmentIt.remove();
}
}
List<Assignment> currentAssignments = new ArrayList<>(currentSection.getAssignments());
for (int i = 0; i < currentAssignments.size(); i++) {
Assignment currentAssignment = currentAssignments.get(i);
if (currentAssignment == null) {
currentSection.getAssignments().remove(i);
} else {
Assignment refAssignment = currentAssignment.getTemplateReference();
if (refAssignment != null && !templateAssignments.contains(refAssignment) && !refAssignment.getSection().equals(templateSection) && templateToSectionsMap.containsKey(refAssignment.getSection())) {
// really moved
templateAssignments.remove(refAssignment);
SectionImpl newSection = (SectionImpl) templateToSectionsMap.get(refAssignment.getSection());
syncMovedAssignment(currentSection, newSection, currentAssignment);
}
}
}
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class BinderDAO method syncAssignments.
private void syncAssignments(SectionImpl templateSection, SectionImpl currentSection) {
List<Assignment> templateAssignments = new ArrayList<>(templateSection.getAssignments());
List<Assignment> currentAssignments = new ArrayList<>(currentSection.getAssignments());
for (Assignment currentAssignment : currentAssignments) {
if (currentAssignment == null) {
log.error("Missing assignment: " + currentSection.getKey());
continue;
}
Assignment refAssignment = currentAssignment.getTemplateReference();
if (refAssignment == null) {
if (currentAssignment.getAssignmentStatus() != AssignmentStatus.deleted) {
currentAssignment.setAssignmentStatus(AssignmentStatus.deleted);
currentAssignment = dbInstance.getCurrentEntityManager().merge(currentAssignment);
}
} else if (!templateAssignments.contains(refAssignment)) {
// this case is normally not possible
// if it happens, don't do anything, let the data safe
} else {
templateAssignments.remove(refAssignment);
AssignmentImpl currentImpl = (AssignmentImpl) currentAssignment;
currentAssignment = syncAssignment(refAssignment, currentImpl);
}
}
for (Assignment templateAssignment : templateAssignments) {
if (templateAssignment != null) {
assignmentDao.createAssignment(templateAssignment, AssignmentStatus.notStarted, currentSection);
}
}
}
use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.
the class MyPageListController method loadModel.
@Override
protected void loadModel(UserRequest ureq, String searchString) {
Map<Long, Long> numberOfCommentsMap = portfolioService.getNumberOfCommentsOnOwnedPage(getIdentity());
List<CategoryToElement> categorizedElements = portfolioService.getCategorizedOwnedPages(getIdentity());
Map<OLATResourceable, List<Category>> categorizedElementMap = 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());
}
List<Assignment> assignments = portfolioService.searchOwnedAssignments(getIdentity());
Map<Page, List<Assignment>> pageToAssignments = new HashMap<>();
for (Assignment assignment : assignments) {
Page page = assignment.getPage();
List<Assignment> assignmentList;
if (pageToAssignments.containsKey(page)) {
assignmentList = pageToAssignments.get(page);
} else {
assignmentList = new ArrayList<>();
pageToAssignments.put(page, assignmentList);
}
assignmentList.add(assignment);
}
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary");
List<Page> pages = portfolioService.searchOwnedPages(getIdentity(), searchString);
List<PortfolioElementRow> rows = new ArrayList<>(pages.size());
List<TimelinePoint> points = new ArrayList<>(pages.size());
for (Page page : pages) {
if (page.getPageStatus() == PageStatus.deleted) {
continue;
}
List<Assignment> assignmentList = pageToAssignments.get(page);
PortfolioElementRow row = forgePageRow(ureq, page, null, assignmentList, categorizedElementMap, numberOfCommentsMap, true);
rows.add(row);
if (page.getSection() != null) {
Section section = page.getSection();
row.setMetaSectionTitle(section.getTitle());
if (section.getBinder() != null) {
row.setMetaBinderTitle(section.getBinder().getTitle());
}
}
row.setNewFloatingEntryLink(newEntryButton);
String s = page.getPageStatus() == null ? "draft" : page.getPageStatus().name();
points.add(new TimelinePoint(page.getKey().toString(), page.getTitle(), page.getCreationDate(), s));
}
timelineEl.setPoints(points);
// clean up the posters
disposeRows();
model.setObjects(rows);
tableEl.reset();
tableEl.reloadData();
}
Aggregations