Search in sources :

Example 11 with SectionImpl

use of org.olat.modules.portfolio.model.SectionImpl in project OpenOLAT by OpenOLAT.

the class PortfolioServiceImpl method changePageStatus.

@Override
public Page changePageStatus(Page page, PageStatus status, Identity identity, Role by) {
    PageStatus currentStatus = page.getPageStatus();
    Page reloadedPage = pageDao.loadByKey(page.getKey());
    ((PageImpl) reloadedPage).setPageStatus(status);
    if (status == PageStatus.published) {
        Date now = new Date();
        if (reloadedPage.getInitialPublicationDate() == null) {
            ((PageImpl) reloadedPage).setInitialPublicationDate(now);
        }
        ((PageImpl) reloadedPage).setLastPublicationDate(now);
        Section section = reloadedPage.getSection();
        // auto update the status of the evaluation form of the authors of the binder
        changeAssignmentStatus(page, section, EvaluationFormSessionStatus.done);
        if (section != null) {
            SectionStatus sectionStatus = section.getSectionStatus();
            if (currentStatus == PageStatus.closed) {
                if (sectionStatus == SectionStatus.closed) {
                    ((SectionImpl) section).setSectionStatus(SectionStatus.inProgress);
                    binderDao.updateSection(section);
                }
            } else if (sectionStatus == null || sectionStatus == SectionStatus.notStarted || sectionStatus == SectionStatus.closed) {
                ((SectionImpl) section).setSectionStatus(SectionStatus.inProgress);
                binderDao.updateSection(section);
            }
        }
    } else if (status == PageStatus.inRevision) {
        Section section = reloadedPage.getSection();
        changeAssignmentStatus(page, section, EvaluationFormSessionStatus.inProgress);
        if (section != null) {
            SectionStatus sectionStatus = section.getSectionStatus();
            if (sectionStatus == null || sectionStatus == SectionStatus.notStarted || sectionStatus == SectionStatus.closed) {
                if (sectionStatus == SectionStatus.closed) {
                    ((SectionImpl) section).setSectionStatus(SectionStatus.inProgress);
                    binderDao.updateSection(section);
                }
            }
        }
        pageUserInfosDao.updateStatus(reloadedPage, PageUserStatus.inProcess, PageUserStatus.done);
    } else if (status == PageStatus.closed) {
        // set user informations to done
        pageUserInfosDao.updateStatus(reloadedPage, PageUserStatus.done);
    }
    if (reloadedPage.getSection() != null && reloadedPage.getSection().getBinder() != null) {
        Binder binder = reloadedPage.getSection().getBinder();
        updateAssessmentEntryLastModification(binder, identity, by);
    }
    return pageDao.updatePage(reloadedPage);
}
Also used : PageImpl(org.olat.modules.portfolio.model.PageImpl) Binder(org.olat.modules.portfolio.Binder) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) PageStatus(org.olat.modules.portfolio.PageStatus) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) Page(org.olat.modules.portfolio.Page) SectionStatus(org.olat.modules.portfolio.SectionStatus) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) SectionImpl(org.olat.modules.portfolio.model.SectionImpl) AssessmentSectionImpl(org.olat.modules.portfolio.model.AssessmentSectionImpl) Date(java.util.Date)

Example 12 with SectionImpl

use of org.olat.modules.portfolio.model.SectionImpl in project OpenOLAT by OpenOLAT.

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;
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) Binder(org.olat.modules.portfolio.Binder) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) SectionImpl(org.olat.modules.portfolio.model.SectionImpl) AssessmentSectionImpl(org.olat.modules.portfolio.model.AssessmentSectionImpl) File(java.io.File)

Example 13 with SectionImpl

use of org.olat.modules.portfolio.model.SectionImpl 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 14 with SectionImpl

use of org.olat.modules.portfolio.model.SectionImpl in project OpenOLAT by OpenOLAT.

the class BinderDAO method createInternalSection.

private SectionImpl createInternalSection(Binder binder, Section templateSection) {
    SectionImpl section = new SectionImpl();
    section.setCreationDate(new Date());
    section.setLastModified(section.getCreationDate());
    section.setBaseGroup(groupDao.createGroup());
    section.setTitle(templateSection.getTitle());
    section.setDescription(templateSection.getDescription());
    section.setBeginDate(templateSection.getBeginDate());
    section.setEndDate(templateSection.getEndDate());
    section.setOverrideBeginEndDates(false);
    section.setStatus(SectionStatus.notStarted.name());
    section.setBinder(binder);
    section.setTemplateReference(templateSection);
    return section;
}
Also used : SectionImpl(org.olat.modules.portfolio.model.SectionImpl) Date(java.util.Date)

Example 15 with SectionImpl

use of org.olat.modules.portfolio.model.SectionImpl 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)

Aggregations

SectionImpl (org.olat.modules.portfolio.model.SectionImpl)20 Section (org.olat.modules.portfolio.Section)12 AssessmentSectionImpl (org.olat.modules.portfolio.model.AssessmentSectionImpl)12 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)10 Assignment (org.olat.modules.portfolio.Assignment)8 Date (java.util.Date)6 Binder (org.olat.modules.portfolio.Binder)6 Page (org.olat.modules.portfolio.Page)6 AssessedBinder (org.olat.modules.portfolio.model.AssessedBinder)6 AssessedPage (org.olat.modules.portfolio.model.AssessedPage)6 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)6 ArrayList (java.util.ArrayList)4 PageStatus (org.olat.modules.portfolio.PageStatus)4 PageImpl (org.olat.modules.portfolio.model.PageImpl)4 File (java.io.File)2 HashMap (java.util.HashMap)2 SectionStatus (org.olat.modules.portfolio.SectionStatus)2 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)2 SectionKeyRef (org.olat.modules.portfolio.model.SectionKeyRef)2