Search in sources :

Example 1 with CheckListExcelExport

use of org.olat.course.nodes.cl.ui.CheckListExcelExport in project OpenOLAT by OpenOLAT.

the class CheckListCourseNode method archiveNodeData.

/**
 * Make an archive of all datas.
 */
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    String dirName = "cl_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    ModuleConfiguration config = getModuleConfiguration();
    CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    if (list != null && list.getList() != null) {
        Set<String> usedNames = new HashSet<>();
        for (Checkbox checkbox : list.getList()) {
            VFSContainer dir = checkboxManager.getFileContainer(course.getCourseEnvironment(), this);
            if (dir != null) {
                VFSItem item = dir.resolve(checkbox.getFilename());
                if (item instanceof VFSLeaf) {
                    String path = dirName + "/" + Formatter.makeStringFilesystemSave(checkbox.getTitle());
                    if (usedNames.contains(checkbox.getTitle())) {
                        path += "_" + checkbox.getCheckboxId();
                    } else {
                        usedNames.add(checkbox.getTitle());
                    }
                    ZipUtil.addToZip(item, path, exportStream);
                }
            }
        }
    }
    String filename = dirName + "/" + StringHelper.transformDisplayNameToFileSystemName(getShortName());
    new CheckListExcelExport(this, course, locale).exportAll(filename, exportStream);
    // assessment documents
    if (hasIndividualAsssessmentDocuments()) {
        List<AssessmentEntry> assessmentEntries = course.getCourseEnvironment().getAssessmentManager().getAssessmentEntries(this);
        if (assessmentEntries != null && !assessmentEntries.isEmpty()) {
            String assessmentDirName = dirName + "/Assessment_documents";
            for (AssessmentEntry assessmentEntry : assessmentEntries) {
                Identity assessedIdentity = assessmentEntry.getIdentity();
                List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
                String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
                String userDirName = assessmentDirName + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
                if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
                    for (File document : assessmentDocuments) {
                        String path = userDirName + "/" + document.getName();
                        ZipUtil.addFileToZip(path, document, exportStream);
                    }
                }
            }
        }
    }
    return super.archiveNodeData(locale, course, options, exportStream, charset);
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ModuleConfiguration(org.olat.modules.ModuleConfiguration) VFSContainer(org.olat.core.util.vfs.VFSContainer) CheckListExcelExport(org.olat.course.nodes.cl.ui.CheckListExcelExport) VFSItem(org.olat.core.util.vfs.VFSItem) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with CheckListExcelExport

use of org.olat.course.nodes.cl.ui.CheckListExcelExport in project openolat by klemens.

the class CheckListCourseNode method archiveNodeData.

/**
 * Make an archive of all datas.
 */
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    String dirName = "cl_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    ModuleConfiguration config = getModuleConfiguration();
    CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    if (list != null && list.getList() != null) {
        Set<String> usedNames = new HashSet<>();
        for (Checkbox checkbox : list.getList()) {
            VFSContainer dir = checkboxManager.getFileContainer(course.getCourseEnvironment(), this);
            if (dir != null) {
                VFSItem item = dir.resolve(checkbox.getFilename());
                if (item instanceof VFSLeaf) {
                    String path = dirName + "/" + Formatter.makeStringFilesystemSave(checkbox.getTitle());
                    if (usedNames.contains(checkbox.getTitle())) {
                        path += "_" + checkbox.getCheckboxId();
                    } else {
                        usedNames.add(checkbox.getTitle());
                    }
                    ZipUtil.addToZip(item, path, exportStream);
                }
            }
        }
    }
    String filename = dirName + "/" + StringHelper.transformDisplayNameToFileSystemName(getShortName());
    new CheckListExcelExport(this, course, locale).exportAll(filename, exportStream);
    // assessment documents
    if (hasIndividualAsssessmentDocuments()) {
        List<AssessmentEntry> assessmentEntries = course.getCourseEnvironment().getAssessmentManager().getAssessmentEntries(this);
        if (assessmentEntries != null && !assessmentEntries.isEmpty()) {
            String assessmentDirName = dirName + "/Assessment_documents";
            for (AssessmentEntry assessmentEntry : assessmentEntries) {
                Identity assessedIdentity = assessmentEntry.getIdentity();
                List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
                String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
                String userDirName = assessmentDirName + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
                if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
                    for (File document : assessmentDocuments) {
                        String path = userDirName + "/" + document.getName();
                        ZipUtil.addFileToZip(path, document, exportStream);
                    }
                }
            }
        }
    }
    return super.archiveNodeData(locale, course, options, exportStream, charset);
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ModuleConfiguration(org.olat.modules.ModuleConfiguration) VFSContainer(org.olat.core.util.vfs.VFSContainer) CheckListExcelExport(org.olat.course.nodes.cl.ui.CheckListExcelExport) VFSItem(org.olat.core.util.vfs.VFSItem) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Identity (org.olat.core.id.Identity)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 CheckboxManager (org.olat.course.nodes.cl.CheckboxManager)2 Checkbox (org.olat.course.nodes.cl.model.Checkbox)2 CheckboxList (org.olat.course.nodes.cl.model.CheckboxList)2 CheckListExcelExport (org.olat.course.nodes.cl.ui.CheckListExcelExport)2 ModuleConfiguration (org.olat.modules.ModuleConfiguration)2 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)2