Search in sources :

Example 56 with Assignment

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);
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page)

Example 57 with Assignment

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;
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Section(org.olat.modules.portfolio.Section) SectionImpl(org.olat.modules.portfolio.model.SectionImpl)

Example 58 with Assignment

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);
            }
        }
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) ArrayList(java.util.ArrayList) SectionImpl(org.olat.modules.portfolio.model.SectionImpl)

Example 59 with Assignment

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);
        }
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl) ArrayList(java.util.ArrayList)

Example 60 with Assignment

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();
}
Also used : PortfolioElementRow(org.olat.modules.portfolio.ui.model.PortfolioElementRow) Category(org.olat.modules.portfolio.Category) OLATResourceable(org.olat.core.id.OLATResourceable) HashMap(java.util.HashMap) CategoryToElement(org.olat.modules.portfolio.CategoryToElement) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Section(org.olat.modules.portfolio.Section) Assignment(org.olat.modules.portfolio.Assignment) ArrayList(java.util.ArrayList) List(java.util.List) TimelinePoint(org.olat.modules.portfolio.ui.component.TimelinePoint)

Aggregations

Assignment (org.olat.modules.portfolio.Assignment)78 Section (org.olat.modules.portfolio.Section)48 Binder (org.olat.modules.portfolio.Binder)30 Identity (org.olat.core.id.Identity)28 Test (org.junit.Test)26 Page (org.olat.modules.portfolio.Page)26 ArrayList (java.util.ArrayList)24 RepositoryEntry (org.olat.repository.RepositoryEntry)20 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)18 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)18 SectionRef (org.olat.modules.portfolio.SectionRef)16 File (java.io.File)8 HashMap (java.util.HashMap)8 List (java.util.List)8 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 SectionImpl (org.olat.modules.portfolio.model.SectionImpl)8 PortfolioElementRow (org.olat.modules.portfolio.ui.model.PortfolioElementRow)8 Link (org.olat.core.gui.components.link.Link)6