Search in sources :

Example 76 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class ProjectBrokerCourseNode method archiveNodeData.

@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    boolean dataFound = false;
    String dropboxPath = DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this);
    OlatRootFolderImpl dropboxDir = new OlatRootFolderImpl(dropboxPath, null);
    String returnboxPath = ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this);
    OlatRootFolderImpl returnboxDir = new OlatRootFolderImpl(returnboxPath, null);
    if (!dropboxDir.exists() && !returnboxDir.exists()) {
        return false;
    }
    String exportDirName = "projectbroker_" + Formatter.makeStringFilesystemSave(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    try {
        String projectBrokerTableExport = ProjectBrokerExportGenerator.createCourseResultsOverviewTable(this, course, locale);
        String tableExportFileName = ExportUtil.createFileNameWithTimeStamp(getShortTitle() + "-projectbroker_overview", "xls");
        exportStream.putNextEntry(new ZipEntry(exportDirName + "/" + tableExportFileName));
        IOUtils.write(projectBrokerTableExport, exportStream, "UTF-8");
        exportStream.closeEntry();
    } catch (IOException e) {
        log.error("", e);
    }
    // copy dropboxes to tmp dir
    if (dropboxDir.exists()) {
        // OLAT-6426 archive only dropboxes of users that handed in at least one file -> prevent empty folders in archive
        for (VFSItem themaItem : dropboxDir.getItems()) {
            if (!(themaItem instanceof VFSContainer))
                continue;
            List<VFSItem> userFolderArray = ((VFSContainer) themaItem).getItems();
            for (VFSItem userFolder : userFolderArray) {
                if (!VFSManager.isDirectoryAndNotEmpty(userFolder))
                    continue;
                String path = exportDirName + "/dropboxes/" + themaItem.getName();
                ZipUtil.addToZip(userFolder, path, exportStream);
            }
        }
    }
    // copy returnboxes to tmp dir
    if (returnboxDir.exists()) {
        for (VFSItem themaItem : returnboxDir.getItems()) {
            if (!(themaItem instanceof VFSContainer))
                continue;
            List<VFSItem> userFolderArray = ((VFSContainer) themaItem).getItems();
            for (VFSItem userFolder : userFolderArray) {
                if (!VFSManager.isDirectoryAndNotEmpty(userFolder))
                    continue;
                String path = exportDirName + "/returnboxes/" + themaItem.getName();
                ZipUtil.addToZip(userFolder, path, exportStream);
            }
        }
    }
    return dataFound;
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ZipEntry(java.util.zip.ZipEntry) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Date(java.util.Date)

Example 77 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class GTASampleSolutionsEditController method updateModel.

private void updateModel() {
    List<Solution> solutionList = gtaManager.getSolutions(courseEnv, gtaNode);
    List<SolutionRow> rows = new ArrayList<>(solutionList.size());
    for (Solution solution : solutionList) {
        String filename = solution.getFilename();
        String author = null;
        VFSItem item = solutionContainer.resolve(filename);
        if (item instanceof MetaTagged) {
            MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
            if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
                author = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
            }
        }
        DownloadLink downloadLink = null;
        if (item instanceof VFSLeaf) {
            downloadLink = uifactory.addDownloadLink("file_" + (++linkCounter), filename, null, (VFSLeaf) item, solutionTable);
        }
        rows.add(new SolutionRow(solution, author, downloadLink));
    }
    solutionModel.setObjects(rows);
    solutionTable.reset();
}
Also used : DownloadLink(org.olat.core.gui.components.form.flexible.elements.DownloadLink) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) Solution(org.olat.course.nodes.gta.model.Solution)

Example 78 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class GTASampleSolutionsEditController method doCreateSolutionEditor.

private void doCreateSolutionEditor(UserRequest ureq, Solution solution) {
    String documentName = solution.getFilename();
    VFSItem item = solutionContainer.resolve(documentName);
    if (item == null) {
        item = solutionContainer.createChildLeaf(documentName);
    } else {
        documentName = VFSManager.rename(solutionContainer, documentName);
        item = solutionContainer.createChildLeaf(documentName);
    }
    if (item instanceof MetaTagged) {
        MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
        if (metaInfo != null) {
            metaInfo.setAuthor(getIdentity());
        }
        metaInfo.write();
    }
    newSolutionEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), solutionContainer, documentName, "media", true, true);
    newSolutionEditorCtrl.getRichTextConfiguration().disableMedia();
    newSolutionEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
    newSolutionEditorCtrl.setNewFile(true);
    newSolutionEditorCtrl.setUserObject(solution);
    listenTo(newSolutionEditorCtrl);
    cmc = new CloseableModalController(getWindowControl(), "close", newSolutionEditorCtrl.getInitialComponent());
    listenTo(cmc);
    cmc.activate();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 79 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class PFPeekviewController method addItems.

private void addItems(VFSContainer container, List<VFSLeaf> allLeafs) {
    // exclude files which are also excluded in FolderComponent
    for (VFSItem vfsItem : container.getItems(attachmentExcludeFilter)) {
        if (vfsItem instanceof VFSLeaf) {
            // add leaf to our list
            VFSLeaf leaf = (VFSLeaf) vfsItem;
            allLeafs.add(leaf);
        } else if (vfsItem instanceof VFSContainer) {
            // do it recursively for all children
            VFSContainer childContainer = (VFSContainer) vfsItem;
            addItems(childContainer, allLeafs);
        } else {
        // hu?
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 80 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class ScormDirectoryHelper method getScoDirectory.

/**
 * Return the container where the LMS save the datas for a user.
 * @param username
 * @param courseEnv
 * @param node
 * @return
 */
public static VFSContainer getScoDirectory(String username, CourseEnvironment courseEnv, ScormCourseNode node) {
    Long courseId = courseEnv.getCourseResourceableId();
    VFSItem userFolder = ScormDirectoryHelper.getScormRootFolder().resolve(username);
    if (userFolder != null) {
        VFSItem scoFolder = userFolder.resolve(courseId.toString() + "-" + node.getIdent());
        if (scoFolder instanceof VFSContainer) {
            return (VFSContainer) scoFolder;
        }
    }
    return null;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20